|
|
@ -40,6 +40,7 @@ import com.jme3.material.TechniqueDef.ShadowMode; |
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
|
import com.jme3.math.Vector2f; |
|
|
|
import com.jme3.math.Vector2f; |
|
|
|
import com.jme3.math.Vector3f; |
|
|
|
import com.jme3.math.Vector3f; |
|
|
|
|
|
|
|
import com.jme3.shader.Shader; |
|
|
|
import com.jme3.shader.VarType; |
|
|
|
import com.jme3.shader.VarType; |
|
|
|
import com.jme3.texture.Texture; |
|
|
|
import com.jme3.texture.Texture; |
|
|
|
import com.jme3.texture.Texture.WrapMode; |
|
|
|
import com.jme3.texture.Texture.WrapMode; |
|
|
@ -48,8 +49,10 @@ import com.jme3.texture.image.ColorSpace; |
|
|
|
import com.jme3.util.PlaceholderAssets; |
|
|
|
import com.jme3.util.PlaceholderAssets; |
|
|
|
import com.jme3.util.blockparser.BlockLanguageParser; |
|
|
|
import com.jme3.util.blockparser.BlockLanguageParser; |
|
|
|
import com.jme3.util.blockparser.Statement; |
|
|
|
import com.jme3.util.blockparser.Statement; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.util.EnumMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.logging.Level; |
|
|
|
import java.util.logging.Level; |
|
|
|
import java.util.logging.Logger; |
|
|
|
import java.util.logging.Logger; |
|
|
@ -69,15 +72,14 @@ public class J3MLoader implements AssetLoader { |
|
|
|
private TechniqueDef technique; |
|
|
|
private TechniqueDef technique; |
|
|
|
private RenderState renderState; |
|
|
|
private RenderState renderState; |
|
|
|
|
|
|
|
|
|
|
|
private String vertLanguage; |
|
|
|
private EnumMap<Shader.ShaderType, String> shaderLanguage; |
|
|
|
private String fragLanguage; |
|
|
|
private EnumMap<Shader.ShaderType, String> shaderName; |
|
|
|
|
|
|
|
|
|
|
|
private String vertName; |
|
|
|
|
|
|
|
private String fragName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String whitespacePattern = "\\p{javaWhitespace}+"; |
|
|
|
private static final String whitespacePattern = "\\p{javaWhitespace}+"; |
|
|
|
|
|
|
|
|
|
|
|
public J3MLoader() { |
|
|
|
public J3MLoader() { |
|
|
|
|
|
|
|
shaderLanguage = new EnumMap<Shader.ShaderType, String>(Shader.ShaderType.class); |
|
|
|
|
|
|
|
shaderName = new EnumMap<Shader.ShaderType, String>(Shader.ShaderType.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -92,15 +94,20 @@ public class J3MLoader implements AssetLoader { |
|
|
|
throw new IOException("Shader statement syntax incorrect: " + statement); |
|
|
|
throw new IOException("Shader statement syntax incorrect: " + statement); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeAndLang[0].equals("VertexShader")) { |
|
|
|
for (Shader.ShaderType shaderType : Shader.ShaderType.values()) { |
|
|
|
vertName = split[1].trim(); |
|
|
|
if (typeAndLang[0].equals(shaderType.toString() + "Shader")) { |
|
|
|
vertLanguage = typeAndLang[1]; |
|
|
|
readShaderDefinition(shaderType, split[1].trim(), typeAndLang[1]); |
|
|
|
} else if (typeAndLang[0].equals("FragmentShader")) { |
|
|
|
} |
|
|
|
fragName = split[1].trim(); |
|
|
|
|
|
|
|
fragLanguage = typeAndLang[1]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void readShaderDefinition(Shader.ShaderType shaderType, String name, String language) { |
|
|
|
|
|
|
|
System.out.println(shaderType); |
|
|
|
|
|
|
|
System.out.println(name); |
|
|
|
|
|
|
|
shaderName.put(shaderType, name); |
|
|
|
|
|
|
|
shaderLanguage.put(shaderType, language); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// LightMode <MODE>
|
|
|
|
// LightMode <MODE>
|
|
|
|
private void readLightMode(String statement) throws IOException { |
|
|
|
private void readLightMode(String statement) throws IOException { |
|
|
|
String[] split = statement.split(whitespacePattern); |
|
|
|
String[] split = statement.split(whitespacePattern); |
|
|
@ -406,7 +413,10 @@ public class J3MLoader implements AssetLoader { |
|
|
|
private void readTechniqueStatement(Statement statement) throws IOException { |
|
|
|
private void readTechniqueStatement(Statement statement) throws IOException { |
|
|
|
String[] split = statement.getLine().split("[ \\{]"); |
|
|
|
String[] split = statement.getLine().split("[ \\{]"); |
|
|
|
if (split[0].equals("VertexShader") || |
|
|
|
if (split[0].equals("VertexShader") || |
|
|
|
split[0].equals("FragmentShader")){ |
|
|
|
split[0].equals("FragmentShader") || |
|
|
|
|
|
|
|
split[0].equals("GeometryShader") || |
|
|
|
|
|
|
|
split[0].equals("TesselationControlShader") || |
|
|
|
|
|
|
|
split[0].equals("TesselationEvaluationShader")) { |
|
|
|
readShaderStatement(statement.getLine()); |
|
|
|
readShaderStatement(statement.getLine()); |
|
|
|
} else if (split[0].equals("LightMode")) { |
|
|
|
} else if (split[0].equals("LightMode")) { |
|
|
|
readLightMode(statement.getLine()); |
|
|
|
readLightMode(statement.getLine()); |
|
|
@ -470,16 +480,14 @@ public class J3MLoader implements AssetLoader { |
|
|
|
technique.setShaderFile(technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100"); |
|
|
|
technique.setShaderFile(technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (vertName != null && fragName != null){ |
|
|
|
if (shaderName.containsKey(Shader.ShaderType.Vertex) && shaderName.containsKey(Shader.ShaderType.Fragment)) { |
|
|
|
technique.setShaderFile(vertName, fragName, vertLanguage, fragLanguage); |
|
|
|
technique.setShaderFile(shaderName, shaderLanguage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
materialDef.addTechniqueDef(technique); |
|
|
|
materialDef.addTechniqueDef(technique); |
|
|
|
technique = null; |
|
|
|
technique = null; |
|
|
|
vertName = null; |
|
|
|
shaderLanguage.clear(); |
|
|
|
fragName = null; |
|
|
|
shaderName.clear(); |
|
|
|
vertLanguage = null; |
|
|
|
|
|
|
|
fragLanguage = null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void loadFromRoot(List<Statement> roots) throws IOException { |
|
|
|
private void loadFromRoot(List<Statement> roots) throws IOException { |
|
|
@ -597,7 +605,7 @@ public class J3MLoader implements AssetLoader { |
|
|
|
|
|
|
|
|
|
|
|
protected void initNodesLoader() { |
|
|
|
protected void initNodesLoader() { |
|
|
|
if (!isUseNodes) { |
|
|
|
if (!isUseNodes) { |
|
|
|
isUseNodes = fragName == null && vertName == null; |
|
|
|
isUseNodes = shaderName.get(Shader.ShaderType.Vertex) == null && shaderName.get(Shader.ShaderType.Fragment) == null; |
|
|
|
if (isUseNodes) { |
|
|
|
if (isUseNodes) { |
|
|
|
if (nodesLoaderDelegate == null) { |
|
|
|
if (nodesLoaderDelegate == null) { |
|
|
|
nodesLoaderDelegate = new ShaderNodeLoaderDelegate(); |
|
|
|
nodesLoaderDelegate = new ShaderNodeLoaderDelegate(); |
|
|
|