SDK:
- Material Support: Improve save to texture feature git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10215 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
		
							parent
							
								
									cc9379b42a
								
							
						
					
					
						commit
						6732c15731
					
				| @ -1,8 +1,8 @@ | ||||
| build.xml.data.CRC32=3c35bd02 | ||||
| build.xml.data.CRC32=5c252103 | ||||
| build.xml.script.CRC32=f284e28d | ||||
| build.xml.stylesheet.CRC32=a56c6a5b@2.49.1 | ||||
| build.xml.stylesheet.CRC32=a56c6a5b@2.50.1 | ||||
| # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. | ||||
| # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. | ||||
| nbproject/build-impl.xml.data.CRC32=3c35bd02 | ||||
| nbproject/build-impl.xml.data.CRC32=5c252103 | ||||
| nbproject/build-impl.xml.script.CRC32=56cee44d | ||||
| nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49.1 | ||||
| nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.50.1 | ||||
|  | ||||
| @ -4,9 +4,12 @@ | ||||
|  */ | ||||
| package com.jme3.gde.materials; | ||||
| 
 | ||||
| import com.jme3.asset.TextureKey; | ||||
| import com.jme3.gde.core.assets.ProjectAssetManager; | ||||
| import com.jme3.gde.core.util.Beans; | ||||
| import com.jme3.gde.materials.wizards.StoreTextureWizardWizardAction; | ||||
| import com.jme3.material.MatParam; | ||||
| import com.jme3.material.MatParamTexture; | ||||
| import com.jme3.material.Material; | ||||
| import com.jme3.texture.Image; | ||||
| import com.jme3.texture.Texture; | ||||
| @ -494,11 +497,7 @@ public class EditableMaterialFile { | ||||
|         setMatDefName(mat.getMaterialDef().getAssetName()); | ||||
|         createBaseMaterialFile(); | ||||
|         materialParameters.clear(); | ||||
|         Collection<MatParam> params = mat.getParams(); | ||||
|         for (Iterator<MatParam> it = params.iterator(); it.hasNext();) { | ||||
|             MatParam matParam = it.next(); | ||||
|             checkPackedTextureProps(mat, matParam); | ||||
|         } | ||||
|         checkPackedTextureProps(mat); | ||||
|         additionalRenderStates.put("Wireframe", new MaterialProperty("OnOff", "Wireframe", mat.getAdditionalRenderState().isWireframe() ? "On" : "Off")); | ||||
|         additionalRenderStates.put("DepthWrite", new MaterialProperty("OnOff", "DepthWrite", mat.getAdditionalRenderState().isDepthWrite() ? "On" : "Off")); | ||||
|         additionalRenderStates.put("DepthTest", new MaterialProperty("OnOff", "DepthTest", mat.getAdditionalRenderState().isDepthTest() ? "On" : "Off")); | ||||
| @ -518,43 +517,59 @@ public class EditableMaterialFile { | ||||
|      * @param mat | ||||
|      * @param param | ||||
|      */ | ||||
|     private void checkPackedTextureProps(Material mat, MatParam param) { | ||||
|         MaterialProperty prop = new MaterialProperty(param); | ||||
|         materialParameters.put(param.getName(), prop); | ||||
|         if (prop.getValue() == null) { | ||||
|             switch (param.getVarType()) { | ||||
|                 case Texture2D: | ||||
|                 case Texture3D: | ||||
|                 case TextureArray: | ||||
|                 case TextureBuffer: | ||||
|                 case TextureCubeMap: | ||||
|                     try { | ||||
|                         Texture tex = mat.getTextureParam(param.getName()).getTextureValue(); | ||||
|                         Image img = tex.getImage(); | ||||
|                         if (img == null) { | ||||
|                             logger.log(Level.INFO, "No image found"); | ||||
|                             return; | ||||
|     private void checkPackedTextureProps(Material mat) { | ||||
|         Collection<MatParam> params = mat.getParams(); | ||||
|         for (Iterator<MatParam> it = new ArrayList<MatParam>(params).iterator(); it.hasNext();) { | ||||
|             MatParam param = it.next(); | ||||
|             MaterialProperty prop = new MaterialProperty(param); | ||||
|             if (prop.getValue() == null) { | ||||
|                 switch (param.getVarType()) { | ||||
|                     case Texture2D: | ||||
|                     case Texture3D: | ||||
|                     case TextureArray: | ||||
|                     case TextureBuffer: | ||||
|                     case TextureCubeMap: | ||||
|                         try { | ||||
|                             MatParamTexture texParam = mat.getTextureParam(param.getName()); | ||||
|                             Texture tex = texParam.getTextureValue(); | ||||
|                             Image img = tex.getImage(); | ||||
|                             if (img == null) { | ||||
|                                 logger.log(Level.INFO, "No image found"); | ||||
|                                 return; | ||||
|                             } | ||||
|                             BufferedImage image = ImageToAwt.convert(img, false, false, 0); | ||||
|                             ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||||
|                             ImageWriter imgWrtr = ImageIO.getImageWritersByFormatName("png").next(); | ||||
|                             ImageOutputStream imgOutStrm; | ||||
|                             imgOutStrm = ImageIO.createImageOutputStream(out); | ||||
|                             imgWrtr.setOutput(imgOutStrm); | ||||
|                             ImageWriteParam jpgWrtPrm = imgWrtr.getDefaultWriteParam(); | ||||
|                             imgWrtr.write(null, new IIOImage(image, null, null), jpgWrtPrm); | ||||
|                             imgOutStrm.close(); | ||||
|                             out.close(); | ||||
|                             String texturePath = material.getName(); | ||||
|                             texturePath = "Textures/" + texturePath + "-" + param.getName() + ".png"; | ||||
|                             StoreTextureWizardWizardAction act = new StoreTextureWizardWizardAction(manager, out.toByteArray(), texturePath); | ||||
|                             act.actionPerformed(null); | ||||
|                             texturePath = act.getName(); | ||||
|                             TextureKey texKey = new TextureKey(texturePath); | ||||
|                             TextureKey oldKey = (TextureKey)tex.getKey(); | ||||
|                             if(oldKey!=null){ | ||||
|                                 Beans.copyProperties(texKey, oldKey); | ||||
|                             } | ||||
|                             //TODO: seems like flip is removed due to ImageToAwt | ||||
|                             texKey.setFlipY(false); | ||||
|                             Texture texture = manager.loadTexture(texKey); | ||||
|                             MatParamTexture newParam = new MatParamTexture(texParam.getVarType(), texParam.getName(), texture, texParam.getUnit()); | ||||
|                             materialParameters.put(newParam.getName(), new MaterialProperty(newParam)); | ||||
|                         } catch (Exception ex) { | ||||
|                             Exceptions.printStackTrace(ex); | ||||
|                         } | ||||
|                         BufferedImage image = ImageToAwt.convert(img, false, false, 0); | ||||
|                         ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||||
|                         ImageWriter imgWrtr = ImageIO.getImageWritersByFormatName("png").next(); | ||||
|                         ImageOutputStream imgOutStrm; | ||||
|                         imgOutStrm = ImageIO.createImageOutputStream(out); | ||||
|                         imgWrtr.setOutput(imgOutStrm); | ||||
|                         ImageWriteParam jpgWrtPrm = imgWrtr.getDefaultWriteParam(); | ||||
|                         imgWrtr.write(null, new IIOImage(image, null, null), jpgWrtPrm); | ||||
|                         imgOutStrm.close(); | ||||
|                         out.close(); | ||||
|                         String name = material.getName(); | ||||
|                         name = "Textures/" + name + "-" + param.getName() + ".png"; | ||||
|                         StoreTextureWizardWizardAction act = new StoreTextureWizardWizardAction(manager, out.toByteArray(), name); | ||||
|                         act.actionPerformed(null); | ||||
|                         prop.setValue(act.getName()); | ||||
|                     } catch (Exception ex) { | ||||
|                         Exceptions.printStackTrace(ex); | ||||
|                     } | ||||
|                     break; | ||||
|                 default: | ||||
|                         break; | ||||
|                     default: | ||||
|                 } | ||||
|             } else { | ||||
|                 materialParameters.put(param.getName(), prop); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user