diff --git a/README.md b/README.md index 8600a2b..9e8a2a9 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -## Shader Nodes Plugin 1.1.0 +## Shader Nodes Plugin 1.1.1 It's a plugin for jMonkeyBuilder to support working with shader modes. -#### It requires jMonkeyBuilder 1.3.2 or higher. +#### It requires jMonkeyBuilder 1.7.0 or higher. Creating the shader nodes project file: diff --git a/build.gradle b/build.gradle index 4c89bf2..9b1da8b 100644 --- a/build.gradle +++ b/build.gradle @@ -14,21 +14,24 @@ apply plugin: 'java' apply plugin: 'maven' apply plugin: 'idea' apply plugin: 'org.junit.platform.gradle.plugin' +apply plugin: 'application' group = 'com.spaceshift' -version = '1.1.0' +version = '1.1.1' ext.artifactId = 'shader-nodes' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 1.10 +targetCompatibility = 1.10 compileTestJava { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = 1.10 + targetCompatibility = 1.10 options.compilerArgs += '-parameters' } +mainClassName = "com.ss.editor.DevelopPluginStarter" + ext.junitPlatformVersion = "1.0.0" ext.junitJupiterVersion = "5.0.0" ext.log4jVersion = '2.6.2' @@ -47,14 +50,19 @@ repositories { mavenCentral() jcenter() maven { url 'https://jitpack.io' } + maven { url "https://dl.bintray.com/javasabr/maven" } } configurations { pluginDependences } +javadoc { + failOnError = false +} + dependencies { - compile 'com.github.JavaSabr:jmonkeybuilder:develop-SNAPSHOT' + compile 'com.spaceshift:jmonkeybuilder:1.7.3-4' testCompile "org.junit.platform:junit-platform-commons:$junitPlatformVersion" testRuntime "org.junit.platform:junit-platform-engine:$junitPlatformVersion" @@ -69,21 +77,6 @@ dependencies { testCompile "org.junit.platform:junit-platform-launcher:$junitPlatformVersion" } -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} - task cleanPluginFolders(type: Delete) { doFirst { @@ -175,15 +168,11 @@ task deployPlugin(type: Zip, dependsOn: 'preparePlugin') { } task wrapper(type: Wrapper) { - gradleVersion = '4.3' + gradleVersion = '4.6' } -defaultTasks 'install' +run.dependsOn { + preparePlugin +} -// To specify a license in the pom: -install { - repositories.mavenInstaller { - pom.version = version - pom.artifactId = artifactId - } -} \ No newline at end of file +run.jvmArgs(Arrays.asList("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005", "-Duser.country=EU", "-Duser.language=en")) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 27768f1..f6b961f 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 92165ee..bf3de21 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip diff --git a/pbrMainVertex.vert b/pbrMainVertex.vert new file mode 100644 index 0000000..93248ee --- /dev/null +++ b/pbrMainVertex.vert @@ -0,0 +1,76 @@ +#import "Common/ShaderLib/GLSLCompat.glsllib" +#import "Common/ShaderLib/Instancing.glsllib" +#import "Common/ShaderLib/Skinning.glsllib" + +uniform vec4 m_BaseColor; + +uniform vec4 g_AmbientLightColor; +varying vec2 texCoord; + +#ifdef SEPARATE_TEXCOORD + varying vec2 texCoord2; + attribute vec2 inTexCoord2; +#endif + +varying vec4 Color; + +attribute vec3 inPosition; +attribute vec2 inTexCoord; +attribute vec3 inNormal; + +#ifdef VERTEX_COLOR + attribute vec4 inColor; +#endif + +varying vec3 wNormal; +varying vec3 wPosition; +#if defined(NORMALMAP) || defined(PARALLAXMAP) + attribute vec4 inTangent; + varying vec4 wTangent; +#endif + +void main() { + vec4 modelSpacePos = vec4(inPosition, 1.0); + vec3 modelSpaceNorm = inNormal; + + #if ( defined(NORMALMAP) || defined(PARALLAXMAP)) && !defined(VERTEX_LIGHTING) + vec3 modelSpaceTan = inTangent.xyz; + #endif + + #ifdef NUM_BONES + #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING) + Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan); + #else + Skinning_Compute(modelSpacePos, modelSpaceNorm); + #endif + #endif + + #ifdef NUM_BONES + #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING) + Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan); + #elif defined(NORMALMAP) + Skinning_Compute(modelSpacePos, modelSpaceNorm); + #else + Skinning_Compute(modelSpacePos); + #endif + #endif + + gl_Position = TransformWorldViewProjection(modelSpacePos); + texCoord = inTexCoord; + #ifdef SEPARATE_TEXCOORD + texCoord2 = inTexCoord2; + #endif + + wPosition = TransformWorld(modelSpacePos).xyz; + wNormal = TransformWorldNormal(modelSpaceNorm); + + #if defined(NORMALMAP) || defined(PARALLAXMAP) + wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w); + #endif + + Color = m_BaseColor; + + #ifdef VERTEX_COLOR + Color *= inColor; + #endif +} \ No newline at end of file diff --git a/src/main/java/com/jme3/material/plugin/export/materialdef/J3mdTechniqueDefWriter.java b/src/main/java/com/jme3/material/plugin/export/materialdef/J3mdTechniqueDefWriter.java new file mode 100644 index 0000000..8a76e86 --- /dev/null +++ b/src/main/java/com/jme3/material/plugin/export/materialdef/J3mdTechniqueDefWriter.java @@ -0,0 +1,327 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.material.plugin.export.materialdef; + +import com.jme3.material.MatParam; +import com.jme3.material.RenderState; +import com.jme3.material.TechniqueDef; +import com.jme3.shader.*; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.Collection; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author nehon + */ +public class J3mdTechniqueDefWriter { + + public J3mdTechniqueDefWriter() { + } + + public void write(TechniqueDef techniqueDef, Collection matParams, OutputStreamWriter out) throws IOException { + out.write(" Technique"); + if(!techniqueDef.getName().equals("Default")) { + out.write(" "); + out.write(techniqueDef.getName()); + } + out.write(" {\n"); + + //Light mode + if(techniqueDef.getLightMode() != TechniqueDef.LightMode.Disable ){ + out.write(" LightMode "); + out.write(techniqueDef.getLightMode().name()); + out.write("\n\n"); + } + + //Shadow mode + if(techniqueDef.getShadowMode() != TechniqueDef.ShadowMode.Disable ){ + out.write(" ShadowMode "); + out.write(techniqueDef.getShadowMode().name()); + out.write("\n\n"); + } + + //Shaders + if(!techniqueDef.isUsingShaderNodes()) { + writeShaders(techniqueDef, out); + } + + //World params + if(!techniqueDef.getWorldBindings().isEmpty()){ + writeWorldParams(techniqueDef, out); + } + + //ShaderNodes + if(techniqueDef.isUsingShaderNodes()){ + writeShaderNodes(techniqueDef, matParams, out); + + } else { + //When we have ShaderNodes, Defines are handled differently so we don't have to write them. + //Defines + if (techniqueDef.getDefineNames().length != 0) { + writeDefines(techniqueDef, matParams, out); + } + } + + //render state + RenderState rs = techniqueDef.getRenderState(); + if(rs != null){ + out.write(" RenderState {\n"); + writeRenderState(rs, out); + out.write(" }\n\n"); + } + + //forced render state + rs = techniqueDef.getForcedRenderState(); + if(rs != null){ + out.write(" ForcedRenderState {\n"); + writeRenderState(rs, out); + out.write(" }\n\n"); + } + + //no render + if(techniqueDef.isNoRender()){ + out.write(" NoRender\n\n"); + } + + out.write(" }\n"); + } + + private void writeDefines(TechniqueDef techniqueDef, Collection matParams, OutputStreamWriter out) throws IOException { + out.write(" Defines {\n"); + + for (int i = 0; i < techniqueDef.getDefineNames().length; i++) { + String matParamName = getMatParamNameForDefineId(techniqueDef, matParams, i); + if (matParamName != null) { + String defineName = techniqueDef.getDefineNames()[i]; + out.write(" "); + out.write(defineName); + out.write(": "); + out.write(matParamName); + out.write("\n"); + } + } + out.write(" }\n\n"); + } + + private void writeShaderNodes(TechniqueDef techniqueDef, Collection matParams, OutputStreamWriter out) throws IOException { + out.write(" VertexShaderNodes {\n"); + for (ShaderNode shaderNode : techniqueDef.getShaderNodes()) { + if(shaderNode.getDefinition().getType() == Shader.ShaderType.Vertex){ + writeShaderNode(out, shaderNode, matParams); + } + } + out.write(" }\n\n"); + + out.write(" FragmentShaderNodes {\n"); + for (ShaderNode shaderNode : techniqueDef.getShaderNodes()) { + if(shaderNode.getDefinition().getType() == Shader.ShaderType.Fragment){ + writeShaderNode(out, shaderNode, matParams); + } + } + out.write(" }\n\n"); + } + + private void writeWorldParams(TechniqueDef techniqueDef, OutputStreamWriter out) throws IOException { + out.write(" WorldParameters {\n"); + for (UniformBinding uniformBinding : techniqueDef.getWorldBindings()) { + out.write(" "); + out.write(uniformBinding.toString()); + out.write("\n"); + } + out.write(" }\n\n"); + } + + private void writeShaders(TechniqueDef techniqueDef, OutputStreamWriter out) throws IOException { + if (techniqueDef.getShaderProgramNames().size() > 0) { + for (Shader.ShaderType shaderType : techniqueDef.getShaderProgramNames().keySet()) { + // System.err.println(shaderType + " " +techniqueDef.getShaderProgramNames().get(shaderType) + " " +techniqueDef.getShaderProgramLanguage(shaderType)) + out.write(" "); + out.write(shaderType.name()); + out.write("Shader "); + out.write(techniqueDef.getShaderProgramLanguage(shaderType)); + out.write(": "); + out.write(techniqueDef.getShaderProgramNames().get(shaderType)); + out.write("\n"); + } + out.write("\n"); + } + } + + private void writeShaderNode( OutputStreamWriter out, ShaderNode shaderNode, Collection matParams) throws IOException { + out.write(" ShaderNode "); + out.write(shaderNode.getName()); + out.write(" {\n"); + + if (shaderNode.getCondition() != null){ + out.write(" Condition: "); + out.write(formatCondition(shaderNode.getCondition(), matParams)); + out.write("\n"); + } + + out.write(" Definition: "); + out.write(shaderNode.getDefinition().getName()); + out.write(": "); + out.write(shaderNode.getDefinition().getPath()); + out.write("\n"); + + final List inputMapping = shaderNode.getInputMapping(); + final List outputMapping = shaderNode.getOutputMapping(); + + if (!inputMapping.isEmpty()) { + out.write(" InputMappings {\n"); + for (VariableMapping mapping : inputMapping) { + writeVariableMapping(out, shaderNode, mapping, matParams); + } + out.write(" }\n"); + } + + if (!outputMapping.isEmpty()) { + out.write(" OutputMappings {\n"); + for (VariableMapping mapping : outputMapping) { + writeVariableMapping(out, shaderNode, mapping, matParams); + } + out.write(" }\n"); + } + + out.write(" }\n"); + } + + private void writeVariableMapping(OutputStreamWriter out, + ShaderNode shaderNode, + VariableMapping mapping, + Collection matParams) throws IOException { + + final ShaderNodeVariable leftVar = mapping.getLeftVariable(); + final ShaderNodeVariable rightVar = mapping.getRightVariable(); + final String rightExpression = mapping.getRightExpression(); + + out.write(" "); + + if (!leftVar.getNameSpace().equals(shaderNode.getName())) { + out.write(leftVar.getNameSpace()); + out.write("."); + } + + out.write(leftVar.getName()); + + if (!mapping.getLeftSwizzling().equals("")) { + out.write("."); + out.write(mapping.getLeftSwizzling()); + } + + out.write(" = "); + + if (rightVar != null) { + + if (!rightVar.getNameSpace().equals(shaderNode.getName())) { + out.write(rightVar.getNameSpace()); + out.write("."); + } + + String rightVarName = rightVar.getName(); + if (rightVarName.startsWith("g_") || rightVarName.startsWith("m_")) { + rightVarName = rightVarName.substring(2, rightVarName.length()); + } + + out.write(rightVarName); + + if (!mapping.getRightSwizzling().equals("")) { + out.write("."); + out.write(mapping.getRightSwizzling()); + } + } else { + out.write("%%"); + out.write(rightExpression); + out.write("%%"); + } + + if (mapping.getCondition() != null) { + out.write(" : "); + out.write(formatCondition(mapping.getCondition(), matParams)); + } + + out.write("\n"); + } + + private String formatCondition(String condition, Collection matParams){ + //condition = condition.replaceAll("defined\\(",""); + + String res = condition; + Pattern pattern = Pattern.compile("defined\\(([A-Z0-9]*)\\)"); + Matcher m = pattern.matcher(condition); + + while(m.find()){ + String match = m.group(0); + String defineName = m.group(1).toLowerCase(); + for (MatParam matParam : matParams) { + if(matParam.getName().toLowerCase().equals(defineName)){ + res = res.replace(match, matParam.getName()); + } + } + } + + return res; + } + + private void writeRenderStateAttribute(OutputStreamWriter out, String name, String value) throws IOException { + out.write(" "); + out.write(name); + out.write(" "); + out.write(value); + out.write("\n"); + } + + private void writeRenderState(RenderState rs, OutputStreamWriter out) throws IOException { + RenderState defRs = RenderState.DEFAULT; + if(rs.getBlendMode() != defRs.getBlendMode()) { + writeRenderStateAttribute(out, "Blend", rs.getBlendMode().name()); + } + if(rs.isWireframe() != defRs.isWireframe()) { + writeRenderStateAttribute(out, "Wireframe", rs.isWireframe()?"On":"Off"); + } + if(rs.getFaceCullMode() != defRs.getFaceCullMode()) { + writeRenderStateAttribute(out, "FaceCull", rs.getFaceCullMode().name()); + } + if(rs.isDepthWrite() != defRs.isDepthWrite()) { + writeRenderStateAttribute(out, "DepthWrite", rs.isDepthWrite()?"On":"Off"); + } + if(rs.isDepthTest() != defRs.isDepthTest()) { + writeRenderStateAttribute(out, "DepthTest", rs.isDepthTest()?"On":"Off"); + } + if(rs.getBlendEquation() != defRs.getBlendEquation()) { + writeRenderStateAttribute(out, "BlendEquation", rs.getBlendEquation().name()); + } + if(rs.getBlendEquationAlpha() != defRs.getBlendEquationAlpha()) { + writeRenderStateAttribute(out, "BlendEquationAlpha", rs.getBlendEquationAlpha().name()); + } + if(rs.getPolyOffsetFactor() != defRs.getPolyOffsetFactor() || rs.getPolyOffsetUnits() != defRs.getPolyOffsetUnits()) { + writeRenderStateAttribute(out, "PolyOffset", rs.getPolyOffsetFactor() + " " + rs.getPolyOffsetUnits()); + } + if(rs.isColorWrite() != defRs.isColorWrite()) { + writeRenderStateAttribute(out, "ColorWrite", rs.isColorWrite()?"On":"Off"); + } + if(rs.getDepthFunc() != defRs.getDepthFunc()) { + writeRenderStateAttribute(out, "DepthFunc", rs.getDepthFunc().name()); + } + if(rs.getLineWidth() != defRs.getLineWidth()) { + writeRenderStateAttribute(out, "LineWidth", Float.toString(rs.getLineWidth())); + } + } + + private String getMatParamNameForDefineId(TechniqueDef techniqueDef, Collection matParams, int defineId) { + for (MatParam matParam : matParams) { + Integer id = techniqueDef.getShaderParamDefineId(matParam.getName()); + if(id !=null && id == defineId){ + return matParam.getName(); + } + } + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java b/src/main/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java new file mode 100644 index 0000000..0a345b1 --- /dev/null +++ b/src/main/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java @@ -0,0 +1,1146 @@ +/* + * Copyright (c) 2009-2012 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.material.plugins; + +import com.jme3.asset.AssetManager; +import com.jme3.asset.AssetNotFoundException; +import com.jme3.asset.ShaderNodeDefinitionKey; +import com.jme3.material.MatParam; +import com.jme3.material.MaterialDef; +import com.jme3.material.ShaderGenerationInfo; +import com.jme3.material.TechniqueDef; +import com.jme3.shader.Shader.ShaderType; +import com.jme3.shader.*; +import com.jme3.util.blockparser.Statement; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This class is here to be able to load shaderNodeDefinition from both the + * J3MLoader and ShaderNodeDefinitionLoader. + * + * Also it allows to load the ShaderNodes from a j3md file and build the + * ShaderNodes list of each technique and the ShaderGenerationInfo needed to + * generate shaders + * + * @author Nehon + */ +public class ShaderNodeLoaderDelegate { + + private static final boolean[] IM_HAS_NAME_SPACE = {false, true}; + private static final boolean[] OM_HAS_NAME_SPACE = {true, false}; + + protected Map nodeDefinitions; + protected Map nodes; + protected ShaderNodeDefinition shaderNodeDefinition; + protected ShaderNode shaderNode; + protected TechniqueDef techniqueDef; + protected Map attributes = new HashMap<>(); + protected Map vertexDeclaredUniforms = new HashMap<>(); + protected Map fragmentDeclaredUniforms = new HashMap<>(); + protected Map varyings = new HashMap<>(); + protected MaterialDef materialDef; + protected String shaderLanguage; + protected String shaderName; + protected String varNames = ""; + protected AssetManager assetManager; + protected ConditionParser conditionParser = new ConditionParser(); + protected List nulledConditions = new ArrayList(); + + protected class DeclaredVariable { + + ShaderNodeVariable var; + List nodes = new ArrayList(); + + public DeclaredVariable(ShaderNodeVariable var) { + this.var = var; + } + + public final void addNode(ShaderNode c) { + if (!nodes.contains(c)) { + nodes.add(c); + } + } + } + /** + * Read the ShaderNodesDefinitions block and returns a list of + * ShaderNodesDefinition This method is used by the j3sn loader + * + * note that the order of the definitions in the list is not guaranteed. + * + * @param statements the list statements to parse + * @param key the ShaderNodeDefinitionKey + * @return a list of ShaderNodesDefinition + * @throws IOException + */ + public List readNodesDefinitions(List statements, ShaderNodeDefinitionKey key) throws IOException { + + for (Statement statement : statements) { + String[] split = statement.getLine().split("[ \\{]"); + if (statement.getLine().startsWith("ShaderNodeDefinition")) { + String name = statement.getLine().substring("ShaderNodeDefinition".length()).trim(); + + + if (!getNodeDefinitions().containsKey(name)) { + shaderNodeDefinition = new ShaderNodeDefinition(); + getNodeDefinitions().put(name, shaderNodeDefinition); + shaderNodeDefinition.setName(name); + shaderNodeDefinition.setPath(key.getName()); + readShaderNodeDefinition(statement.getContents(), key); + + } + } else { + throw new MatParseException("ShaderNodeDefinition", split[0], statement); + } + } + + return new ArrayList(getNodeDefinitions().values()); + } + + /** + * Read the ShaderNodesDefinitions block and internally stores a map of + * ShaderNodesDefinition This method is used by the j3m loader. + * + * When loaded in a material, the definitions are not stored as a list, but + * they are stores in Shadernodes based on this definition. + * + * The map is here to map the definition to the nodes, and ovoid reloading + * already loaded definitions + * + * @param statements the list of statements to parse + * @throws IOException + */ + public void readNodesDefinitions(List statements) throws IOException { + readNodesDefinitions(statements, new ShaderNodeDefinitionKey()); + } + + /** + * effectively reads the ShaderNodesDefinitions block + * + * @param statements the list of statements to parse + * @param key the ShaderNodeDefinitionKey + * @throws IOException + */ + protected void readShaderNodeDefinition(List statements, ShaderNodeDefinitionKey key) throws IOException { + boolean isLoadDoc = key instanceof ShaderNodeDefinitionKey && ((ShaderNodeDefinitionKey) key).isLoadDocumentation(); + for (Statement statement : statements) { + try { + String[] split = statement.getLine().split("[ \\{]"); + String line = statement.getLine(); + + if (line.startsWith("Type")) { + String type = line.substring(line.lastIndexOf(':') + 1).trim(); + shaderNodeDefinition.setType(ShaderType.valueOf(type)); + } else if (line.startsWith("Shader ")) { + readShaderStatement(statement); + shaderNodeDefinition.getShadersLanguage().add(shaderLanguage); + shaderNodeDefinition.getShadersPath().add(shaderName); + } else if (line.startsWith("Documentation")) { + if (isLoadDoc) { + String doc = ""; + for (Statement statement1 : statement.getContents()) { + doc += "\n" + statement1.getLine(); + } + shaderNodeDefinition.setDocumentation(doc); + } + } else if (line.startsWith("Input")) { + varNames = ""; + for (Statement statement1 : statement.getContents()) { + try { + shaderNodeDefinition.getInputs().add(readVariable(statement1)); + } catch (RuntimeException e) { + throw new MatParseException(e.getMessage(), statement1, e); + } + } + } else if (line.startsWith("Output")) { + varNames = ""; + for (Statement statement1 : statement.getContents()) { + try { + if (statement1.getLine().trim().equals("None")) { + shaderNodeDefinition.setNoOutput(true); + } else { + shaderNodeDefinition.getOutputs().add(readVariable(statement1)); + } + } catch (RuntimeException e) { + throw new MatParseException(e.getMessage(), statement1, e); + } + } + } else { + throw new MatParseException("one of Type, Shader, Documentation, Input, Output", split[0], statement); + } + } catch (RuntimeException e) { + throw new MatParseException(e.getMessage(), statement, e); + } + } + } + + /** + * reads a variable declaration statement <glslType> <varName> + * + * @param statement the statement to parse + * @return a ShaderNodeVariable extracted from the statement + * @throws IOException + */ + protected ShaderNodeVariable readVariable(Statement statement) throws IOException { + + String line = statement.getLine().trim().replaceAll("\\s*\\[", "["); + String[] splitVar = line.split("\\s"); + + if (splitVar.length > 3) { + throw new MatParseException("More than 3 arguments", splitVar.length + "", statement); + } + + String defaultValue = splitVar.length > 2? splitVar[2] : null; + String varName = splitVar[1]; + String varType = splitVar[0]; + String multiplicity = null; + + if (varName.contains("[")) { + //we have an array + String[] arr = splitVar[1].split("\\["); + varName = arr[0].trim(); + multiplicity = arr[1].replaceAll("\\]", "").trim(); + } + + if (varNames.contains(varName + ";")) { + throw new MatParseException("Duplicate variable name " + varName, statement); + } + + varNames += varName + ";"; + + final ShaderNodeVariable variable = new ShaderNodeVariable(varType, "", varName, multiplicity); + variable.setDefaultValue(defaultValue); + + return variable; + } + + /** + * reads the VertexShaderNodes{} block + * + * @param statements the list of statements to parse + * @throws IOException + */ + public void readVertexShaderNodes(List statements) throws IOException { + attributes.clear(); + readNodes(statements); + } + + /** + * reads a list of ShaderNode{} blocks + * + * @param statements the list of statements to parse + * @throws IOException + */ + protected void readShaderNode(List statements) throws IOException { + + final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); + final List unusedNodes = generationInfo.getUnusedNodes(); + + for (Statement statement : statements) { + + String line = statement.getLine(); + String[] split = statement.getLine().split("[ \\{]"); + + if (line.startsWith("Definition")) { + ShaderNodeDefinition def = findDefinition(statement); + shaderNode.setDefinition(def); + if(def.isNoOutput()){ + unusedNodes.remove(shaderNode.getName()); + } + } else if (line.startsWith("Condition")) { + String condition = line.substring(line.lastIndexOf(":") + 1).trim(); + extractCondition(condition, statement); + shaderNode.setCondition(conditionParser.getFormattedExpression()); + } else if (line.startsWith("InputMappings")) { + for (final Statement subStatement : statement.getContents()) { + + VariableMapping mapping = readInputMapping(subStatement); + + final ShaderNodeVariable rightVariable = mapping.getRightVariable(); + if (rightVariable != null) { + unusedNodes.remove(rightVariable.getNameSpace()); + } + + shaderNode.getInputMapping().add(mapping); + } + } else if (line.startsWith("OutputMappings")) { + for (Statement statement1 : statement.getContents()) { + VariableMapping mapping = readOutputMapping(statement1); + unusedNodes.remove(shaderNode.getName()); + shaderNode.getOutputMapping().add(mapping); + } + } else { + throw new MatParseException("ShaderNodeDefinition", split[0], statement); + } + } + } + + /** + * Reads a mapping statement. Sets the nameSpace, name and swizzling of the + * left variable. Sets the name, nameSpace and swizzling of the right + * variable types will be determined later. Also, we can have the right part as expression. + *
+     * Format variable to variable: <nameSpace>.<varName>[.<swizzling>] = <nameSpace>.<varName>[.<swizzling>][:Condition]
+     * Format expression to variable: <nameSpace>.<varName>[.<swizzling>] = %% expression %% [:Condition]
+     * 
+ * + * @param statement the statement to read. + * @return the read mapping. + * @throws MatParseException if the statement isn't valid. + */ + protected VariableMapping parseMapping(Statement statement, boolean[] hasNameSpace) throws MatParseException { + + VariableMapping mapping = new VariableMapping(); + String[] cond = statement.getLine().split(":"); + String[] vars = cond[0].split("="); + + checkMappingFormat(vars, statement); + + ShaderNodeVariable[] variables = new ShaderNodeVariable[2]; + String[] swizzle = new String[2]; + String rightExpression = null; + + for (int i = 0; i < vars.length; i++) { + + final String var = vars[i].trim(); + + // it seems that is expression, not variable + if (var.contains("%%")) { + rightExpression = var.substring(2, var.length() - 2); + continue; + } + + String[] expression = var.split("\\."); + + if (hasNameSpace[i]) { + if (expression.length <= 3) { + variables[i] = new ShaderNodeVariable("", expression[0].trim(), expression[1].trim()); + } + if (expression.length == 3) { + swizzle[i] = expression[2].trim(); + } + } else { + if (expression.length <= 2) { + variables[i] = new ShaderNodeVariable("", expression[0].trim()); + } + if (expression.length == 2) { + swizzle[i] = expression[1].trim(); + } + } + } + + mapping.setLeftVariable(variables[0]); + mapping.setLeftSwizzling(swizzle[0] != null ? swizzle[0] : ""); + + if (rightExpression != null) { + mapping.setRightExpression(rightExpression); + } else { + mapping.setRightVariable(variables[1]); + mapping.setRightSwizzling(swizzle[1] != null ? swizzle[1] : ""); + } + + if (cond.length > 1) { + extractCondition(cond[1], statement); + mapping.setCondition(conditionParser.getFormattedExpression()); + } + + return mapping; + } + + /** + * reads the FragmentShaderNodes{} block + * + * @param statements the list of statements to parse + * @throws IOException + */ + public void readFragmentShaderNodes(List statements) throws IOException { + readNodes(statements); + } + + /** + * Reads a Shader statement of this form : + * + * @param statement + * @throws IOException + */ + protected void readShaderStatement(Statement statement) throws IOException { + String[] split = statement.getLine().split(":"); + if (split.length != 2) { + throw new MatParseException("Shader statement syntax incorrect", statement); + } + String[] typeAndLang = split[0].split("\\p{javaWhitespace}+"); + if (typeAndLang.length != 2) { + throw new MatParseException("Shader statement syntax incorrect", statement); + } + shaderName = split[1].trim(); + shaderLanguage = typeAndLang[1]; + } + + /** + * Sets the technique definition currently being loaded + * + * @param techniqueDef the technique def + */ + public void setTechniqueDef(TechniqueDef techniqueDef) { + this.techniqueDef = techniqueDef; + } + + /** + * sets the material def currently being loaded + * + * @param materialDef + */ + public void setMaterialDef(MaterialDef materialDef) { + this.materialDef = materialDef; + } + + /** + * Searches a variable in the given list and updates its type and namespace. + * + * @param var the variable to update. + * @param list the variables list. + * @return true if the variable has been found and updated. + */ + protected boolean updateVariableFromList(ShaderNodeVariable var, List list) { + for (ShaderNodeVariable shaderNodeVariable : list) { + if (shaderNodeVariable.getName().equals(var.getName())) { + var.setType(shaderNodeVariable.getType()); + var.setMultiplicity(shaderNodeVariable.getMultiplicity()); + var.setNameSpace(shaderNode.getName()); + return true; + } + } + return false; + } + + /** + * Updates the type of the right variable of a mapping from the type of the + * left variable. + * + * @param mapping the mapping to consider. + */ + protected void updateRightTypeFromLeftType(VariableMapping mapping) { + String type = mapping.getLeftVariable().getType(); + int card = ShaderUtils.getCardinality(type, mapping.getRightSwizzling()); + if (card > 0) { + if (card == 1) { + type = "float"; + } else { + type = "vec" + card; + } + } + mapping.getRightVariable().setType(type); + } + + /** + * Checks if once a mapping expression is split by "=" the resulting array + * have 2 elements. + * + * @param vars the array. + * @param statement the statement. + * @throws MatParseException if the array isn't correct. + */ + protected void checkMappingFormat(String[] vars, Statement statement) throws MatParseException { + if (vars.length != 2) { + throw new MatParseException("Not a valid expression should be '[.] = " + + ".[.][:Condition]'", statement); + } + } + + /** + * Finds a {@link MatParam} in the {@link MaterialDef} from the given name. + * + * @param varName the material param name. + * @return the found {@link MatParam} or null. + */ + protected MatParam findMatParam(String varName) { + for (MatParam matParam : materialDef.getMaterialParams()) { + if (varName.equals(matParam.getName())) { + return matParam; + } + } + return null; + } + + /** + * finds an UniformBinding representing a WorldParam from the techniqueDef + * + * @param varName the name of the WorldParam + * @return the corresponding UniformBinding to the WorldParam + */ + protected UniformBinding findWorldParam(String varName) { + for (UniformBinding worldParam : techniqueDef.getWorldBindings()) { + if (varName.equals(worldParam.toString())) { + return worldParam; + } + } + return null; + } + + /** + * updates the right variable of the given mapping from a UniformBinding (a + * WorldParam) it checks if the uniform hasn't already been loaded, add it + * to the maps if not. + * + * @param param the WorldParam UniformBinding + * @param mapping the mapping + * @param map the map of uniforms to search into + * @return true if the param was added to the map + */ + protected boolean updateRightFromUniforms(UniformBinding param, VariableMapping mapping, Map map) { + + ShaderNodeVariable right = mapping.getRightVariable(); + String name = param.toString(); + + DeclaredVariable dv = map.get(name); + if (dv == null) { + right.setType(param.getGlslType()); + right.setName(name); + right.setPrefix("g_"); + dv = new DeclaredVariable(right); + map.put(right.getName(), dv); + dv.addNode(shaderNode); + mapping.setRightVariable(right); + return true; + } + dv.addNode(shaderNode); + mapping.setRightVariable(dv.var); + return false; + } + + /** + * Updates the right variable of the given mapping from a {@link MatParam} (a + * WorldParam) it checks if the uniform hasn't already been loaded, add it + * to the maps if not. + * + * @param param the mat param. + * @param mapping the mapping. + * @param map the map of uniforms to search into. + * @return true if the param was added to the map. + */ + public boolean updateRightFromUniforms(MatParam param, VariableMapping mapping, Map map, + Statement statement) throws MatParseException { + + final ShaderNodeVariable left = mapping.getLeftVariable(); + final ShaderNodeVariable right = mapping.getRightVariable(); + + DeclaredVariable dv = map.get(param.getName()); + + if (dv == null) { + + right.setType(param.getVarType().getGlslType()); + right.setName(param.getName()); + right.setPrefix("m_"); + + if (left.getMultiplicity() != null) { + + if (!param.getVarType().name().endsWith("Array")) { + throw new MatParseException(param.getName() + " is not of Array type", statement); + } + + String multiplicity = left.getMultiplicity(); + try { + Integer.parseInt(multiplicity); + } catch (final NumberFormatException nfe) { + // multiplicity is not an int attempting to find for a material parameter. + MatParam mp = findMatParam(multiplicity); + if (mp != null) { + // It's tied to a material param, let's create a define and use this as the multiplicity + addDefine(multiplicity, VarType.Int); + multiplicity = multiplicity.toUpperCase(); + left.setMultiplicity(multiplicity); + // only declare the variable if the define is defined. + left.setCondition(mergeConditions(left.getCondition(), "defined(" + multiplicity + ")", "||")); + } else { + throw new MatParseException("Wrong multiplicity for variable" + left.getName() + ". " + + multiplicity + " should be an int or a declared material parameter.", statement); + } + } + + // the right variable must have the same multiplicity and the same condition. + right.setMultiplicity(multiplicity); + right.setCondition(left.getCondition()); + } + + dv = new DeclaredVariable(right); + map.put(right.getName(), dv); + dv.addNode(shaderNode); + mapping.setRightVariable(right); + return true; + } + + dv.addNode(shaderNode); + mapping.setRightVariable(dv.var); + + return false; + } + + /** + * Updates a variable from the attribute list. + * + * @param right the variable + * @param mapping the mapping + */ + public void updateVarFromAttributes(ShaderNodeVariable right, VariableMapping mapping) { + DeclaredVariable dv = attributes.get(right.getName()); + if (dv == null) { + dv = new DeclaredVariable(right); + attributes.put(right.getName(), dv); + updateRightTypeFromLeftType(mapping); + } else { + mapping.setRightVariable(dv.var); + } + dv.addNode(shaderNode); + } + + /** + * Adds a define to the technique def + * + * @param paramName + */ + public void addDefine(String paramName, VarType paramType) { + if (techniqueDef.getShaderParamDefine(paramName) == null) { + techniqueDef.addShaderParamDefine(paramName, paramType, paramName.toUpperCase()); + } + } + + /** + * Finds a variable with the given name from the list of variable. + * + * @param vars the list of shader node variables. + * @param rightVarName the variable name to search for. + * @return the found variable or null is not found. + */ + public ShaderNodeVariable findNodeOutput(List vars, String rightVarName) { + ShaderNodeVariable var = null; + for (ShaderNodeVariable variable : vars) { + if (variable.getName().equals(rightVarName)) { + var = variable; + } + } + return var; + } + + /** + * Extracts and checks a condition expression. + * + * @param condition the condition expression. + * @param statement the statement being read. + * @throws MatParseException if the condition isn't valid. + */ + public void extractCondition(String condition, Statement statement) throws MatParseException { + List defines = conditionParser.extractDefines(condition); + for (String string : defines) { + MatParam param = findMatParam(string); + if (param != null) { + addDefine(param.getName(), param.getVarType()); + } else { + throw new MatParseException("Invalid condition, condition must match a Material Parameter named " + condition, statement); + } + } + } + + /** + * Reads an input mapping. + * + * @param statement the statement being read. + * @return the variable mapping. + * @throws MatParseException if we have a problem with parsing input mapping statement. + */ + public VariableMapping readInputMapping(Statement statement) throws MatParseException { + + VariableMapping mapping; + try { + mapping = parseMapping(statement, IM_HAS_NAME_SPACE); + } catch (final Exception e) { + throw new MatParseException("Unexpected mapping format", statement, e); + } + + final ShaderNodeDefinition definition = shaderNode.getDefinition(); + final ShaderNodeVariable left = mapping.getLeftVariable(); + final ShaderNodeVariable right = mapping.getRightVariable(); + final String expression = mapping.getRightExpression(); + + if (!updateVariableFromList(left, definition.getInputs())) { + throw new MatParseException(left.getName() + " is not an input variable of " + definition.getName(), statement); + } else if (left.getType().startsWith("sampler") && (right == null || !right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_MAT_PARAM))) { + throw new MatParseException("Samplers can only be assigned to MatParams", statement); + } + + if (right == null && expression == null) { + throw new MatParseException("The mapping doesn't have a right variable or a right expression.", statement); + } + + if (right == null) { + return mapping; + } + + if (right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_GLOBAL)) { + right.setType("vec4"); // Globals are all vec4 for now (maybe forever...) + storeGlobal(right, statement); + } else if (right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_VERTEX_ATTRIBUTE)) { + if (definition.getType() == ShaderType.Fragment) { + throw new MatParseException("Cannot have an attribute as input in a fragment shader" + right.getName(), statement); + } + updateVarFromAttributes(mapping.getRightVariable(), mapping); + storeAttribute(mapping.getRightVariable()); + } else if (right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_MAT_PARAM)) { + + MatParam param = findMatParam(right.getName()); + if (param == null) { + throw new MatParseException("Could not find a Material Parameter named " + right.getName(), statement); + } + + if (definition.getType() == ShaderType.Vertex) { + if (updateRightFromUniforms(param, mapping, vertexDeclaredUniforms, statement)) { + updateMaterialTextureType(statement, mapping, left, param); + storeVertexUniform(mapping.getRightVariable()); + } + } else { + if (updateRightFromUniforms(param, mapping, fragmentDeclaredUniforms, statement)) { + updateMaterialTextureType(statement, mapping, left, param); + storeFragmentUniform(mapping.getRightVariable()); + } + } + + } else if (right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_WORLD_PARAM)) { + + UniformBinding worldParam = findWorldParam(right.getName()); + if (worldParam == null) { + throw new MatParseException("Could not find a World Parameter named " + right.getName(), statement); + } + + if (definition.getType() == ShaderType.Vertex) { + if (updateRightFromUniforms(worldParam, mapping, vertexDeclaredUniforms)) { + storeVertexUniform(mapping.getRightVariable()); + } + } else { + if (updateRightFromUniforms(worldParam, mapping, fragmentDeclaredUniforms)) { + storeFragmentUniform(mapping.getRightVariable()); + } + } + + } else { + + ShaderNode node = nodes.get(right.getNameSpace()); + + if (node == null) { + throw new MatParseException("Undeclared node" + right.getNameSpace() + + ". Make sure this node is declared before the current node", statement); + } + + ShaderNodeVariable var = findNodeOutput(node.getDefinition().getOutputs(), right.getName()); + + if (var == null) { + throw new MatParseException("Cannot find output variable" + right.getName() + + " form ShaderNode " + node.getName(), statement); + } + + right.setNameSpace(node.getName()); + right.setType(var.getType()); + right.setMultiplicity(var.getMultiplicity()); + + mapping.setRightVariable(right); + + storeVaryings(node, mapping.getRightVariable()); + } + + checkTypes(mapping, statement); + + return mapping; + } + + /** + * Updates the material texture type of the variable mapping. + * + * @param statement the statement. + * @param mapping the variable mapping. + * @param left the left variable. + * @param param the material parameter. + * @throws MatParseException if the texture type isn't valid. + */ + private void updateMaterialTextureType(final Statement statement, final VariableMapping mapping, + final ShaderNodeVariable left, final MatParam param) throws MatParseException { + + if (!mapping.getRightVariable().getType().contains("|")) { + return; + } + + final String type = fixSamplerType(left.getType(), mapping.getRightVariable().getType()); + + if (type != null) { + mapping.getRightVariable().setType(type); + } else { + throw new MatParseException(param.getVarType().toString() + " can only be matched to one of " + + param.getVarType().getGlslType().replaceAll("\\|", ",") + " found " + left.getType(), statement); + } + } + + /** + * Reads an output mapping. + * + * @param statement the statement being read. + * @return the mapping + * @throws MatParseException if we have a problem with parsing the statement. + */ + public VariableMapping readOutputMapping(Statement statement) throws MatParseException { + + VariableMapping mapping; + try { + mapping = parseMapping(statement, OM_HAS_NAME_SPACE); + } catch (final Exception e) { + throw new MatParseException("Unexpected mapping format", statement, e); + } + + final ShaderNodeDefinition definition = shaderNode.getDefinition(); + final ShaderNodeVariable left = mapping.getLeftVariable(); + final ShaderNodeVariable right = mapping.getRightVariable(); + + if (left.getType().startsWith("sampler") || right.getType().startsWith("sampler")) { + throw new MatParseException("Samplers can only be inputs", statement); + } + + if (left.getNameSpace().equals(ShaderGenerator.NAME_SPACE_GLOBAL)) { + left.setType("vec4"); // Globals are all vec4 for now (maybe forever...) + storeGlobal(left, statement); + } else { + throw new MatParseException("Only Global nameSpace is allowed for outputMapping, got" + left.getNameSpace(), statement); + } + + if (!updateVariableFromList(right, definition.getOutputs())) { + throw new MatParseException(right.getName() + " is not an output variable of " + definition.getName(), statement); + } + + checkTypes(mapping, statement); + + return mapping; + } + + /** + * Reads a list of ShaderNodes + * + * @param statements the list of statements to read + * @throws IOException + */ + public void readNodes(List statements) throws IOException { + if (techniqueDef.getShaderNodes() == null) { + techniqueDef.setShaderNodes(new ArrayList()); + techniqueDef.setShaderGenerationInfo(new ShaderGenerationInfo()); + } + + for (Statement statement : statements) { + String[] split = statement.getLine().split("[ \\{]"); + if (statement.getLine().startsWith("ShaderNode ")) { + String name = statement.getLine().substring("ShaderNode".length()).trim(); + if (nodes == null) { + nodes = new HashMap(); + } + if (!nodes.containsKey(name)) { + shaderNode = new ShaderNode(); + shaderNode.setName(name); + techniqueDef.getShaderGenerationInfo().getUnusedNodes().add(name); + readShaderNode(statement.getContents()); + nodes.put(name, shaderNode); + techniqueDef.getShaderNodes().add(shaderNode); + } else { + throw new MatParseException("ShaderNode " + name + " is already defined", statement); + } + + } else { + throw new MatParseException("ShaderNode", split[0], statement); + } + } + } + + /** + * retrieve the leftType corresponding sampler type from the rightType + * + * @param leftType the left samplerType + * @param rightType the right sampler type (can be multiple types separated + * by "|" + * @return the type or null if not found + */ + public String fixSamplerType(String leftType, String rightType) { + String[] types = rightType.split("\\|"); + for (String string : types) { + if (leftType.equals(string)) { + return string; + } + } + return null; + } + + /** + * Stores a global output. + * + * @param var the variable to store. + * @param varStatement the statement being read. + * @throws MatParseException if we have duplicates of a global vertex output variable. + */ + public void storeGlobal(ShaderNodeVariable var, Statement varStatement) throws MatParseException { + var.setShaderOutput(true); + + final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); + final ShaderNodeDefinition definition = shaderNode.getDefinition(); + + if (definition.getType() == ShaderType.Vertex) { + + ShaderNodeVariable global = generationInfo.getVertexGlobal(); + + if (global != null) { + + if (!global.getName().equals(var.getName())) { + throw new MatParseException("A global output is already defined for the vertex shader: " + + global.getName() + ". vertex shader can only have one global output", varStatement); + } + + } else { + generationInfo.setVertexGlobal(var); + } + + } else if (definition.getType() == ShaderType.Fragment) { + storeVariable(var, generationInfo.getFragmentGlobals()); + } + } + + /** + * Stores an attribute. + * + * @param var the variable to store. + */ + public void storeAttribute(ShaderNodeVariable var) { + storeVariable(var, techniqueDef.getShaderGenerationInfo().getAttributes()); + } + + /** + * Stores a vertex uniform. + * + * @param var the variable to store. + */ + public void storeVertexUniform(ShaderNodeVariable var) { + storeVariable(var, techniqueDef.getShaderGenerationInfo().getVertexUniforms()); + } + + /** + * store a fragment uniform + * + * @param var the variable to store + */ + public void storeFragmentUniform(ShaderNodeVariable var) { + storeVariable(var, techniqueDef.getShaderGenerationInfo().getFragmentUniforms()); + } + + /** + * sets the assetManager + * + * @param assetManager + */ + public void setAssetManager(AssetManager assetManager) { + this.assetManager = assetManager; + } + + /** + * Find the definition from this statement (loads it if necessary) + * + * @param statement the statement being read + * @return the definition + * @throws IOException + */ + public ShaderNodeDefinition findDefinition(Statement statement) throws IOException { + + final String defLine[] = statement.getLine().split(":"); + + if (defLine.length != 3) { + throw new MatParseException("Can't find shader node definition for: ", statement); + } + + final Map nodeDefinitions = getNodeDefinitions(); + final String definitionName = defLine[1].trim(); + final String definitionPath = defLine[2].trim(); + final String fullName = definitionName + ":" + definitionPath; + + ShaderNodeDefinition def = nodeDefinitions.get(fullName); + if (def != null) { + return def; + } + + List defs; + try { + defs = assetManager.loadAsset(new ShaderNodeDefinitionKey(definitionPath)); + } catch (final AssetNotFoundException e) { + throw new MatParseException("Couldn't find " + definitionPath, statement, e); + } + + for (final ShaderNodeDefinition definition : defs) { + if (definitionName.equals(definition.getName())) { + def = definition; + } + final String key = definition.getName() + ":" + definitionPath; + if (!(nodeDefinitions.containsKey(key))) { + nodeDefinitions.put(key, definition); + } + } + + if (def == null) { + throw new MatParseException(definitionName + " is not a declared as Shader Node Definition", statement); + } + + return def; + } + + /** + * store a varying + * + * @param node the shaderNode + * @param variable the variable to store + */ + public void storeVaryings(ShaderNode node, ShaderNodeVariable variable) { + variable.setShaderOutput(true); + + final ShaderNodeDefinition nodeDefinition = node.getDefinition(); + final ShaderNodeDefinition currentDefinition = shaderNode.getDefinition(); + + if (nodeDefinition.getType() != ShaderType.Vertex || + currentDefinition.getType() != ShaderType.Fragment) { + return; + } + + final String fullName = node.getName() + "." + variable.getName(); + + DeclaredVariable declaredVar = varyings.get(fullName); + + if (declaredVar == null) { + techniqueDef.getShaderGenerationInfo().getVaryings().add(variable); + declaredVar = new DeclaredVariable(variable); + varyings.put(fullName, declaredVar); + } + + declaredVar.addNode(shaderNode); + + // if a variable is declared with the same name as an input and an output and is a varying, + // set it as a shader output so it's declared as a varying only once. + for (final VariableMapping variableMapping : node.getInputMapping()) { + final ShaderNodeVariable leftVariable = variableMapping.getLeftVariable(); + if (leftVariable.getName().equals(variable.getName())) { + leftVariable.setShaderOutput(true); + } + } + } + + /** + * merges 2 condition with the given operator + * + * @param condition1 the first condition + * @param condition2 the second condition + * @param operator the operator ("&&" or "||&) + * @return the merged condition + */ + public String mergeConditions(String condition1, String condition2, String operator) { + if (condition1 != null) { + if (condition2 == null) { + return condition1; + } else { + String mergedCondition = "(" + condition1 + ") " + operator + " (" + condition2 + ")"; + return mergedCondition; + } + } else { + return condition2; + } + } + + /** + * Searches a variable in a list from its name and merges the conditions of the + * variables. + * + * @param variable the variable. + * @param varList the variable list. + */ + public void storeVariable(ShaderNodeVariable variable, List varList) { + for (ShaderNodeVariable var : varList) { + if (var.getName().equals(variable.getName())) { + return; + } + } + varList.add(variable); + } + + /** + * check the types of a mapping, left type must match right type take the + * swizzle into account + * + * @param mapping the mapping + * @param statement1 the statement being read + * @throws MatParseException + */ + protected void checkTypes(VariableMapping mapping, Statement statement1) throws MatParseException { + if (!ShaderUtils.typesMatch(mapping)) { + String ls = mapping.getLeftSwizzling().length() == 0 ? "" : "." + mapping.getLeftSwizzling(); + String rs = mapping.getRightSwizzling().length() == 0 ? "" : "." + mapping.getRightSwizzling(); + throw new MatParseException("Type mismatch, cannot convert " + mapping.getRightVariable().getType() + rs + " to " + mapping.getLeftVariable().getType() + ls, statement1); + } + if (!ShaderUtils.multiplicityMatch(mapping)) { + String type1 = mapping.getLeftVariable().getType() + "[" + mapping.getLeftVariable().getMultiplicity() + "]"; + String type2 = mapping.getRightVariable().getType() + "[" + mapping.getRightVariable().getMultiplicity() + "]"; + throw new MatParseException("Type mismatch, cannot convert " + type1 + " to " + type2, statement1); + } + } + + private Map getNodeDefinitions() { + if (nodeDefinitions == null) { + nodeDefinitions = new HashMap<>(); + } + return nodeDefinitions; + } + + + public void clear() { + nodeDefinitions.clear(); + nodes.clear(); + shaderNodeDefinition = null; + shaderNode = null; + techniqueDef = null; + attributes.clear(); + vertexDeclaredUniforms.clear(); + fragmentDeclaredUniforms.clear(); + varyings.clear(); + materialDef = null; + shaderLanguage = ""; + shaderName = ""; + varNames = ""; + assetManager = null; + nulledConditions.clear(); + } +} diff --git a/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java b/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java new file mode 100644 index 0000000..601bcbe --- /dev/null +++ b/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java @@ -0,0 +1,673 @@ +/* + * Copyright (c) 2009-2012 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.shader; + +import com.jme3.asset.AssetManager; +import com.jme3.material.ShaderGenerationInfo; +import com.jme3.material.plugins.ConditionParser; +import com.jme3.shader.Shader.ShaderType; + +import java.util.ArrayList; +import java.util.List; + +/** + * This shader Generator can generate Vertex and Fragment shaders from + * shadernodes for GLSL 1.0 + * + * @author Nehon + */ +public class Glsl100ShaderGenerator extends ShaderGenerator { + + /** + * the indentation characters 1à tabulation characters + */ + private final static String INDENTCHAR = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; + + protected ShaderNodeVariable inPosTmp; + + /** + * creates a Glsl100ShaderGenerator + * @param assetManager the assetManager + */ + public Glsl100ShaderGenerator(AssetManager assetManager) { + super(assetManager); + } + + @Override + protected void generateUniforms(StringBuilder source, ShaderGenerationInfo info, ShaderType type) { + generateUniforms(source, type == ShaderType.Vertex ? info.getVertexUniforms() : info.getFragmentUniforms()); + } + + /** + * declare a list of uniforms + * + * @param source the source to append to + * @param uniforms the list of uniforms + */ + protected void generateUniforms(StringBuilder source, List uniforms) { + source.append("\n"); + for (ShaderNodeVariable var : uniforms) { + declareVariable(source, var, false, "uniform"); + } + } + + /** + * {@inheritDoc} + * + * attributes are all declared, inPositon is declared even if it's not in + * the list and it's condition is nulled. + */ + @Override + protected void generateAttributes(StringBuilder source, ShaderGenerationInfo info) { + source.append("\n"); + boolean inPosition = false; + for (ShaderNodeVariable var : info.getAttributes()) { + if (var.getName().equals("inPosition")) { + inPosition = true; + var.setCondition(null); + fixInPositionType(var); + //keep track on the InPosition variable to avoid iterating through attributes again + inPosTmp = var; + } + declareAttribute(source, var); + + } + if (!inPosition) { + inPosTmp = new ShaderNodeVariable("vec3", "inPosition"); + declareAttribute(source, inPosTmp); + } + + } + + @Override + protected void generateVaryings(StringBuilder source, ShaderGenerationInfo info, ShaderType type) { + source.append("\n"); + for (ShaderNodeVariable var : info.getVaryings()) { + declareVarying(source, var, type != ShaderType.Vertex); + } + } + + /** + * {@inheritDoc} + * + * if the declaration contains no code nothing is done, else it's appended + */ + @Override + protected void generateDeclarativeSection(StringBuilder source, ShaderNode shaderNode, String nodeSource, ShaderGenerationInfo info) { + if (nodeSource.replaceAll("\\n", "").trim().length() > 0) { + nodeSource = updateDefinesName(nodeSource, shaderNode); + source.append("\n"); + unIndent(); + startCondition(shaderNode.getCondition(), source); + source.append(nodeSource); + source.append("\n"); + endCondition(shaderNode.getCondition(), source); + indent(); + } + } + + /** + * {@inheritDoc} + * + * Shader outputs are declared and initialized inside the main section + */ + @Override + protected void generateStartOfMainSection(StringBuilder source, ShaderGenerationInfo info, ShaderType type) { + source.append("\n"); + source.append("void main() {\n"); + indent(); + appendIndent(source); + if (type == ShaderType.Vertex) { + declareGlobalPosition(info, source); + } else if (type == ShaderType.Fragment) { + for (ShaderNodeVariable global : info.getFragmentGlobals()) { + declareVariable(source, global, "vec4(1.0)"); + } + } + source.append("\n"); + } + + /** + * {@inheritDoc} + * + * outputs are assigned to built in glsl output. then the main section is + * closed + * + * This code accounts for multi render target and correctly output to + * gl_FragData if several output are declared for the fragment shader + */ + @Override + protected void generateEndOfMainSection(StringBuilder source, ShaderGenerationInfo info, ShaderType type) { + source.append("\n"); + if (type == ShaderType.Vertex) { + appendOutput(source, "gl_Position", info.getVertexGlobal()); + } else if (type == ShaderType.Fragment) { + List globals = info.getFragmentGlobals(); + if (globals.size() == 1) { + appendOutput(source, "gl_FragColor", globals.get(0)); + } else { + int i = 0; + //Multi Render Target + for (ShaderNodeVariable global : globals) { + appendOutput(source, "gl_FragData[" + i + "]", global); + i++; + } + } + } + unIndent(); + appendIndent(source); + source.append("}\n"); + } + + /** + * Appends an output assignment to a shader globalOutputName = + * nameSpace_varName; + * + * @param source the source StringBuilter to append the code. + * @param globalOutputName the name of the global output (can be gl_Position + * or gl_FragColor etc...). + * @param var the variable to assign to the output. + */ + protected void appendOutput(StringBuilder source, String globalOutputName, ShaderNodeVariable var) { + appendIndent(source); + source.append(globalOutputName); + source.append(" = "); + source.append(var.getNameSpace()); + source.append("_"); + source.append(var.getName()); + source.append(";\n"); + } + + /** + * {@inheritDoc} + * + * this methods does things in this order : + * + * 1. declaring and mapping input
+ * variables : variable replaced with MatParams or WorldParams that are Samplers are not + * declared and are replaced by the param actual name in the code. For others + * variables, the name space is appended with a "_" before the variable name + * in the code to avoid names collision between shaderNodes.
+ * + * 2. declaring output variables :
+ * variables are declared if they were not already + * declared as input (inputs can also be outputs) or if they are not + * declared as varyings. The variable name is also prefixed with the s=name + * space and "_" in the shaderNode code
+ * + * 3. append of the actual ShaderNode code
+ * + * 4. mapping outputs to global output if needed
+ * + *
+ * All of this is embed in a #if conditional statement if needed + */ + @Override + protected void generateNodeMainSection(StringBuilder source, ShaderNode shaderNode, String nodeSource, ShaderGenerationInfo info) { + + nodeSource = updateDefinesName(nodeSource, shaderNode); + source.append("\n"); + comment(source, shaderNode, "Begin"); + startCondition(shaderNode.getCondition(), source); + + final List declaredInputs = new ArrayList<>(); + + for (VariableMapping mapping : shaderNode.getInputMapping()) { + + final ShaderNodeVariable rightVariable = mapping.getRightVariable(); + final ShaderNodeVariable leftVariable = mapping.getLeftVariable(); + + //Variables fed with a sampler matparam or world param are replaced by the matparam itself + //It avoids issue with samplers that have to be uniforms. + if (rightVariable != null && isWorldOrMaterialParam(rightVariable) && rightVariable.getType().startsWith("sampler")) { + nodeSource = replace(nodeSource, leftVariable, rightVariable.getPrefix() + rightVariable.getName()); + } else { + + if (leftVariable.getType().startsWith("sampler")) { + throw new IllegalArgumentException("a Sampler must be a uniform"); + } + + map(mapping, source); + } + + String newName = shaderNode.getName() + "_" + leftVariable.getName(); + if (!declaredInputs.contains(newName)) { + nodeSource = replace(nodeSource, leftVariable, newName); + declaredInputs.add(newName); + } + } + + final ShaderNodeDefinition definition = shaderNode.getDefinition(); + + for (final ShaderNodeVariable var : definition.getInputs()) { + + if (var.getDefaultValue() == null) { + continue; + } + + final String fullName = shaderNode.getName() + "_" + var.getName(); + + if (declaredInputs.contains(fullName)) { + continue; + } + + final ShaderNodeVariable variable = new ShaderNodeVariable(var.getType(), shaderNode.getName(), + var.getName(), var.getMultiplicity()); + + if (!isVarying(info, variable)) { + declareVariable(source, variable, var.getDefaultValue(), true, null); + } + + nodeSource = replaceVariableName(nodeSource, variable); + declaredInputs.add(fullName); + } + + for (ShaderNodeVariable var : definition.getOutputs()) { + ShaderNodeVariable v = new ShaderNodeVariable(var.getType(), shaderNode.getName(), var.getName(), var.getMultiplicity()); + if (!declaredInputs.contains(shaderNode.getName() + "_" + var.getName())) { + if (!isVarying(info, v)) { + declareVariable(source, v); + } + nodeSource = replaceVariableName(nodeSource, v); + } + } + + source.append(nodeSource); + + for (VariableMapping mapping : shaderNode.getOutputMapping()) { + map(mapping, source); + } + endCondition(shaderNode.getCondition(), source); + comment(source, shaderNode, "End"); + } + + /** + * declares a variable, embed in a conditional block if needed + * @param source the StringBuilder to use + * @param var the variable to declare + * @param appendNameSpace true to append the nameSpace + "_" + */ + protected void declareVariable(StringBuilder source, ShaderNodeVariable var, boolean appendNameSpace) { + declareVariable(source, var, appendNameSpace, null); + } + + /** + * declares a variable, embed in a conditional block if needed. the namespace is appended with "_" + * @param source the StringBuilder to use + * @param var the variable to declare + */ + protected void declareVariable(StringBuilder source, ShaderNodeVariable var) { + declareVariable(source, var, true, null); + } + + /** + * declares a variable, embed in a conditional block if needed. the namespace is appended with "_" + * @param source the StringBuilder to use + * @param var the variable to declare + * @param value the initialization value to assign the the variable + */ + protected void declareVariable(StringBuilder source, ShaderNodeVariable var, String value) { + declareVariable(source, var, value, true, null); + } + + /** + * declares a variable, embed in a conditional block if needed. + * @param source the StringBuilder to use + * @param var the variable to declare + * @param appendNameSpace true to append the nameSpace + "_" + * @param modifier the modifier of the variable (attribute, varying, in , out,...) + */ + protected void declareVariable(StringBuilder source, ShaderNodeVariable var, boolean appendNameSpace, String modifier) { + declareVariable(source, var, null, appendNameSpace, modifier); + } + + /** + * declares a variable, embed in a conditional block if needed. + * @param source the StringBuilder to use + * @param var the variable to declare + * @param value the initialization value to assign the the variable + * @param appendNameSpace true to append the nameSpace + "_" + * @param modifier the modifier of the variable (attribute, varying, in , out,...) + */ + protected void declareVariable(StringBuilder source, ShaderNodeVariable var, String value, boolean appendNameSpace, String modifier) { + startCondition(var.getCondition(), source); + appendIndent(source); + if (modifier != null) { + source.append(modifier); + source.append(" "); + } + + source.append(var.getType()); + source.append(" "); + if (appendNameSpace) { + source.append(var.getNameSpace()); + source.append("_"); + } + source.append(var.getPrefix()); + source.append(var.getName()); + if (var.getMultiplicity() != null) { + source.append("["); + source.append(var.getMultiplicity().toUpperCase()); + source.append("]"); + } + if (value != null) { + source.append(" = "); + source.append(value); + } + source.append(";\n"); + endCondition(var.getCondition(), source); + } + + /** + * Starts a conditional block + * @param condition the block condition + * @param source the StringBuilder to use + */ + protected void startCondition(String condition, StringBuilder source) { + if (condition != null) { + appendIndent(source); + source.append("#if "); + source.append(condition); + source.append("\n"); + indent(); + } + } + + /** + * Ends a conditional block + * @param condition the block condition + * @param source the StringBuilder to use + */ + protected void endCondition(String condition, StringBuilder source) { + if (condition != null) { + unIndent(); + appendIndent(source); + source.append("#endif\n"); + + } + } + + /** + * Appends a mapping to the source, embed in a conditional block if needed, + * with variables nameSpaces and swizzle. + * + * @param mapping the VariableMapping to append + * @param source the StringBuilder to use + */ + protected void map(VariableMapping mapping, StringBuilder source) { + + final ShaderNodeVariable leftVariable = mapping.getLeftVariable(); + final ShaderNodeVariable rightVariable = mapping.getRightVariable(); + final String rightExpression = mapping.getRightExpression(); + + startCondition(mapping.getCondition(), source); + appendIndent(source); + if (!leftVariable.isShaderOutput()) { + source.append(leftVariable.getType()); + source.append(" "); + } + source.append(leftVariable.getNameSpace()); + source.append("_"); + source.append(leftVariable.getName()); + if (leftVariable.getMultiplicity() != null){ + source.append("["); + source.append(leftVariable.getMultiplicity()); + source.append("]"); + } + + // left swizzle, the variable can't be declared and assigned on the same line. + if (mapping.getLeftSwizzling().length() > 0) { + //initialize the declared variable to 0.0 + source.append(" = "); + source.append(leftVariable.getType()); + source.append("(0.0);\n"); + appendIndent(source); + // assign the value on a new line + source.append(leftVariable.getNameSpace()); + source.append("_"); + source.append(leftVariable.getName()); + source.append("."); + source.append(mapping.getLeftSwizzling()); + } + source.append(" = "); + + if (rightVariable != null) { + + String namePrefix = getAppendableNameSpace(rightVariable); + source.append(namePrefix); + source.append(rightVariable.getPrefix()); + source.append(rightVariable.getName()); + + if (mapping.getRightSwizzling().length() > 0) { + source.append("."); + source.append(mapping.getRightSwizzling()); + } + + } else { + source.append(rightExpression); + } + + source.append(";\n"); + endCondition(mapping.getCondition(), source); + } + + /** + * replaces a variable name in a shaderNode source code by prefixing it + * with its nameSpace and "_" if needed. + * @param nodeSource the source to modify + * @param var the variable to replace + * @return the modified source + */ + protected String replaceVariableName(String nodeSource, ShaderNodeVariable var) { + String namePrefix = getAppendableNameSpace(var); + String newName = namePrefix + var.getName(); + nodeSource = replace(nodeSource, var, newName); + return nodeSource; + } + + /** + * Finds if a variable is a varying + * @param info the ShaderGenerationInfo + * @param v the variable + * @return true is the given variable is a varying + */ + protected boolean isVarying(ShaderGenerationInfo info, ShaderNodeVariable v) { + boolean isVarying = false; + for (ShaderNodeVariable shaderNodeVariable : info.getVaryings()) { + if (shaderNodeVariable.equals(v)) { + isVarying = true; + } + } + return isVarying; + } + + /** + * Appends a comment to the generated code + * @param source the StringBuilder to use + * @param shaderNode the shader node being processed (to append its name) + * @param comment the comment to append + */ + protected void comment(StringBuilder source, ShaderNode shaderNode, String comment) { + appendIndent(source); + source.append("//"); + source.append(shaderNode.getName()); + source.append(" : "); + source.append(comment); + source.append("\n"); + } + + /** + * returns the name space to append for a variable. + * Attributes, WorldParam and MatParam names space must not be appended + * @param var the variable + * @return the namespace to append for this variable + */ + protected String getAppendableNameSpace(ShaderNodeVariable var) { + String namePrefix = var.getNameSpace() + "_"; + if (namePrefix.equals("Attr_") || namePrefix.equals("WorldParam_") || namePrefix.equals("MatParam_")) { + namePrefix = ""; + } + return namePrefix; + } + + /** + * transforms defines name is the shader node code. + * One can use a #if defined(inputVariableName) in a shaderNode code. + * This method is responsible for changing the variable name with the + * appropriate defined based on the mapping condition of this variable. + * Complex condition syntax are handled. + * + * @param nodeSource the sahderNode source code + * @param shaderNode the ShaderNode being processed + * @return the modified shaderNode source. + */ + protected String updateDefinesName(String nodeSource, ShaderNode shaderNode) { + String[] lines = nodeSource.split("\\n"); + ConditionParser parser = new ConditionParser(); + for (String line : lines) { + + if (line.trim().startsWith("#if")) { + List params = parser.extractDefines(line.trim()); + String l = line.trim().replaceAll("defined", "").replaceAll("#if ", "").replaceAll("#ifdef", "");//parser.getFormattedExpression(); + boolean match = false; + for (String param : params) { + for (VariableMapping map : shaderNode.getInputMapping()) { + if ((map.getLeftVariable().getName()).equals(param)) { + if (map.getCondition() != null) { + l = l.replaceAll(param, map.getCondition()); + match = true; + } + } + } + } + if (match) { + nodeSource = nodeSource.replace(line.trim(), "#if " + l); + } + } + } + return nodeSource; + } + + /** + * replaced a variable name in a source code with the given name + * @param nodeSource the source to use + * @param var the variable + * @param newName the new name of the variable + * @return the modified source code + */ + protected String replace(String nodeSource, ShaderNodeVariable var, String newName) { + nodeSource = nodeSource.replaceAll("(?<=\\W)" + var.getName() + "(?=\\W)", newName); + return nodeSource; + } + + /** + * Finds if a variable is a world or a material parameter + * @param var the variable + * @return true if the variable is a Word or material parameter + */ + protected boolean isWorldOrMaterialParam(ShaderNodeVariable var) { + return var.getNameSpace().equals("MatParam") || var.getNameSpace().equals("WorldParam"); + } + + @Override + protected String getLanguageAndVersion(ShaderType type) { + return "GLSL100"; + } + + /** + * appends indentation. + * @param source + */ + protected void appendIndent(StringBuilder source) { + source.append(INDENTCHAR.substring(0, indent)); + } + + /** + * Declares an attribute + * @param source the StringBuilder to use + * @param var the variable to declare as an attribute + */ + protected void declareAttribute(StringBuilder source, ShaderNodeVariable var) { + declareVariable(source, var, false, "attribute"); + } + + /** + * Declares a varying + * @param source the StringBuilder to use + * @param var the variable to declare as an varying + * @param input a boolean set to true if the this varying is an input. + * this in not used in this implementation but can be used in overridings + * implementation + */ + protected void declareVarying(StringBuilder source, ShaderNodeVariable var, boolean input) { + declareVariable(source, var, true, "varying"); + } + + /** + * Decrease indentation with a check so the indent is never negative. + */ + protected void unIndent() { + indent--; + indent = Math.max(0, indent); + } + + /** + * increase indentation with a check so that indentation is never over 10 + */ + protected void indent() { + indent++; + indent = Math.min(10, indent); + } + + /** + * makes sure inPosition attribute is of type vec3 or vec4 + * @param var the inPosition attribute + */ + protected void fixInPositionType(ShaderNodeVariable var) { + if(!var.getType().equals("vec3") || !var.getType().equals("vec4")){ + var.setType("vec3"); + } + } + + /** + * declare and assign the global position in the vertex shader. + * @param info the shader generation info + * @param source the shader source being generated + */ + protected void declareGlobalPosition(ShaderGenerationInfo info, StringBuilder source) { + if(inPosTmp.getType().equals(info.getVertexGlobal().getType())){ + declareVariable(source, info.getVertexGlobal(), "inPosition"); + }else{ + declareVariable(source, info.getVertexGlobal(), "vec4(inPosition,1.0)"); + } + } +} diff --git a/src/main/java/com/jme3/shader/ShaderGenerator.java b/src/main/java/com/jme3/shader/ShaderGenerator.java new file mode 100644 index 0000000..4086036 --- /dev/null +++ b/src/main/java/com/jme3/shader/ShaderGenerator.java @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2009-2012 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.shader; + +import com.jme3.asset.AssetManager; +import com.jme3.material.ShaderGenerationInfo; +import com.jme3.material.TechniqueDef; +import com.jme3.shader.Shader.ShaderType; +import com.jme3.shader.plugins.ShaderAssetKey; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * This class is the base for a shader generator using the ShaderNodes system, + * it contains basis mechanism of generation, but no actual generation code. + * This class is abstract, any Shader generator must extend it. + * + * @author Nehon + */ +public abstract class ShaderGenerator { + + public static final String NAME_SPACE_GLOBAL = "Global"; + public static final String NAME_SPACE_VERTEX_ATTRIBUTE = "Attr"; + public static final String NAME_SPACE_MAT_PARAM = "MatParam"; + public static final String NAME_SPACE_WORLD_PARAM = "WorldParam"; + + /** + * the asset manager + */ + protected AssetManager assetManager; + /** + * indentation value for generation + */ + protected int indent; + /** + * the technique def to use for the shader generation + */ + protected TechniqueDef techniqueDef = null; + /** + * Extension pattern + */ + Pattern extensions = Pattern.compile("(#extension.*\\s+)"); + + private Map imports = new LinkedHashMap<>(); + + /** + * Build a shaderGenerator + * + * @param assetManager + */ + protected ShaderGenerator(AssetManager assetManager) { + this.assetManager = assetManager; + } + + public void initialize(TechniqueDef techniqueDef){ + this.techniqueDef = techniqueDef; + } + + /** + * Generate vertex and fragment shaders for the given technique + * + * @return a Shader program + */ + public Shader generateShader(String definesSourceCode) { + if (techniqueDef == null) { + throw new UnsupportedOperationException("The shaderGenerator was not " + + "properly initialized, call " + + "initialize(TechniqueDef) before any generation"); + } + + String techniqueName = techniqueDef.getName(); + ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); + + Shader shader = new Shader(); + for (ShaderType type : ShaderType.values()) { + String extension = type.getExtension(); + String language = getLanguageAndVersion(type); + String shaderSourceCode = buildShader(techniqueDef.getShaderNodes(), info, type); + + if (shaderSourceCode != null) { + String shaderSourceAssetName = techniqueName + "." + extension; + shader.addSource(type, shaderSourceAssetName, shaderSourceCode, definesSourceCode, language); + } + } + + techniqueDef = null; + return shader; + } + + /** + * This method is responsible for the shader generation. + * + * @param shaderNodes the list of shader nodes + * @param info the ShaderGenerationInfo filled during the Technique loading + * @param type the type of shader to generate + * @return the code of the generated vertex shader + */ + protected String buildShader(List shaderNodes, ShaderGenerationInfo info, ShaderType type) { + if (type == ShaderType.TessellationControl || + type == ShaderType.TessellationEvaluation || + type == ShaderType.Geometry) { + // TODO: Those are not supported. + // Too much code assumes that type is either Vertex or Fragment + return null; + } + + imports.clear(); + + indent = 0; + + StringBuilder sourceDeclaration = new StringBuilder(); + StringBuilder source = new StringBuilder(); + + generateUniforms(sourceDeclaration, info, type); + + if (type == ShaderType.Vertex) { + generateAttributes(sourceDeclaration, info); + } + generateVaryings(sourceDeclaration, info, type); + + generateStartOfMainSection(source, info, type); + + generateDeclarationAndMainBody(shaderNodes, sourceDeclaration, source, info, type); + + generateEndOfMainSection(source, info, type); + + //insert imports backward + int insertIndex = sourceDeclaration.length(); + for (String importSource : imports.values()) { + sourceDeclaration.insert(insertIndex, importSource); + } + + sourceDeclaration.append(source); + + return moveExtensionsUp(sourceDeclaration); + } + + /** + * parses the source and moves all the extensions at the top of the shader source as having extension declarations + * in the middle of a shader is against the specs and not supported by all drivers. + * @param sourceDeclaration + * @return + */ + private String moveExtensionsUp(StringBuilder sourceDeclaration) { + Matcher m = extensions.matcher( sourceDeclaration.toString()); + StringBuilder finalSource = new StringBuilder(); + while(m.find()){ + finalSource.append(m.group()); + } + finalSource.append(m.replaceAll("")); + return finalSource.toString(); + } + + /** + * iterates through shader nodes to load them and generate the shader + * declaration part and main body extracted from the shader nodes, for the + * given shader type + * + * @param shaderNodes the list of shader nodes + * @param sourceDeclaration the declaration part StringBuilder of the shader + * to generate + * @param source the main part StringBuilder of the shader to generate + * @param info the ShaderGenerationInfo + * @param type the Shader type + */ + protected void generateDeclarationAndMainBody(List shaderNodes, StringBuilder sourceDeclaration, StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { + for (ShaderNode shaderNode : shaderNodes) { + if (info.getUnusedNodes().contains(shaderNode.getName())) { + continue; + } + if (shaderNode.getDefinition().getType() == type) { + int index = findShaderIndexFromVersion(shaderNode, type); + String shaderPath = shaderNode.getDefinition().getShadersPath().get(index); + Map sources = (Map) assetManager.loadAsset(new ShaderAssetKey(shaderPath, false)); + String loadedSource = sources.get("[main]"); + for (String name : sources.keySet()) { + if (!name.equals("[main]")) { + imports.put(name, sources.get(name)); + } + } + appendNodeDeclarationAndMain(loadedSource, sourceDeclaration, source, shaderNode, info, shaderPath); + } + } + } + + /** + * Appends declaration and main part of a node to the shader declaration and + * main part. the loadedSource is split by "void main(){" to split + * declaration from main part of the node source code.The trailing "}" is + * removed from the main part. Each part is then respectively passed to + * generateDeclarativeSection and generateNodeMainSection. + * + * @see ShaderGenerator#generateDeclarativeSection + * @see ShaderGenerator#generateNodeMainSection + * + * @param loadedSource the actual source code loaded for this node. + * @param shaderPath path the the shader file + * @param sourceDeclaration the Shader declaration part string builder. + * @param source the Shader main part StringBuilder. + * @param shaderNode the shader node. + * @param info the ShaderGenerationInfo. + */ + protected void appendNodeDeclarationAndMain(String loadedSource, StringBuilder sourceDeclaration, StringBuilder source, ShaderNode shaderNode, ShaderGenerationInfo info, String shaderPath) { + if (loadedSource.length() > 1) { + loadedSource = loadedSource.substring(0, loadedSource.lastIndexOf("}")); + String[] sourceParts = loadedSource.split("\\s*void\\s*main\\s*\\(\\s*\\)\\s*\\{"); + if(sourceParts.length<2){ + throw new IllegalArgumentException("Syntax error in "+ shaderPath +". Cannot find 'void main(){' in \n"+ loadedSource); + } + generateDeclarativeSection(sourceDeclaration, shaderNode, sourceParts[0], info); + generateNodeMainSection(source, shaderNode, sourceParts[1], info); + } else { + //if source is empty, we still call generateNodeMainSection so that mappings can be done. + generateNodeMainSection(source, shaderNode, loadedSource, info); + } + + } + + /** + * returns the language + version of the shader should be something like + * "GLSL100" for glsl 1.0 "GLSL150" for glsl 1.5. + * + * @param type the shader type for which the version should be returned. + * + * @return the shaderLanguage and version. + */ + protected abstract String getLanguageAndVersion(Shader.ShaderType type); + + /** + * generates the uniforms declaration for a shader of the given type. + * + * @param source the source StringBuilder to append generated code. + * @param info the ShaderGenerationInfo. + * @param type the shader type the uniforms have to be generated for. + */ + protected abstract void generateUniforms(StringBuilder source, ShaderGenerationInfo info, ShaderType type); + + /** + * generates the attributes declaration for the vertex shader. There is no + * Shader type passed here as attributes are only used in vertex shaders + * + * @param source the source StringBuilder to append generated code. + * @param info the ShaderGenerationInfo. + */ + protected abstract void generateAttributes(StringBuilder source, ShaderGenerationInfo info); + + /** + * generates the varyings for the given shader type shader. Note that + * varyings are deprecated in glsl 1.3, but this method will still be called + * to generate all non global inputs and output of the shaders. + * + * @param source the source StringBuilder to append generated code. + * @param info the ShaderGenerationInfo. + * @param type the shader type the varyings have to be generated for. + */ + protected abstract void generateVaryings(StringBuilder source, ShaderGenerationInfo info, ShaderType type); + + /** + * Appends the given shaderNode declarative part to the shader declarative + * part. If needed the sahder type can be determined by fetching the + * shaderNode's definition type. + * + * @see ShaderNode#getDefinition() + * @see ShaderNodeDefinition#getType() + * + * @param nodeDecalarationSource the declaration part of the node + * @param source the StringBuilder to append generated code. + * @param shaderNode the shaderNode. + * @param info the ShaderGenerationInfo. + */ + protected abstract void generateDeclarativeSection(StringBuilder source, ShaderNode shaderNode, String nodeDecalarationSource, ShaderGenerationInfo info); + + /** + * generates the start of the shader main section. this method is + * responsible of appending the "void main(){" in the shader and declaring + * all global outputs of the shader + * + * @param source the StringBuilder to append generated code. + * @param info the ShaderGenerationInfo. + * @param type the shader type the section has to be generated for. + */ + protected abstract void generateStartOfMainSection(StringBuilder source, ShaderGenerationInfo info, ShaderType type); + + /** + * generates the end of the shader main section. this method is responsible + * of appending the last "}" in the shader and mapping all global outputs of + * the shader + * + * @param source the StringBuilder to append generated code. + * @param info the ShaderGenerationInfo. + * @param type the shader type the section has to be generated for. + */ + protected abstract void generateEndOfMainSection(StringBuilder source, ShaderGenerationInfo info, ShaderType type); + + /** + * Appends the given shaderNode main part to the shader declarative part. If + * needed the shader type can be determined by fetching the shaderNode's + * definition type. + * + * @see ShaderNode#getDefinition() + * @see ShaderNodeDefinition#getType() + * + * @param source the StringBuilder to append generated code. + * @param shaderNode the shaderNode. + * @param nodeSource the declaration part of the loaded shaderNode source. + * @param info the ShaderGenerationInfo. + */ + protected abstract void generateNodeMainSection(StringBuilder source, ShaderNode shaderNode, String nodeSource, ShaderGenerationInfo info); + + /** + * returns the shaderpath index according to the version of the generator. + * This allow to select the higher version of the shader that the generator + * can handle + * + * @param shaderNode the shaderNode being processed + * @param type the shaderType + * @return the index of the shader path in ShaderNodeDefinition shadersPath + * list + * @throws NumberFormatException + */ + protected int findShaderIndexFromVersion(ShaderNode shaderNode, ShaderType type) throws NumberFormatException { + int index = 0; + List lang = shaderNode.getDefinition().getShadersLanguage(); + int genVersion = Integer.parseInt(getLanguageAndVersion(type).substring(4)); + int curVersion = 0; + for (int i = 0; i < lang.size(); i++) { + int version = Integer.parseInt(lang.get(i).substring(4)); + if (version > curVersion && version <= genVersion) { + curVersion = version; + index = i; + } + } + return index; + } +} diff --git a/src/main/java/com/jme3/shader/ShaderNode.java b/src/main/java/com/jme3/shader/ShaderNode.java new file mode 100644 index 0000000..c31b81a --- /dev/null +++ b/src/main/java/com/jme3/shader/ShaderNode.java @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2009-2012 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.shader; + +import com.jme3.export.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * A ShaderNode is the unit brick part of a shader program. A shader can be + * describe with several shader nodes that are plugged together through inputs + * and outputs. + * + * A ShaderNode is based on a definition that has a shader code, inputs and + * output variables. This node can be activated based on a condition, and has + * input and output mapping. + * + * This class is not intended to be used by JME users directly. It's the + * structure for loading shader nodes from a J3md material definition file + * + * @author Nehon + */ +public class ShaderNode implements Savable, Cloneable { + + private String name; + private ShaderNodeDefinition definition; + private String condition; + + private List inputMapping = new ArrayList<>(); + private List outputMapping = new ArrayList<>(); + + /** + * Creates a shader node. + * + * @param name the name. + * @param definition the shader node definition. + * @param condition the condition to activate this node. + */ + public ShaderNode(String name, ShaderNodeDefinition definition, String condition) { + this.name = name; + this.definition = definition; + this.condition = condition; + } + + /** + * Creates a shader node. + */ + public ShaderNode() { + } + + /** + * Gets the name of the node. + * + * @return the name of the node + */ + public String getName() { + return name; + } + + /** + * Sets the name of the node. + * + * @param name the name of the node. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns the shader node definition. + * + * @return the shader node definition. + */ + public ShaderNodeDefinition getDefinition() { + return definition; + } + + /** + * Sets the shader node definition. + * + * @param definition the shader node definition. + */ + public void setDefinition(ShaderNodeDefinition definition) { + this.definition = definition; + } + + /** + * Gets the condition. + * + * @return the condition. + */ + public String getCondition() { + return condition; + } + + /** + * Sets the condition. + * + * @param condition the condition. + */ + public void setCondition(String condition) { + this.condition = condition; + } + + /** + * Returns a list of variable mapping representing the input mappings of this + * node. + * + * @return the input mappings. + */ + public List getInputMapping() { + return inputMapping; + } + + /** + * Sets the input mappings. + * + * @param inputMapping the input mappings. + */ + public void setInputMapping(List inputMapping) { + this.inputMapping = inputMapping; + } + + /** + * Returns a list of variable mapping representing the output mappings of this + * node. + * + * @return the output mappings. + */ + public List getOutputMapping() { + return outputMapping; + } + + /** + * Sets the output mappings. + * + * @param outputMapping the output mappings. + */ + public void setOutputMapping(List outputMapping) { + this.outputMapping = outputMapping; + } + + /** + * jme serialization + * + * @param ex the exporter + * @throws IOException + */ + @Override + public void write(JmeExporter ex) throws IOException { + OutputCapsule oc = ex.getCapsule(this); + oc.write(name, "name", ""); + oc.write(definition, "definition", null); + oc.write(condition, "condition", null); + oc.writeSavableArrayList((ArrayList) inputMapping, "inputMapping", new ArrayList()); + oc.writeSavableArrayList((ArrayList) outputMapping, "outputMapping", new ArrayList()); + } + + /** + * jme serialization + * + * @param im the importer + * @throws IOException + */ + @Override + public void read(JmeImporter im) throws IOException { + InputCapsule ic = im.getCapsule(this); + name = ic.readString("name", ""); + definition = (ShaderNodeDefinition) ic.readSavable("definition", null); + condition = ic.readString("condition", null); + inputMapping = (List) ic.readSavableArrayList("inputMapping", new ArrayList()); + outputMapping = (List) ic.readSavableArrayList("outputMapping", new ArrayList()); + } + + /** + * convenience tostring + * + * @return a string + */ + @Override + public String toString() { + + final StringBuilder builder = new StringBuilder("ShaderNode:"); + builder.append("\n\tname=").append(name) + .append("\n\tdefinition=").append(definition.getName()) + .append("\n\tcondition=").append(condition); + + if (!inputMapping.isEmpty()) { + builder.append("\n\tinputMapping:\n"); + for (final VariableMapping mapping : inputMapping) { + builder.append("\t\t").append(mapping).append('\n'); + } + } + + if (!outputMapping.isEmpty()) { + builder.append("\n\toutputMapping:\n"); + for (final VariableMapping mapping : outputMapping) { + builder.append("\t\t").append(mapping).append('\n'); + } + } + + if (builder.charAt(builder.length() - 1) == '\n') { + builder.delete(builder.length() - 1, builder.length()); + } + + return builder.toString(); + } + + @Override + public ShaderNode clone() throws CloneNotSupportedException { + ShaderNode clone = (ShaderNode) super.clone(); + + // No need to clone the definition. + clone.definition = definition; + + clone.inputMapping = new ArrayList<>(); + for (VariableMapping variableMapping : inputMapping) { + clone.inputMapping.add(variableMapping.clone()); + } + + clone.outputMapping = new ArrayList<>(); + for (VariableMapping variableMapping : outputMapping) { + clone.outputMapping.add(variableMapping.clone()); + } + + return clone; + } +} diff --git a/src/main/java/com/jme3/shader/ShaderNodeVariable.java b/src/main/java/com/jme3/shader/ShaderNodeVariable.java new file mode 100644 index 0000000..bbb0761 --- /dev/null +++ b/src/main/java/com/jme3/shader/ShaderNodeVariable.java @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2009-2012 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.shader; + +import com.jme3.export.InputCapsule; +import com.jme3.export.JmeExporter; +import com.jme3.export.JmeImporter; +import com.jme3.export.OutputCapsule; +import com.jme3.export.Savable; +import java.io.IOException; + +/** + * A shader node variable + * + * @author Nehon + */ +public class ShaderNodeVariable implements Savable, Cloneable { + + private String prefix = ""; + private String name; + private String type; + private String nameSpace; + private String condition; + private String multiplicity; + private String defaultValue; + + private boolean shaderOutput = false; + + /** + * creates a ShaderNodeVariable + * + * @param type the glsl type of the variable + * @param name the name of the variable + */ + public ShaderNodeVariable(String type, String name) { + this.name = name; + this.type = type; + } + + /** + * creates a ShaderNodeVariable + * + * @param type the glsl type of the variable + * @param nameSpace the nameSpace (can be the name of the shaderNode or + * Global,Attr,MatParam,WorldParam) + * @param name the name of the variable + * @param multiplicity the number of element if this variable is an array. Can be an Int of a declared material parameter + */ + public ShaderNodeVariable(String type, String nameSpace, String name, String multiplicity) { + this.name = name; + this.nameSpace = nameSpace; + this.type = type; + this.multiplicity = multiplicity; + } + + + /** + * creates a ShaderNodeVariable + * + * @param type the glsl type of the variable + * @param nameSpace the nameSpace (can be the name of the shaderNode or + * Global,Attr,MatParam,WorldParam) + * @param name the name of the variable + * @param multiplicity the number of element if this variable is an array. Can be an Int of a declared material parameter + * @param prefix the variable prefix to append at generation times. This is mostly to add the g_ and m_ for uniforms + */ + public ShaderNodeVariable(String type, String nameSpace, String name, String multiplicity, String prefix) { + this(type, nameSpace, name, multiplicity); + this.prefix = prefix; + } + + /** + * creates a ShaderNodeVariable + * + * @param type the glsl type of the variable + * @param nameSpace the nameSpace (can be the name of the shaderNode or + * Global,Attr,MatParam,WorldParam) + * @param name the name of the variable + */ + public ShaderNodeVariable(String type, String nameSpace, String name) { + this.name = name; + this.nameSpace = nameSpace; + this.type = type; + } + + /** + * returns the name + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * sets the name + * + * @param name the name + */ + public void setName(String name) { + this.name = name; + } + + /** + * + * @return the glsl type + */ + public String getType() { + return type; + } + + /** + * sets the glsl type + * + * @param type the type + */ + public void setType(String type) { + this.type = type; + } + + /** + * + * @return the name space (can be the name of the shaderNode or + * Global,Attr,MatParam,WorldParam) + */ + public String getNameSpace() { + return nameSpace; + } + + /** + * @return the variable prefix + */ + public String getPrefix() { + return prefix; + } + + /** + * Sets the variable prefix (m_ or g_) + * + * @param prefix + */ + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + /** + * sets the nameSpace (can be the name of the shaderNode or + * Global,Attr,MatParam,WorldParam) + * + * @param nameSpace + */ + public void setNameSpace(String nameSpace) { + this.nameSpace = nameSpace; + } + + /** + * Gets the default value of this variable. + * + * @return the default value of this variable. + */ + public String getDefaultValue() { + return defaultValue; + } + + /** + * Sets the default value of this variable. + * + * @param defaultValue the default value of this variable. + */ + public void setDefaultValue(final String defaultValue) { + this.defaultValue = defaultValue; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 29 * hash + (name != null?name.hashCode():0); + hash = 29 * hash + (type != null?type.hashCode():0); + hash = 29 * hash + (prefix != null ? prefix.hashCode() : 0); + hash = 29 * hash + (nameSpace != null?nameSpace.hashCode():0); + hash = 29 * hash + (condition != null?condition.hashCode():0); + hash = 29 * hash + (multiplicity != null?multiplicity.hashCode():0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ShaderNodeVariable other = (ShaderNodeVariable) obj; + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) { + return false; + } + if ((this.prefix == null) ? (other.prefix != null) : !this.prefix.equals(other.prefix)) { + return false; + } + if ((this.nameSpace == null) ? (other.nameSpace != null) : !this.nameSpace.equals(other.nameSpace)) { + return false; + } + if ((this.condition == null) ? (other.condition != null) : !this.condition.equals(other.condition)) { + return false; + } + if ((this.multiplicity == null) ? (other.multiplicity != null) : !this.multiplicity.equals(other.multiplicity)) { + return false; + } + return true; + } + + /** + * jme serialization (not used) + * + * @param ex the exporter + * @throws IOException + */ + @Override + public void write(JmeExporter ex) throws IOException { + OutputCapsule oc = ex.getCapsule(this); + oc.write(name, "name", ""); + oc.write(type, "type", ""); + oc.write(prefix, "prefix", ""); + oc.write(nameSpace, "nameSpace", ""); + oc.write(condition, "condition", null); + oc.write(shaderOutput, "shaderOutput", false); + oc.write(multiplicity, "multiplicity", null); + oc.write(defaultValue, "defaultValue", null); + } + + /** + * jme serialization (not used) + * + * @param im the importer + * @throws IOException + */ + @Override + public void read(JmeImporter im) throws IOException { + InputCapsule ic = im.getCapsule(this); + name = ic.readString("name", ""); + type = ic.readString("type", ""); + prefix = ic.readString("pefix", ""); + nameSpace = ic.readString("nameSpace", ""); + condition = ic.readString("condition", null); + shaderOutput = ic.readBoolean("shaderOutput", false); + multiplicity = ic.readString("multiplicity", null); + defaultValue = ic.readString("defaultValue", null); + } + + /** + * + * @return the condition for this variable to be declared + */ + public String getCondition() { + return condition; + } + + /** + * sets the condition + * + * @param condition the condition + */ + public void setCondition(String condition) { + this.condition = condition; + } + + @Override + public String toString() { + return type + ' ' + (nameSpace != null ? (nameSpace + '.') : "") + name; + } + + /** + * + * @return true if this variable is a shader output + */ + public boolean isShaderOutput() { + return shaderOutput; + } + + /** + * sets to true if this variable is a shader output + * + * @param shaderOutput true if this variable is a shader output + */ + public void setShaderOutput(boolean shaderOutput) { + this.shaderOutput = shaderOutput; + } + + /** + * + * @return the number of elements if this variable is an array + */ + public String getMultiplicity() { + return multiplicity; + } + + /** + * sets the number of elements of this variable making it an array + * this value can be a number of can be a define + * @param multiplicity + */ + public void setMultiplicity(String multiplicity) { + this.multiplicity = multiplicity; + } + + @Override + public ShaderNodeVariable clone() throws CloneNotSupportedException { + return (ShaderNodeVariable) super.clone(); + } +} diff --git a/src/main/java/com/jme3/shader/VariableMapping.java b/src/main/java/com/jme3/shader/VariableMapping.java new file mode 100644 index 0000000..93b138f --- /dev/null +++ b/src/main/java/com/jme3/shader/VariableMapping.java @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2009-2012 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.shader; + +import com.jme3.export.*; + +import java.io.IOException; +import java.util.Objects; + +/** + * Represents a mapping between 2 shader node variables or a left shader node variable and a value expression. + * + * @author Nehon + */ +public class VariableMapping implements Savable, Cloneable { + + private ShaderNodeVariable leftVariable; + private ShaderNodeVariable rightVariable; + private String rightExpression; + private String condition; + private String leftSwizzling = ""; + private String rightSwizzling = ""; + + /** + * Creates a VariableMapping. + */ + public VariableMapping() { + } + + /** + * Creates a VariableMapping. + * + * @param leftVariable the left hand side variable of the expression + * @param leftSwizzling the swizzling of the left variable + * @param rightVariable the right hand side variable of the expression + * @param rightSwizzling the swizzling of the right variable + * @param condition the condition for this mapping + */ + public VariableMapping(ShaderNodeVariable leftVariable, String leftSwizzling, ShaderNodeVariable rightVariable, + String rightSwizzling, String condition) { + this.leftVariable = leftVariable; + this.rightVariable = rightVariable; + this.condition = condition; + this.leftSwizzling = Objects.requireNonNull(leftSwizzling); + this.rightSwizzling = Objects.requireNonNull(rightSwizzling); + } + + /** + * Gets the left variable. + * + * @return the left variable. + */ + public ShaderNodeVariable getLeftVariable() { + return leftVariable; + } + + /** + * Sets the left variable. + * + * @param leftVariable the left variable. + */ + public void setLeftVariable(ShaderNodeVariable leftVariable) { + this.leftVariable = leftVariable; + } + + /** + * Gets the right variable. + * + * @return the right variable or null. + */ + public ShaderNodeVariable getRightVariable() { + return rightVariable; + } + + /** + * Sets the right variable. + * + * @param rightVariable the right variable. + */ + public void setRightVariable(ShaderNodeVariable rightVariable) { + this.rightVariable = rightVariable; + } + + /** + * Gets the right expression. + * + * @return the right expression or null. + */ + public String getRightExpression() { + return rightExpression; + } + + /** + * Sets the right expression. + * + * @param rightExpression the right expression. + */ + public void setRightExpression(final String rightExpression) { + this.rightExpression = rightExpression; + } + + /** + * Gets the condition. + * + * @return the condition + */ + public String getCondition() { + return condition; + } + + /** + * Sets the condition. + * + * @param condition the condition or null. + */ + public void setCondition(String condition) { + this.condition = condition; + } + + /** + * Gets the left swizzle. + * + * @return the left swizzle or empty string. + */ + public String getLeftSwizzling() { + return leftSwizzling; + } + + /** + * Sets the left swizzle. + * + * @param leftSwizzling the left swizzle. + */ + public void setLeftSwizzling(String leftSwizzling) { + this.leftSwizzling = Objects.requireNonNull(leftSwizzling); + } + + /** + * Gets the right swizzle. + * + * @return the right swizzle or empty string. + */ + public String getRightSwizzling() { + return rightSwizzling; + } + + /** + * Sets the right swizzle. + * + * @param rightSwizzling the right swizzle. + */ + public void setRightSwizzling(String rightSwizzling) { + this.rightSwizzling = Objects.requireNonNull(rightSwizzling); + } + + /** + * jme serialization (not used) + * + * @param ex the exporter + * @throws IOException + */ + @Override + public void write(JmeExporter ex) throws IOException { + OutputCapsule oc = ex.getCapsule(this); + oc.write(leftVariable, "leftVariable", null); + oc.write(rightVariable, "rightVariable", null); + oc.write(rightExpression, "rightExpression", null); + oc.write(condition, "condition", ""); + oc.write(leftSwizzling, "leftSwizzling", ""); + oc.write(rightSwizzling, "rightSwizzling", ""); + } + + /** + * jme serialization (not used) + * + * @param im the importer + * @throws IOException + */ + @Override + public void read(JmeImporter im) throws IOException { + InputCapsule ic = im.getCapsule(this); + leftVariable = (ShaderNodeVariable) ic.readSavable("leftVariable", null); + rightVariable = (ShaderNodeVariable) ic.readSavable("rightVariable", null); + rightExpression = ic.readString("rightExpression", null); + condition = ic.readString("condition", ""); + leftSwizzling = ic.readString("leftSwizzling", ""); + rightSwizzling = ic.readString("rightSwizzling", ""); + } + + @Override + public String toString() { + + final StringBuilder builder = new StringBuilder(leftVariable.toString()); + + if (!leftSwizzling.isEmpty()) { + builder.append('.').append(leftSwizzling); + } + + builder.append(" = "); + + if (rightVariable != null) { + + builder.append(rightVariable.getType()) + .append(' ') + .append(rightVariable.getNameSpace()) + .append('.') + .append(rightVariable.getName()); + + if (!rightSwizzling.isEmpty()) { + builder.append('.').append(rightSwizzling); + } + + } else if (rightExpression != null) { + builder.append(rightExpression); + } + + if (condition != null && !condition.isEmpty()) { + builder.append(" : ").append(condition); + } + + return builder.toString(); + } + + @Override + protected VariableMapping clone() throws CloneNotSupportedException { + VariableMapping clone = (VariableMapping) super.clone(); + clone.leftVariable = leftVariable.clone(); + if (rightVariable != null) { + clone.rightVariable = rightVariable.clone(); + } + return clone; + } +} diff --git a/src/main/java/com/jme3/shader/glsl/AstShaderGenerator.java b/src/main/java/com/jme3/shader/glsl/AstShaderGenerator.java index 1a57a69..5f9fa5a 100644 --- a/src/main/java/com/jme3/shader/glsl/AstShaderGenerator.java +++ b/src/main/java/com/jme3/shader/glsl/AstShaderGenerator.java @@ -523,7 +523,7 @@ protected void generateNodeMainSection(final StringBuilder source, final ShaderN // Variables fed with a sampler matparam or world param are replaced by the matparam itself // It avoids issue with samplers that have to be uniforms. - if (isWorldOrMaterialParam(rightVariable) && rightVariable.getType().startsWith("sampler")) { + if (rightVariable != null && isWorldOrMaterialParam(rightVariable) && rightVariable.getType().startsWith("sampler")) { nodeSource = replace(nodeSource, leftVariable, rightVariable.getPrefix() + rightVariable.getName()); } else { @@ -758,7 +758,7 @@ private void findAvailableDefinesToDefine(final ShaderNode shaderNode, final Lis for (final VariableMapping mapping : otherInputMapping) { final ShaderNodeVariable variable = mapping.getRightVariable(); - if (!shaderNode.getName().equals(variable.getNameSpace())) { + if (variable == null || !shaderNode.getName().equals(variable.getNameSpace())) { continue; } diff --git a/src/main/java/com/ss/editor/shader/nodes/PluginMessages.java b/src/main/java/com/ss/editor/shader/nodes/PluginMessages.java index 949bd05..ab52649 100644 --- a/src/main/java/com/ss/editor/shader/nodes/PluginMessages.java +++ b/src/main/java/com/ss/editor/shader/nodes/PluginMessages.java @@ -58,6 +58,7 @@ public interface PluginMessages { @NotNull String NODE_ELEMENT_VERTEX_ATTRIBUTE = RESOURCE_BUNDLE.getString("NodeElementVertexAttribute"); @NotNull String NODE_ELEMENT_WORLD_PARAMETER = RESOURCE_BUNDLE.getString("NodeElementWorldParameter"); @NotNull String NODE_ELEMENT_MATERIAL_PARAMETER = RESOURCE_BUNDLE.getString("NodeElementMaterialParameter"); + @NotNull String NODE_ELEMENT_USE_EXPRESSION = RESOURCE_BUNDLE.getString("NodeElementUseExpression"); @NotNull String TREE_NODE_PREVIEW_MATERIAL_SETTINGS = RESOURCE_BUNDLE.getString("TreeNodePreviewMaterialSettings"); @NotNull String TREE_NODE_SHADER_NODE_DEFINITIONS = RESOURCE_BUNDLE.getString("TreeNodeShaderNodeDefinitions"); diff --git a/src/main/java/com/ss/editor/shader/nodes/ShaderNodesEditorPlugin.java b/src/main/java/com/ss/editor/shader/nodes/ShaderNodesEditorPlugin.java index f5fb88f..717407b 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ShaderNodesEditorPlugin.java +++ b/src/main/java/com/ss/editor/shader/nodes/ShaderNodesEditorPlugin.java @@ -1,12 +1,10 @@ package com.ss.editor.shader.nodes; -import com.jme3.asset.AssetManager; import com.jme3.shader.glsl.AstGlsl150ShaderGenerator; import com.jme3.shader.glsl.AstShaderGenerator; -import com.ss.editor.Editor; import com.ss.editor.FileExtensions; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.manager.FileIconManager; import com.ss.editor.manager.ResourceManager; import com.ss.editor.plugin.EditorPlugin; @@ -20,9 +18,10 @@ import com.ss.editor.ui.component.creator.FileCreatorRegistry; import com.ss.editor.ui.component.editor.EditorRegistry; import com.ss.editor.ui.control.property.builder.PropertyBuilderRegistry; -import com.ss.editor.ui.control.tree.node.TreeNodeFactoryRegistry; -import com.ss.editor.ui.css.CSSRegistry; +import com.ss.editor.ui.control.tree.node.factory.TreeNodeFactoryRegistry; +import com.ss.editor.ui.css.CssRegistry; import com.ss.editor.ui.preview.FilePreviewFactoryRegistry; +import com.ss.editor.util.EditorUtil; import com.ss.rlib.plugin.PluginContainer; import com.ss.rlib.plugin.PluginSystem; import com.ss.rlib.plugin.annotation.PluginDescription; @@ -35,8 +34,8 @@ */ @PluginDescription( id = "com.ss.editor.shader.nodes", - version = "1.1.0", - minAppVersion = "1.3.2", + version = "1.1.1", + minAppVersion = "1.7.0", name = "Shader Nodes Tools", description = "The plugin with editors to work with shader node materials." ) @@ -45,37 +44,37 @@ public class ShaderNodesEditorPlugin extends EditorPlugin { @NotNull public static final String PROJECT_FILE_EXTENSION = "j3snm"; - public ShaderNodesEditorPlugin(@NotNull final PluginContainer pluginContainer) { + public ShaderNodesEditorPlugin(@NotNull PluginContainer pluginContainer) { super(pluginContainer); } @Override - public void onAfterCreateJMEContext(@NotNull final PluginSystem pluginSystem) { - super.onAfterCreateJMEContext(pluginSystem); + public void onAfterCreateJmeContext(@NotNull PluginSystem pluginSystem) { + super.onAfterCreateJmeContext(pluginSystem); System.setProperty(AstShaderGenerator.PROP_USE_CASE, "false"); - final AssetManager assetManager = Editor.getInstance().getAssetManager(); + var assetManager = EditorUtil.getAssetManager(); assetManager.setShaderGenerator(new AstGlsl150ShaderGenerator(assetManager)); } - @FXThread + @FxThread @Override - public void onBeforeCreateJavaFXContext(@NotNull final PluginSystem pluginSystem) { - super.onBeforeCreateJavaFXContext(pluginSystem); - final ResourceManager resourceManager = ResourceManager.getInstance(); + public void onBeforeCreateJavaFxContext(@NotNull PluginSystem pluginSystem) { + super.onBeforeCreateJavaFxContext(pluginSystem); + var resourceManager = ResourceManager.getInstance(); resourceManager.registerInterestedFileType(FileExtensions.JME_SHADER_NODE); resourceManager.registerInterestedFileType(FileExtensions.GLSL_LIB); } @Override @FromAnyThread - public void register(@NotNull final CSSRegistry registry) { + public void register(@NotNull CssRegistry registry) { super.register(registry); registry.register("com/ss/editor/shader/nodes/style.css", getClassLoader()); } @Override @FromAnyThread - public void register(@NotNull final FileCreatorRegistry registry) { + public void register(@NotNull FileCreatorRegistry registry) { super.register(registry); registry.register(ShaderNodesProjectFileCreator.DESCRIPTION); registry.register(ShaderNodeDefinitionsFileCreator.DESCRIPTION); @@ -83,7 +82,7 @@ public void register(@NotNull final FileCreatorRegistry registry) { @Override @FromAnyThread - public void register(@NotNull final EditorRegistry registry) { + public void register(@NotNull EditorRegistry registry) { super.register(registry); registry.register(ShaderNodesFileEditor.DESCRIPTION); registry.register(ShaderNodeDefinitionFileEditor.DESCRIPTION); @@ -91,21 +90,21 @@ public void register(@NotNull final EditorRegistry registry) { @Override @FromAnyThread - public void register(@NotNull final TreeNodeFactoryRegistry registry) { + public void register(@NotNull TreeNodeFactoryRegistry registry) { super.register(registry); registry.register(ShaderNodesTreeNodeFactory.getInstance()); } @Override @FromAnyThread - public void register(@NotNull final PropertyBuilderRegistry registry) { + public void register(@NotNull PropertyBuilderRegistry registry) { super.register(registry); registry.register(ShaderNodesPropertyBuilder.getInstance()); } @Override @FromAnyThread - public void register(@NotNull final FileIconManager iconManager) { + public void register(@NotNull FileIconManager iconManager) { super.register(iconManager); iconManager.register((path, extension) -> { if (PROJECT_FILE_EXTENSION.equals(extension)) { @@ -118,7 +117,7 @@ public void register(@NotNull final FileIconManager iconManager) { @Override @FromAnyThread - public void register(@NotNull final FilePreviewFactoryRegistry registry) { + public void register(@NotNull FilePreviewFactoryRegistry registry) { super.register(registry); registry.register(SndFilePreviewFactory.getInstance()); } diff --git a/src/main/java/com/ss/editor/shader/nodes/model/PreviewMaterialSettings.java b/src/main/java/com/ss/editor/shader/nodes/model/PreviewMaterialSettings.java index a3418ac..01b4b47 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/PreviewMaterialSettings.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/PreviewMaterialSettings.java @@ -11,7 +11,7 @@ */ public class PreviewMaterialSettings extends RootMaterialSettings { - public PreviewMaterialSettings(@NotNull final Material material) { + public PreviewMaterialSettings(@NotNull Material material) { super(material); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/ShaderNodesProject.java b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/ShaderNodesProject.java index 5df646d..6c23022 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/ShaderNodesProject.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/ShaderNodesProject.java @@ -6,7 +6,7 @@ import com.jme3.util.clone.Cloner; import com.jme3.util.clone.JmeCloneable; import com.ss.editor.annotation.FromAnyThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.state.TechniqueDefState; import com.ss.editor.util.EditorUtil; import org.jetbrains.annotations.NotNull; @@ -53,7 +53,7 @@ public ShaderNodesProject() { * @param techniqueDefStates the states of technique definitions of this project. */ @FromAnyThread - public void updateTechniqueDefStates(@NotNull final List techniqueDefStates) { + public void updateTechniqueDefStates(@NotNull List techniqueDefStates) { this.techniqueDefStates = new ArrayList<>(techniqueDefStates); } @@ -73,7 +73,7 @@ public void updateTechniqueDefStates(@NotNull final List tech * @param matParams the settings list of preview material. */ @FromAnyThread - public void setMatParams(@NotNull final Collection matParams) { + public void setMatParams(@NotNull Collection matParams) { this.matParams = new ArrayList<>(matParams); } @@ -103,12 +103,12 @@ public void setMatParams(@NotNull final Collection matParams) { * @param materialDefContent the content of material definition. */ @FromAnyThread - public void setMaterialDefContent(@NotNull final String materialDefContent) { + public void setMaterialDefContent(@NotNull String materialDefContent) { this.materialDefContent = materialDefContent; } @Override - @JMEThread + @JmeThread public ShaderNodesProject jmeClone() { try { return (ShaderNodesProject) super.clone(); @@ -118,37 +118,38 @@ public ShaderNodesProject jmeClone() { } @Override - @JMEThread - public void cloneFields(@NotNull final Cloner cloner, @NotNull final Object original) { + @JmeThread + public void cloneFields(@NotNull Cloner cloner, @NotNull Object original) { matParams = cloner.clone(matParams); } @Override - @JMEThread - public void write(@NotNull final JmeExporter ex) throws IOException { + @JmeThread + public void write(@NotNull JmeExporter ex) throws IOException { - final byte[] techStates = EditorUtil.serialize(techniqueDefStates); + var techStates = EditorUtil.serialize(techniqueDefStates); - final OutputCapsule out = ex.getCapsule(this); + var out = ex.getCapsule(this); out.writeSavableArrayList(matParams, "matParams", null); out.write(materialDefContent, "materialDefContent", null); out.write(techStates, "techniqueDefStates", null); } @Override - @JMEThread - public void read(@NotNull final JmeImporter im) throws IOException { + @JmeThread + public void read(@NotNull JmeImporter im) throws IOException { + + var in = im.getCapsule(this); - final InputCapsule in = im.getCapsule(this); matParams = unsafeCast(in.readSavableArrayList("matParams", new ArrayList<>())); materialDefContent = in.readString("materialDefContent", null); - final byte[] techStates = in.readByteArray("techniqueDefStates", null); + var techStates = in.readByteArray("techniqueDefStates", null); if (techStates != null) { try { techniqueDefStates = EditorUtil.deserialize(techStates); - } catch (final RuntimeException e) { + } catch (RuntimeException e) { // we can skip it } } diff --git a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndDocumentation.java b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndDocumentation.java index c429586..44a5e00 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndDocumentation.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndDocumentation.java @@ -17,7 +17,7 @@ public class SndDocumentation { @NotNull private final ShaderNodeDefinition definition; - public SndDocumentation(@NotNull final ShaderNodeDefinition definition) { + public SndDocumentation(@NotNull ShaderNodeDefinition definition) { this.definition = definition; } @@ -45,7 +45,7 @@ public SndDocumentation(@NotNull final ShaderNodeDefinition definition) { * * @param documentation the documentation of this definition. */ - public void setDocumentation(@NotNull final String documentation) { + public void setDocumentation(@NotNull String documentation) { this.definition.setDocumentation(documentation); } @@ -53,14 +53,14 @@ public void setDocumentation(@NotNull final String documentation) { public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final SndDocumentation that = (SndDocumentation) o; + var that = (SndDocumentation) o; if (!definition.equals(that.definition)) return false; return getDocumentation().equals(that.getDocumentation()); } @Override public int hashCode() { - int result = definition.hashCode(); + var result = definition.hashCode(); result = 31 * result + getDocumentation().hashCode(); return result; } diff --git a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndInputParameters.java b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndInputParameters.java index b88cc03..a54a03e 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndInputParameters.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndInputParameters.java @@ -14,7 +14,7 @@ */ public class SndInputParameters extends SndParameters { - public SndInputParameters(@NotNull final ShaderNodeDefinition definition) { + public SndInputParameters(@NotNull ShaderNodeDefinition definition) { super(definition); } diff --git a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndList.java b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndList.java index cdbd83a..7ec26af 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndList.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndList.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.model.shader.node.definition; import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -19,7 +19,7 @@ public class SndList { @NotNull private List definitions; - public SndList(@NotNull final List definitions) { + public SndList(@NotNull List definitions) { this.definitions = definitions; } @@ -28,7 +28,7 @@ public SndList(@NotNull final List definitions) { * * @return the list of definitions. */ - @FXThread + @FxThread public @NotNull List getDefinitions() { return definitions; } diff --git a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndOutputParameters.java b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndOutputParameters.java index e13bd4f..fa37837 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndOutputParameters.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndOutputParameters.java @@ -14,7 +14,7 @@ */ public class SndOutputParameters extends SndParameters { - public SndOutputParameters(@NotNull final ShaderNodeDefinition definition) { + public SndOutputParameters(@NotNull ShaderNodeDefinition definition) { super(definition); } diff --git a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndParameters.java b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndParameters.java index 68a9129..79fa587 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndParameters.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndParameters.java @@ -4,6 +4,7 @@ import com.jme3.shader.ShaderNodeVariable; import com.ss.editor.annotation.FromAnyThread; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -20,7 +21,7 @@ public abstract class SndParameters { @NotNull private final ShaderNodeDefinition definition; - protected SndParameters(@NotNull final ShaderNodeDefinition definition) { + protected SndParameters(@NotNull ShaderNodeDefinition definition) { this.definition = definition; } @@ -43,7 +44,7 @@ protected SndParameters(@NotNull final ShaderNodeDefinition definition) { } @Override - public boolean equals(final Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final SndParameters that = (SndParameters) o; diff --git a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndShaderSource.java b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndShaderSource.java index 10c63f8..a1790a5 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndShaderSource.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndShaderSource.java @@ -3,6 +3,7 @@ import com.jme3.shader.ShaderNodeDefinition; import com.ss.editor.annotation.FromAnyThread; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * The class to present shader sources of a shader node definition. @@ -29,8 +30,11 @@ public class SndShaderSource { @NotNull private final String shaderPath; - public SndShaderSource(@NotNull final ShaderNodeDefinition definition, @NotNull final String language, - @NotNull final String shaderPath) { + public SndShaderSource( + @NotNull ShaderNodeDefinition definition, + @NotNull String language, + @NotNull String shaderPath + ) { this.definition = definition; this.language = language; this.shaderPath = shaderPath; @@ -67,10 +71,10 @@ public SndShaderSource(@NotNull final ShaderNodeDefinition definition, @NotNull } @Override - public boolean equals(final Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final SndShaderSource that = (SndShaderSource) o; + var that = (SndShaderSource) o; if (!definition.equals(that.definition)) return false; if (!language.equals(that.language)) return false; return shaderPath.equals(that.shaderPath); @@ -78,7 +82,7 @@ public boolean equals(final Object o) { @Override public int hashCode() { - int result = definition.hashCode(); + var result = definition.hashCode(); result = 31 * result + language.hashCode(); result = 31 * result + shaderPath.hashCode(); return result; diff --git a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndShaderSources.java b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndShaderSources.java index 8a37182..513020c 100644 --- a/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndShaderSources.java +++ b/src/main/java/com/ss/editor/shader/nodes/model/shader/node/definition/SndShaderSources.java @@ -3,6 +3,7 @@ import com.jme3.shader.ShaderNodeDefinition; import com.ss.editor.annotation.FromAnyThread; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -22,7 +23,7 @@ public class SndShaderSources { @NotNull private final ShaderNodeDefinition definition; - public SndShaderSources(@NotNull final ShaderNodeDefinition definition) { + public SndShaderSources(@NotNull ShaderNodeDefinition definition) { this.definition = definition; } @@ -34,12 +35,12 @@ public SndShaderSources(@NotNull final ShaderNodeDefinition definition) { @FromAnyThread public @NotNull Map getShadeSourceMap() { - final List shadersPath = definition.getShadersPath(); - final List shadersLanguage = definition.getShadersLanguage(); + var shadersPath = definition.getShadersPath(); + var shadersLanguage = definition.getShadersLanguage(); - final Map result = new HashMap<>(); + var result = new HashMap(); - for (int i = 0; i < shadersPath.size(); i++) { + for (var i = 0; i < shadersPath.size(); i++) { result.put(shadersPath.get(i), shadersLanguage.get(i)); } @@ -54,12 +55,12 @@ public SndShaderSources(@NotNull final ShaderNodeDefinition definition) { @FromAnyThread public @NotNull List getShadeSources() { - final List shadersPath = definition.getShadersPath(); - final List shadersLanguage = definition.getShadersLanguage(); + var shadersPath = definition.getShadersPath(); + var shadersLanguage = definition.getShadersLanguage(); - final List result = new ArrayList<>(); + var result = new ArrayList(); - for (int i = 0; i < shadersPath.size(); i++) { + for (var i = 0; i < shadersPath.size(); i++) { result.add(new SndShaderSource(definition, shadersPath.get(i), shadersLanguage.get(i))); } @@ -72,10 +73,10 @@ public SndShaderSources(@NotNull final ShaderNodeDefinition definition) { * @param shaderSource the new shader source. */ @FromAnyThread - public void add(@NotNull final SndShaderSource shaderSource) { + public void add(@NotNull SndShaderSource shaderSource) { - final List shadersPath = definition.getShadersPath(); - final List shadersLanguage = definition.getShadersLanguage(); + var shadersPath = definition.getShadersPath(); + var shadersLanguage = definition.getShadersLanguage(); shadersPath.add(shaderSource.getShaderPath()); shadersLanguage.add(shaderSource.getLanguage()); @@ -88,10 +89,10 @@ public void add(@NotNull final SndShaderSource shaderSource) { * @param shaderSource the new shader source. */ @FromAnyThread - public void add(final int index, @NotNull final SndShaderSource shaderSource) { + public void add(int index, @NotNull SndShaderSource shaderSource) { - final List shadersPath = definition.getShadersPath(); - final List shadersLanguage = definition.getShadersLanguage(); + var shadersPath = definition.getShadersPath(); + var shadersLanguage = definition.getShadersLanguage(); shadersPath.add(index, shaderSource.getShaderPath()); shadersLanguage.add(index, shaderSource.getLanguage()); @@ -103,12 +104,12 @@ public void add(final int index, @NotNull final SndShaderSource shaderSource) { * @param shaderSource the shader source. */ @FromAnyThread - public void remove(@NotNull final SndShaderSource shaderSource) { + public void remove(@NotNull SndShaderSource shaderSource) { - final List shadersPath = definition.getShadersPath(); - final List shadersLanguage = definition.getShadersLanguage(); + var shadersPath = definition.getShadersPath(); + var shadersLanguage = definition.getShadersLanguage(); - final int index = indexOf(shaderSource); + var index = indexOf(shaderSource); if (index == -1) { throw new IllegalArgumentException("not found the shader source " + shaderSource); @@ -125,15 +126,15 @@ public void remove(@NotNull final SndShaderSource shaderSource) { * @return the position or -1. */ @FromAnyThread - public int indexOf(@NotNull final SndShaderSource shaderSource) { + public int indexOf(@NotNull SndShaderSource shaderSource) { - final List shadersPath = definition.getShadersPath(); - final List shadersLanguage = definition.getShadersLanguage(); + var shadersPath = definition.getShadersPath(); + var shadersLanguage = definition.getShadersLanguage(); - for (int i = 0; i < shadersPath.size(); i++) { + for (var i = 0; i < shadersPath.size(); i++) { - final String path = shadersPath.get(i); - final String language = shadersLanguage.get(i); + var path = shadersPath.get(i); + var language = shadersLanguage.get(i); if (path.equals(shaderSource.getShaderPath()) && language.equals(shaderSource.getLanguage())) { return i; @@ -154,10 +155,10 @@ public int indexOf(@NotNull final SndShaderSource shaderSource) { } @Override - public boolean equals(final Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final SndShaderSources that = (SndShaderSources) o; + var that = (SndShaderSources) o; return definition.equals(that.definition); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/PluginCSSClasses.java b/src/main/java/com/ss/editor/shader/nodes/ui/PluginCssClasses.java similarity index 78% rename from src/main/java/com/ss/editor/shader/nodes/ui/PluginCSSClasses.java rename to src/main/java/com/ss/editor/shader/nodes/ui/PluginCssClasses.java index a1fe80f..3b3e373 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/PluginCSSClasses.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/PluginCssClasses.java @@ -7,13 +7,15 @@ * * @author JavaSaBr */ -public interface PluginCSSClasses { +public interface PluginCssClasses { @NotNull String SHADER_NODES_ROOT = "shader-nodes-root"; @NotNull String SHADER_NODE = "shader-node"; @NotNull String SHADER_NODE_HEADER = "header"; @NotNull String SHADER_NODE_PARAMETER = "shader-node-parameter"; @NotNull String SHADER_NODE_INPUT_PARAMETER = "shader-node-input-parameter"; + @NotNull String SHADER_NODE_INPUT_PARAMETER_CONTAINER = "shader-node-input-parameter-container"; + @NotNull String SHADER_NODE_INPUT_PARAMETER_EXPR_LABEL = "shader-node-input-parameter-expr-label"; @NotNull String SHADER_NODE_OUTPUT_PARAMETER = "shader-node-output-parameter"; @NotNull String SHADER_NODE_MATERIAL_OUTPUT_PARAMETER = "shader-node-material-output-parameter"; @NotNull String SHADER_NODE_PARAMETER_SOCKET = "shader-node-parameter-socket"; @@ -24,4 +26,5 @@ public interface PluginCSSClasses { @NotNull String SHADER_CODE_PREVIEW_CONTAINER = "shader-code-preview-component"; @NotNull String SHADER_NODE_DEF_DOCUMENTATION_DIALOG = "shader-node-def-documentation-dialog"; + @NotNull String SHADER_NODE_DEF_DOCUMENTATION_TOOLTIP = "shader-node-def-documentation-tooltip"; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/SndDocumentationArea.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/SndDocumentationArea.java index ef2fb39..e9a715c 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/SndDocumentationArea.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/SndDocumentationArea.java @@ -1,6 +1,6 @@ package com.ss.editor.shader.nodes.ui.component; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.ui.control.code.BaseCodeArea; import org.fxmisc.richtext.model.StyleSpans; import org.jetbrains.annotations.NotNull; @@ -32,13 +32,13 @@ public class SndDocumentationArea extends BaseCodeArea { ); @Override - @FXThread + @FxThread protected @NotNull String[][] getAvailableClasses() { return AVAILABLE_CLASSES; } @Override - @FXThread + @FxThread protected @NotNull StyleSpans> calculateStyleSpans(@NotNull final String text) { return computeHighlighting(PATTERN, text); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/creator/ShaderNodeDefinitionsFileCreator.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/creator/ShaderNodeDefinitionsFileCreator.java index c461f02..8ae61c6 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/creator/ShaderNodeDefinitionsFileCreator.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/creator/ShaderNodeDefinitionsFileCreator.java @@ -9,7 +9,7 @@ import com.jme3.shader.Shader.ShaderType; import com.ss.editor.FileExtensions; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.extension.property.EditablePropertyType; import com.ss.editor.plugin.api.file.creator.GenericFileCreator; @@ -82,15 +82,15 @@ public class ShaderNodeDefinitionsFileCreator extends GenericFileCreator { AVAILABLE_TYPES.add(ShaderType.Vertex.name()); AVAILABLE_TYPES.add(ShaderType.Fragment.name()); - final Renderer renderer = EDITOR.getRenderer(); + var renderer = EditorUtil.getRenderer(); - final EnumSet caps = renderer.getCaps(); + var caps = renderer.getCaps(); caps.stream().filter(cap -> cap.name().startsWith("GLSL")) .map(Enum::name) .sorted(StringUtils::compareIgnoreCase) .forEach(AVAILABLE_GLSL::add); - final InputStream snResource = ShaderNodesProjectFileCreator.class + var snResource = ShaderNodesProjectFileCreator.class .getResourceAsStream("/com/ss/editor/shader/nodes/template/ShaderNodeTemplate.j3sn"); SN_TEMPLATE = FileUtils.read(snResource); @@ -100,7 +100,7 @@ public class ShaderNodeDefinitionsFileCreator extends GenericFileCreator { @FromAnyThread protected @NotNull Array getPropertyDefinitions() { - final Array result = ArrayFactory.newArray(PropertyDefinition.class); + Array result = ArrayFactory.newArray(PropertyDefinition.class); result.add(new PropertyDefinition(EditablePropertyType.STRING, PluginMessages.SND_CREATOR_DEFINITION_NAME, PROP_DEFINITION_NAME, "newShaderNode")); result.add(new PropertyDefinition(EditablePropertyType.STRING_FROM_LIST, @@ -124,37 +124,37 @@ public class ShaderNodeDefinitionsFileCreator extends GenericFileCreator { } @Override - @FXThread + @FxThread protected void processOk() { super.hide(); - final Path shaderNodeFile = notNull(getFileToCreate()); - final Path folder = shaderNodeFile.getParent(); + var shaderNodeFile = notNull(getFileToCreate()); + var folder = shaderNodeFile.getParent(); - final VarTable vars = getVars(); - final String definitionName = vars.getString(PROP_DEFINITION_NAME); - final Caps language = vars.getEnum(PROP_LANGUAGE, Caps.class); - final ShaderType type = vars.getEnum(PROP_TYPE, ShaderType.class); + var vars = getVars(); + var definitionName = vars.getString(PROP_DEFINITION_NAME); + var language = vars.getEnum(PROP_LANGUAGE, Caps.class); + var type = vars.getEnum(PROP_TYPE, ShaderType.class); - final Path shaderFile = folder.resolve(definitionName + "." + type.getExtension()); - final Path assetShaderFile = notNull(getAssetFile(shaderFile)); - final String assetShaderPath = toAssetPath(assetShaderFile); + var shaderFile = folder.resolve(definitionName + "." + type.getExtension()); + var assetShaderFile = notNull(getAssetFile(shaderFile)); + var assetShaderPath = toAssetPath(assetShaderFile); - String result = SN_TEMPLATE.replace("${name}", definitionName); + var result = SN_TEMPLATE.replace("${name}", definitionName); result = result.replace("${type}", type.name()); result = result.replace("${glsl}", language.name()); result = result.replace("${shader_path}", assetShaderPath); - try (final PrintWriter out = new PrintWriter(Files.newOutputStream(shaderNodeFile, WRITE, TRUNCATE_EXISTING, CREATE))) { + try (var out = new PrintWriter(Files.newOutputStream(shaderNodeFile, WRITE, TRUNCATE_EXISTING, CREATE))) { out.print(result); - } catch (final IOException e) { + } catch (IOException e) { EditorUtil.handleException(LOGGER, this, e); return; } - try (final PrintWriter out = new PrintWriter(Files.newOutputStream(shaderFile, WRITE, TRUNCATE_EXISTING, CREATE))) { + try (var out = new PrintWriter(Files.newOutputStream(shaderFile, WRITE, TRUNCATE_EXISTING, CREATE))) { out.print("void main() {\n\n}"); - } catch (final IOException e) { + } catch (IOException e) { EditorUtil.handleException(LOGGER, this, e); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/creator/ShaderNodesProjectFileCreator.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/creator/ShaderNodesProjectFileCreator.java index 3f720b0..8425967 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/creator/ShaderNodesProjectFileCreator.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/creator/ShaderNodesProjectFileCreator.java @@ -52,7 +52,8 @@ public class ShaderNodesProjectFileCreator extends GenericFileCreator { private static final String MD_TEMPLATE; static { - final InputStream mdResource = ShaderNodesProjectFileCreator.class + + var mdResource = ShaderNodesProjectFileCreator.class .getResourceAsStream("/com/ss/editor/shader/nodes/template/MaterialDefinition.j3md"); MD_TEMPLATE = FileUtils.read(mdResource); @@ -62,7 +63,7 @@ public class ShaderNodesProjectFileCreator extends GenericFileCreator { @FromAnyThread protected @NotNull Array getPropertyDefinitions() { - final Array definitions = ArrayFactory.newArray(PropertyDefinition.class); + Array definitions = ArrayFactory.newArray(PropertyDefinition.class); definitions.add(new PropertyDefinition(ENUM, Messages.MODEL_PROPERTY_LIGHT_MODE, PROP_TECHNIQUE_LIGHT_MODE, TechniqueDef.LightMode.SinglePassAndImageBased)); @@ -83,18 +84,18 @@ public class ShaderNodesProjectFileCreator extends GenericFileCreator { @Override @BackgroundThread - protected void writeData(@NotNull final VarTable vars, @NotNull final Path resultFile) throws IOException { + protected void writeData(@NotNull VarTable vars, @NotNull Path resultFile) throws IOException { super.writeData(vars, resultFile); - final TechniqueDef.LightMode lightMode = vars.getEnum(PROP_TECHNIQUE_LIGHT_MODE, TechniqueDef.LightMode.class); - final String updated = MD_TEMPLATE.replace("%light_mode%", lightMode.name()); + var lightMode = vars.getEnum(PROP_TECHNIQUE_LIGHT_MODE, TechniqueDef.LightMode.class); + var updated = MD_TEMPLATE.replace("%light_mode%", lightMode.name()); - final ShaderNodesProject project = new ShaderNodesProject(); + var project = new ShaderNodesProject(); project.setMaterialDefContent(updated); - final BinaryExporter exporter = BinaryExporter.getInstance(); + var exporter = BinaryExporter.getInstance(); - try (final OutputStream out = Files.newOutputStream(resultFile)) { + try (var out = Files.newOutputStream(resultFile)) { exporter.save(project, out); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodeDefinitionFileEditor.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodeDefinitionFileEditor.java index 4dfbba4..4ec9c18 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodeDefinitionFileEditor.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodeDefinitionFileEditor.java @@ -8,15 +8,15 @@ import com.jme3.shader.glsl.parser.GlslParser; import com.ss.editor.FileExtensions; import com.ss.editor.annotation.BackgroundThread; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.extension.property.EditableProperty; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.plugin.api.editor.BaseFileEditorWithSplitRightTool; import com.ss.editor.shader.nodes.PluginMessages; -import com.ss.editor.shader.nodes.ui.component.editor.state.ShaderNodeDefinitionEditorState; import com.ss.editor.shader.nodes.model.shader.node.definition.SndList; import com.ss.editor.shader.nodes.model.shader.node.definition.SndShaderSource; +import com.ss.editor.shader.nodes.ui.component.editor.state.ShaderNodeDefinitionEditorState; import com.ss.editor.shader.nodes.util.J3snExporter; import com.ss.editor.ui.component.editor.EditorDescription; import com.ss.editor.ui.component.editor.state.EditorState; @@ -25,12 +25,15 @@ import com.ss.editor.ui.control.property.PropertyEditor; import com.ss.editor.ui.control.tree.NodeTree; import com.ss.editor.ui.control.tree.node.TreeNode; -import com.ss.editor.ui.css.CSSClasses; +import com.ss.editor.ui.css.CssClasses; +import com.ss.editor.util.EditorUtil; import com.ss.rlib.ui.util.FXUtils; import com.ss.rlib.util.FileUtils; import com.ss.rlib.util.StringUtils; +import com.ss.rlib.util.array.Array; import com.ss.rlib.util.dictionary.DictionaryFactory; import com.ss.rlib.util.dictionary.ObjectDictionary; +import javafx.scene.control.SelectionMode; import javafx.scene.control.SplitPane; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; @@ -118,32 +121,32 @@ public ShaderNodeDefinitionFileEditor() { } @Override - @FXThread - protected void createToolComponents(@NotNull final EditorToolComponent container, @NotNull final StackPane root) { + @FxThread + protected void createToolComponents(@NotNull EditorToolComponent container, @NotNull StackPane root) { super.createToolComponents(container, root); - structureTree = new NodeTree<>(this::selectFromTree, this); + structureTree = new NodeTree<>(this::selectFromTree, this, SelectionMode.SINGLE); propertyEditor = new PropertyEditor<>(this); propertyEditor.prefHeightProperty().bind(root.heightProperty()); container.addComponent(buildSplitComponent(structureTree, propertyEditor, root), PluginMessages.SND_EDITOR_TOOL_STRUCTURE); - FXUtils.addClassTo(structureTree.getTreeView(), CSSClasses.TRANSPARENT_TREE_VIEW); + FXUtils.addClassTo(structureTree.getTreeView(), CssClasses.TRANSPARENT_TREE_VIEW); } - @FXThread + @FxThread @Override - protected void calcVSplitSize(@NotNull final SplitPane splitPane) { + protected void calcVSplitSize(@NotNull SplitPane splitPane) { splitPane.setDividerPosition(0, 0.6); } @Override - @FXThread + @FxThread protected void createEditorAreaPane() { super.createEditorAreaPane(); - final StackPane editorAreaPane = getEditorAreaPane(); + var editorAreaPane = getEditorAreaPane(); codeArea = new GLSLCodeArea(); codeArea.loadContent(""); @@ -157,29 +160,31 @@ protected void createEditorAreaPane() { * * @return the code area. */ - @FXThread + @FxThread private @NotNull GLSLCodeArea getCodeArea() { return notNull(codeArea); } /** - * Handle selected object from the structure tree. + * Handle selected objects from the structure tree. * - * @param object the selected object. + * @param objects the selected objects. */ - @FXThread - private void selectFromTree(@Nullable final Object object) { + @FxThread + private void selectFromTree(@Nullable Array objects) { setEditedShader(null); - final GLSLCodeArea codeArea = getCodeArea(); + var codeArea = getCodeArea(); codeArea.setEditable(false); + var object = objects == null? null : objects.first(); + Object parent = null; Object element; if (object instanceof TreeNode) { - final TreeNode treeNode = (TreeNode) object; - final TreeNode parentNode = treeNode.getParent(); + var treeNode = (TreeNode) object; + var parentNode = treeNode.getParent(); parent = parentNode == null ? null : parentNode.getElement(); element = treeNode.getElement(); } else { @@ -188,17 +193,17 @@ private void selectFromTree(@Nullable final Object object) { if (element instanceof SndShaderSource) { - final SndShaderSource shaderSource = (SndShaderSource) element; - final String code = getGLSLCode(shaderSource.getShaderPath()); + var shaderSource = (SndShaderSource) element; + var code = getGlslCode(shaderSource.getShaderPath()); - EXECUTOR_MANAGER.schedule(() -> { + /* EXECUTOR_MANAGER.schedule(() -> { try { //FIXME to delete GlslParser.newInstance().parseFileDeclaration(shaderSource.getShaderPath(), code); } catch (final Throwable e) { e.printStackTrace(); } - }, 1000); + }, 1000);*/ setEditedShader(shaderSource.getShaderPath()); setIgnoreCodeChanges(true); @@ -218,7 +223,7 @@ private void selectFromTree(@Nullable final Object object) { * * @return the dictionary to store original GLSL code. */ - @FXThread + @FxThread private @NotNull ObjectDictionary getGlslOriginalContent() { return glslOriginalContent; } @@ -228,7 +233,7 @@ private void selectFromTree(@Nullable final Object object) { * * @return the dictionary to track changes of GLSL code. */ - @FXThread + @FxThread private @NotNull ObjectDictionary getGlslChangedContent() { return glslChangedContent; } @@ -238,7 +243,7 @@ private void selectFromTree(@Nullable final Object object) { * * @return the current edited shader. */ - @FXThread + @FxThread private @Nullable String getEditedShader() { return editedShader; } @@ -248,24 +253,28 @@ private void selectFromTree(@Nullable final Object object) { * * @param editedShader the current edited shader. */ - @FXThread - private void setEditedShader(@Nullable final String editedShader) { + @FxThread + private void setEditedShader(@Nullable String editedShader) { this.editedShader = editedShader; } /** + * Return true if need to ignore GLSL code changes. + * * @return true if need to ignore GLSL code changes. */ - @FXThread + @FxThread private boolean isIgnoreCodeChanges() { return ignoreCodeChanges; } /** + * Set true if need to ignore GLSL code changes. + * * @param ignoreCodeChanges true if need to ignore GLSL code changes. */ - @FXThread - private void setIgnoreCodeChanges(final boolean ignoreCodeChanges) { + @FxThread + private void setIgnoreCodeChanges(boolean ignoreCodeChanges) { this.ignoreCodeChanges = ignoreCodeChanges; } @@ -274,23 +283,26 @@ private void setIgnoreCodeChanges(final boolean ignoreCodeChanges) { * * @param glslCode the new GLSL code. */ - @FXThread - private void changeGLSLCode(@NotNull final String glslCode) { - if (isIgnoreCodeChanges()) return; + @FxThread + private void changeGLSLCode(@NotNull String glslCode) { + + if (isIgnoreCodeChanges()) { + return; + } - final String editedShader = getEditedShader(); + var editedShader = getEditedShader(); if (editedShader == null) { return; } - final ObjectDictionary glslOriginalContent = getGlslOriginalContent(); - final String originalCode = glslOriginalContent.get(editedShader); + var glslOriginalContent = getGlslOriginalContent(); + var originalCode = glslOriginalContent.get(editedShader); if (!glslCode.equals(originalCode)) { incrementChange(); } - final ObjectDictionary glslChangedContent = getGlslChangedContent(); + var glslChangedContent = getGlslChangedContent(); glslChangedContent.put(editedShader, glslCode); } @@ -300,20 +312,20 @@ private void changeGLSLCode(@NotNull final String glslCode) { * @param shaderPath the shader path. * @return the GLSL code. */ - @FXThread - private @NotNull String getGLSLCode(@NotNull final String shaderPath) { + @FxThread + private @NotNull String getGlslCode(@NotNull String shaderPath) { - final ObjectDictionary glslChangedContent = getGlslChangedContent(); - final String glslCode = glslChangedContent.get(shaderPath); + var glslChangedContent = getGlslChangedContent(); + var glslCode = glslChangedContent.get(shaderPath); if (glslCode != null) { return glslCode; } - final ObjectDictionary glslOriginalContent = getGlslOriginalContent(); - final Path realFile = notNull(getRealFile(shaderPath)); + var glslOriginalContent = getGlslOriginalContent(); + var realFile = notNull(getRealFile(shaderPath)); - final String readGLSLCode = FileUtils.read(realFile); + var readGLSLCode = FileUtils.read(realFile); glslOriginalContent.put(shaderPath, readGLSLCode); @@ -328,20 +340,21 @@ private void changeGLSLCode(@NotNull final String glslCode) { } @Override - @FXThread - protected void doOpenFile(@NotNull final Path file) throws IOException { + @FxThread + protected void doOpenFile(@NotNull Path file) throws IOException { super.doOpenFile(file); - final Path assetFile = notNull(getAssetFile(file)); - final String assetPath = toAssetPath(assetFile); - final ShaderNodeDefinitionKey key = new ShaderNodeDefinitionKey(assetPath); + var assetFile = notNull(getAssetFile(file)); + var assetPath = toAssetPath(assetFile); + + var key = new ShaderNodeDefinitionKey(assetPath); key.setLoadDocumentation(true); - final AssetManager assetManager = EDITOR.getAssetManager(); + var assetManager = EditorUtil.getAssetManager(); definitionList = assetManager.loadAsset(key); - final NodeTree structureTree = getStructureTree(); + var structureTree = getStructureTree(); structureTree.fill(new SndList(definitionList)); structureTree.expandToLevel(1); } @@ -358,31 +371,31 @@ protected void doOpenFile(@NotNull final Path file) throws IOException { @Override @BackgroundThread - protected void doSave(@NotNull final Path toStore) throws IOException { + protected void doSave(@NotNull Path toStore) throws IOException { super.doSave(toStore); - final J3snExporter exporter = J3snExporter.getInstance(); + var exporter = J3snExporter.getInstance(); - try (OutputStream out = Files.newOutputStream(toStore)) { + try (var out = Files.newOutputStream(toStore)) { exporter.export(getDefinitionList(), out); } - final ObjectDictionary glslChangedContent = getGlslChangedContent(); - final ObjectDictionary glslOriginalContent = getGlslOriginalContent(); + var glslChangedContent = getGlslChangedContent(); + var glslOriginalContent = getGlslOriginalContent(); glslChangedContent.forEach((path, content) -> { - final String original = glslOriginalContent.get(path); + var original = glslOriginalContent.get(path); if (StringUtils.equals(content, original)) { return; } - final Path realFile = notNull(getRealFile(path)); + var realFile = notNull(getRealFile(path)); - try (PrintStream out = new PrintStream(Files.newOutputStream(realFile))) { + try (var out = new PrintStream(Files.newOutputStream(realFile))) { out.print(content); - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException(e); } @@ -395,7 +408,7 @@ protected void doSave(@NotNull final Path toStore) throws IOException { * * @return the structure tree. */ - @FXThread + @FxThread private @NotNull NodeTree getStructureTree() { return notNull(structureTree); } @@ -405,26 +418,26 @@ protected void doSave(@NotNull final Path toStore) throws IOException { * * @return the property editor. */ - @FXThread + @FxThread private @NotNull PropertyEditor getPropertyEditor() { return notNull(propertyEditor); } @Override - @FXThread + @FxThread protected boolean needToolbar() { return true; } @Override - @FXThread - protected void createToolbar(@NotNull final HBox container) { + @FxThread + protected void createToolbar(@NotNull HBox container) { super.createToolbar(container); FXUtils.addToPane(createSaveAction(), container); } @Override - @FXThread + @FxThread protected @Nullable Supplier getEditorStateFactory() { return ShaderNodeDefinitionEditorState::new; } @@ -436,37 +449,42 @@ protected void createToolbar(@NotNull final HBox container) { } @Override - @FXThread - public void notifyFXAddedChild(@NotNull final Object parent, @NotNull final Object added, final int index, - final boolean needSelect) { - - final NodeTree structureTree = getStructureTree(); + @FxThread + public void notifyFxAddedChild( + @NotNull Object parent, + @NotNull Object added, + int index, + boolean needSelect + ) { + + var structureTree = getStructureTree(); structureTree.notifyAdded(parent, added, index); if (needSelect) { - structureTree.select(added); + structureTree.selectSingle(added); } } @Override - @FXThread - public void notifyFXRemovedChild(@NotNull final Object parent, @NotNull final Object removed) { + @FxThread + public void notifyFxRemovedChild(@NotNull Object parent, @NotNull Object removed) { getStructureTree().notifyRemoved(parent, removed); } @Override - @FXThread - public void notifyFXChangeProperty(@Nullable final Object parent, @NotNull final Object object, - @NotNull final String propertyName) { - super.notifyFXChangeProperty(parent, object, propertyName); - - final NodeTree structureTree = getStructureTree(); + @FxThread + public void notifyFxChangeProperty( + @Nullable Object parent, + @NotNull Object object, + @NotNull String propertyName + ) { + super.notifyFxChangeProperty(parent, object, propertyName); + + var structureTree = getStructureTree(); structureTree.notifyChanged(parent, object); - final PropertyEditor propertyEditor = getPropertyEditor(); - if (object instanceof EditableProperty) { - propertyEditor.refresh(); + getPropertyEditor().refresh(); } } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesChangeConsumer.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesChangeConsumer.java index 8517081..046091b 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesChangeConsumer.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesChangeConsumer.java @@ -9,8 +9,8 @@ import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.UniformBinding; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -21,6 +21,8 @@ public interface ShaderNodesChangeConsumer extends ChangeConsumer { /** + * Get the edited material definition. + * * @return the edited material definition. */ @FromAnyThread @@ -40,8 +42,8 @@ public interface ShaderNodesChangeConsumer extends ChangeConsumer { * @param shaderNode the shader nodes. * @param mapping the variable mapping. */ - @FXThread - void notifyAddedMapping(@NotNull final ShaderNode shaderNode, @NotNull final VariableMapping mapping); + @FxThread + void notifyAddedMapping(@NotNull ShaderNode shaderNode, @NotNull VariableMapping mapping); /** * Notify about removed the variable mapping. @@ -49,8 +51,8 @@ public interface ShaderNodesChangeConsumer extends ChangeConsumer { * @param shaderNode the shader nodes. * @param mapping the variable mapping. */ - @FXThread - void notifyRemovedMapping(@NotNull final ShaderNode shaderNode, @NotNull final VariableMapping mapping); + @FxThread + void notifyRemovedMapping(@NotNull ShaderNode shaderNode, @NotNull VariableMapping mapping); /** * Notify about replaced the variable mapping. @@ -59,9 +61,12 @@ public interface ShaderNodesChangeConsumer extends ChangeConsumer { * @param oldMapping the old variable mapping. * @param newMapping the new variable mapping. */ - @FXThread - void notifyReplacedMapping(@NotNull final ShaderNode shaderNode, @NotNull final VariableMapping oldMapping, - @NotNull final VariableMapping newMapping); + @FxThread + void notifyReplacedMapping( + @NotNull ShaderNode shaderNode, + @NotNull VariableMapping oldMapping, + @NotNull VariableMapping newMapping + ); /** * Notify about added the material parameter. @@ -69,16 +74,16 @@ void notifyReplacedMapping(@NotNull final ShaderNode shaderNode, @NotNull final * @param matParam the material parameter. * @param location the location. */ - @FXThread - void notifyAddedMatParameter(@NotNull final MatParam matParam, @NotNull Vector2f location); + @FxThread + void notifyAddedMatParameter(@NotNull MatParam matParam, @NotNull Vector2f location); /** * Notify about removed the material parameter. * * @param matParam the material parameter. */ - @FXThread - void notifyRemovedMatParameter(@NotNull final MatParam matParam); + @FxThread + void notifyRemovedMatParameter(@NotNull MatParam matParam); /** * Notify about added the attribute. @@ -86,16 +91,16 @@ void notifyReplacedMapping(@NotNull final ShaderNode shaderNode, @NotNull final * @param variable the variable of the attribute. * @param location the location. */ - @FXThread - void notifyAddedAttribute(@NotNull final ShaderNodeVariable variable, @NotNull Vector2f location); + @FxThread + void notifyAddedAttribute(@NotNull ShaderNodeVariable variable, @NotNull Vector2f location); /** * Notify about removed the attribute. * * @param variable the variable of the attribute. */ - @FXThread - void notifyRemovedAttribute(@NotNull final ShaderNodeVariable variable); + @FxThread + void notifyRemovedAttribute(@NotNull ShaderNodeVariable variable); /** * Notify about added the world parameter. @@ -103,16 +108,16 @@ void notifyReplacedMapping(@NotNull final ShaderNode shaderNode, @NotNull final * @param binding the binding. * @param location the location. */ - @FXThread - void notifyAddedWorldParameter(@NotNull final UniformBinding binding, @NotNull Vector2f location); + @FxThread + void notifyAddedWorldParameter(@NotNull UniformBinding binding, @NotNull Vector2f location); /** * Notify about removed the world parameter. * * @param binding the binding. */ - @FXThread - void notifyRemovedWorldParameter(@NotNull final UniformBinding binding); + @FxThread + void notifyRemovedWorldParameter(@NotNull UniformBinding binding); /** * Notify about added the shader nodes. @@ -120,16 +125,16 @@ void notifyReplacedMapping(@NotNull final ShaderNode shaderNode, @NotNull final * @param shaderNode the shader nodes. * @param location the location. */ - @FXThread - void notifyAddedShaderNode(@NotNull final ShaderNode shaderNode, @NotNull Vector2f location); + @FxThread + void notifyAddedShaderNode(@NotNull ShaderNode shaderNode, @NotNull Vector2f location); /** * Notify about removed the shader nodes. * * @param shaderNode the shader nodes. */ - @FXThread - void notifyRemovedRemovedShaderNode(@NotNull final ShaderNode shaderNode); + @FxThread + void notifyRemovedRemovedShaderNode(@NotNull ShaderNode shaderNode); /** * Notify about changed state of the shader nodes variable. @@ -138,9 +143,12 @@ void notifyReplacedMapping(@NotNull final ShaderNode shaderNode, @NotNull final * @param location the location. * @param width the width. */ - @FXThread - void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull final Vector2f location, - final double width); + @FxThread + void notifyChangeState( + @NotNull ShaderNodeVariable variable, + @NotNull Vector2f location, + double width + ); /** * Notify about changed state of the shader nodes. @@ -149,8 +157,8 @@ void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull fina * @param location the location. * @param width the width. */ - @FXThread - void notifyChangeState(@NotNull final ShaderNode shaderNode, @NotNull final Vector2f location, final double width); + @FxThread + void notifyChangeState(@NotNull ShaderNode shaderNode, @NotNull Vector2f location, double width); /** * Notify about changed state of the global nodes. @@ -159,8 +167,8 @@ void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull fina * @param location the location. * @param width the width. */ - @FXThread - void notifyChangeGlobalNodeState(final boolean input, @NotNull final Vector2f location, final double width); + @FxThread + void notifyChangeGlobalNodeState(boolean input, @NotNull Vector2f location, double width); /** * Get saved location of the shader nodes. @@ -168,8 +176,8 @@ void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull fina * @param shaderNode the shader nodes. * @return the location or null. */ - @FXThread - @Nullable Vector2f getLocation(@NotNull final ShaderNode shaderNode); + @FxThread + @Nullable Vector2f getLocation(@NotNull ShaderNode shaderNode); /** * Get saved location of the shader nodes variable. @@ -177,8 +185,8 @@ void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull fina * @param variable the shader nodes variable. * @return the location or null. */ - @FXThread - @Nullable Vector2f getLocation(@NotNull final ShaderNodeVariable variable); + @FxThread + @Nullable Vector2f getLocation(@NotNull ShaderNodeVariable variable); /** * Get saved location of the global nodes. @@ -186,8 +194,8 @@ void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull fina * @param input true if it's input global nodes. * @return the location or null. */ - @FXThread - @Nullable Vector2f getGlobalNodeLocation(final boolean input); + @FxThread + @Nullable Vector2f getGlobalNodeLocation(boolean input); /** * Get saved width of the shader nodes. @@ -195,8 +203,8 @@ void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull fina * @param shaderNode the shader nodes. * @return the width or 0. */ - @FXThread - double getWidth(@NotNull final ShaderNode shaderNode); + @FxThread + double getWidth(@NotNull ShaderNode shaderNode); /** * Get saved width of the shader nodes variable. @@ -204,8 +212,8 @@ void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull fina * @param variable the shader nodes variable. * @return the width or null. */ - @FXThread - double getWidth(@NotNull final ShaderNodeVariable variable); + @FxThread + double getWidth(@NotNull ShaderNodeVariable variable); /** * Get saved width of the global nodes. @@ -213,22 +221,22 @@ void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull fina * @param input true if it's input global nodes. * @return the width or null. */ - @FXThread - double getGlobalNodeWidth(final boolean input); + @FxThread + double getGlobalNodeWidth(boolean input); /** * Notify about added the technique definition. * * @param techniqueDef the technique definition. */ - @FXThread - void notifyAddedTechnique(@NotNull final TechniqueDef techniqueDef); + @FxThread + void notifyAddedTechnique(@NotNull TechniqueDef techniqueDef); /** * Notify about removed the technique definition. * * @param techniqueDef the technique definition. */ - @FXThread - void notifyRemovedTechnique(@NotNull final TechniqueDef techniqueDef); + @FxThread + void notifyRemovedTechnique(@NotNull TechniqueDef techniqueDef); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesEditor3DState.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesEditor3DPart.java similarity index 54% rename from src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesEditor3DState.java rename to src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesEditor3DPart.java index 179b5fb..d00749b 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesEditor3DState.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesEditor3DPart.java @@ -2,8 +2,9 @@ import com.jme3.material.Material; import com.ss.editor.annotation.FromAnyThread; -import com.ss.editor.annotation.JMEThread; -import com.ss.editor.plugin.api.editor.material.BaseMaterialEditor3DState; +import com.ss.editor.annotation.JmeThread; +import com.ss.editor.plugin.api.editor.material.BaseMaterialEditor3DPart; +import com.ss.editor.util.EditorUtil; import org.jetbrains.annotations.NotNull; /** @@ -11,9 +12,9 @@ * * @author JavaSaBr */ -public class ShaderNodesEditor3DState extends BaseMaterialEditor3DState { +public class ShaderNodesEditor3DPart extends BaseMaterialEditor3DPart { - public ShaderNodesEditor3DState(@NotNull final ShaderNodesFileEditor fileEditor) { + public ShaderNodesEditor3DPart(@NotNull ShaderNodesFileEditor fileEditor) { super(fileEditor); } @@ -24,8 +25,8 @@ public ShaderNodesEditor3DState(@NotNull final ShaderNodesFileEditor fileEditor) * @param name the name. */ @FromAnyThread - public void selectTechnique(@NotNull final Material material, @NotNull final String name) { - EXECUTOR_MANAGER.addJMETask(() -> selectTechniqueImpl(material, name)); + public void selectTechnique(@NotNull Material material, @NotNull String name) { + EXECUTOR_MANAGER.addJmeTask(() -> selectTechniqueImpl(material, name)); } /** @@ -34,14 +35,14 @@ public void selectTechnique(@NotNull final Material material, @NotNull final Str * @param material the material. * @param name the name. */ - @JMEThread - private void selectTechniqueImpl(@NotNull final Material material, @NotNull final String name) { - material.selectTechnique(name, EDITOR.getRenderManager()); + @JmeThread + private void selectTechniqueImpl(@NotNull Material material, @NotNull String name) { + material.selectTechnique(name, EditorUtil.getRenderManager()); updateMaterialImpl(material); } @Override - protected void handleMaterialException(@NotNull final RuntimeException exception) { + protected void handleMaterialException(@NotNull RuntimeException exception) { LOGGER.warning(this, exception); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesFileEditor.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesFileEditor.java index 4b59954..58f73d0 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesFileEditor.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/ShaderNodesFileEditor.java @@ -14,6 +14,7 @@ import com.jme3.material.plugin.export.materialdef.J3mdExporter; import com.jme3.material.plugins.J3MLoader; import com.jme3.math.Vector2f; +import com.jme3.renderer.RenderManager; import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.UniformBinding; @@ -21,11 +22,11 @@ import com.ss.editor.FileExtensions; import com.ss.editor.Messages; import com.ss.editor.annotation.BackgroundThread; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.manager.ResourceManager; import com.ss.editor.plugin.api.dialog.GenericFactoryDialog; -import com.ss.editor.plugin.api.editor.material.BaseMaterialEditor3DState.ModelType; +import com.ss.editor.plugin.api.editor.material.BaseMaterialEditor3DPart; import com.ss.editor.plugin.api.editor.material.BaseMaterialFileEditor; import com.ss.editor.plugin.api.property.PropertyDefinition; import com.ss.editor.shader.nodes.PluginMessages; @@ -52,10 +53,10 @@ import com.ss.editor.ui.component.editor.state.EditorState; import com.ss.editor.ui.component.tab.EditorToolComponent; import com.ss.editor.ui.control.property.PropertyEditor; -import com.ss.editor.ui.css.CSSClasses; +import com.ss.editor.ui.css.CssClasses; import com.ss.editor.ui.dialog.asset.virtual.StringVirtualAssetEditorDialog; import com.ss.editor.ui.util.DynamicIconSupport; -import com.ss.editor.ui.util.UIUtils; +import com.ss.editor.ui.util.UiUtils; import com.ss.editor.util.EditorUtil; import com.ss.editor.util.MaterialUtils; import com.ss.rlib.ui.util.FXUtils; @@ -88,7 +89,7 @@ * @author JavaSaBr */ public class ShaderNodesFileEditor extends - BaseMaterialFileEditor implements + BaseMaterialFileEditor implements ShaderNodesChangeConsumer { @NotNull @@ -183,49 +184,48 @@ public class ShaderNodesFileEditor extends private boolean ignoreLightModeChanges; @Override - @FXThread - protected @NotNull ShaderNodesEditor3DState create3DEditorState() { - return new ShaderNodesEditor3DState(this); + @FxThread + protected @NotNull ShaderNodesEditor3DPart create3DEditorPart() { + return new ShaderNodesEditor3DPart(this); } @Override - @FXThread + @FxThread protected @Nullable Supplier getEditorStateFactory() { return ShaderNodesEditorState::new; } @Override - @FXThread - protected void doOpenFile(@NotNull final Path file) throws IOException { + @FxThread + protected void doOpenFile(@NotNull Path file) throws IOException { super.doOpenFile(file); - final AssetManager assetManager = EDITOR.getAssetManager(); - final BinaryImporter importer = BinaryImporter.getInstance(); + var assetManager = EditorUtil.getAssetManager(); + var importer = BinaryImporter.getInstance(); importer.setAssetManager(assetManager); - try (final InputStream in = Files.newInputStream(file)) { + try (var in = Files.newInputStream(file)) { setProject((ShaderNodesProject) importer.load(in)); } catch (final IOException e) { throw new RuntimeException(e); } - final ShaderNodesProject project = getProject(); - final String materialDefContent = notNull(project.getMaterialDefContent()); + var project = getProject(); + var materialDefContent = notNull(project.getMaterialDefContent()); - final ByteArrayInputStream materialDefStream = - new ByteArrayInputStream(materialDefContent.getBytes("UTF-8")); + var materialDefStream = new ByteArrayInputStream(materialDefContent.getBytes("UTF-8")); - final AssetKey tempKey = new AssetKey<>("tempMatDef"); - final StreamAssetInfo assetInfo = new StreamAssetInfo(assetManager, tempKey, materialDefStream); + var tempKey = new AssetKey("tempMatDef"); + var assetInfo = new StreamAssetInfo(assetManager, tempKey, materialDefStream); - final J3MLoader loader = new J3MLoader(); - final MaterialDef materialDef = (MaterialDef) loader.load(assetInfo); + var loader = new J3MLoader(); + var materialDef = (MaterialDef) loader.load(assetInfo); materialDef.getTechniqueDefsNames().forEach(techniqueDefName -> { materialDef.getTechniqueDefs(techniqueDefName).forEach(techniqueDef -> { - final ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); - final List fragmentGlobals = info.getFragmentGlobals(); + var info = techniqueDef.getShaderGenerationInfo(); + var fragmentGlobals = info.getFragmentGlobals(); if (fragmentGlobals.isEmpty()) { fragmentGlobals.add(new ShaderNodeVariable("vec4", GlobalShaderNodeElement.NAMESPACE, "color", null)); @@ -238,27 +238,27 @@ protected void doOpenFile(@NotNull final Path file) throws IOException { }); setMaterialDef(materialDef); - getEditor3DState().updateMaterial(EDITOR.getDefaultMaterial()); - final ShaderNodesEditor3DState editor3DState = getEditor3DState(); - editor3DState.changeMode(ModelType.BOX); + var editor3DPart = getEditor3DPart(); + editor3DPart.updateMaterial(EditorUtil.getDefaultMaterial()); + editor3DPart.changeMode(BaseMaterialEditor3DPart.ModelType.BOX); } @Override - @FXThread + @FxThread protected void loadState() { super.loadState(); - EXECUTOR_MANAGER.addFXTask(this::buildMaterial); + EXECUTOR_MANAGER.addFxTask(this::buildMaterial); - final ShaderNodesEditorState editorState = getEditorState(); + var editorState = getEditorState(); if (editorState == null) { return; } editorState.cleanUp(getMaterialDef()); - final List defStates = editorState.getTechniqueDefStates(); + var defStates = editorState.getTechniqueDefStates(); if (defStates.isEmpty()) { defStates.addAll(getProject().getTechniqueDefStates()); @@ -267,24 +267,24 @@ protected void loadState() { @Override @BackgroundThread - protected void doSave(@NotNull final Path toStore) throws IOException { + protected void doSave(@NotNull Path toStore) throws IOException { super.doSave(toStore); - final BinaryExporter exporter = BinaryExporter.getInstance(); + var exporter = BinaryExporter.getInstance(); - final MaterialDef materialDef = getMaterialDef(); - final Material currentMaterial = getCurrentMaterial(); - final ByteArrayOutputStream bout = new ByteArrayOutputStream(); + var materialDef = getMaterialDef(); + var currentMaterial = getCurrentMaterial(); + var bout = new ByteArrayOutputStream(); - final ShaderNodesEditorState editorState = notNull(getEditorState()); - final List defStates = editorState.getTechniqueDefStates(); + var editorState = notNull(getEditorState()); + var defStates = editorState.getTechniqueDefStates(); - final J3mdExporter materialExporter = new J3mdExporter(); + var materialExporter = new J3mdExporter(); materialExporter.save(materialDef, bout); - final String materialDefContent = new String(bout.toByteArray(), "UTF-8"); + var materialDefContent = new String(bout.toByteArray(), "UTF-8"); - final ShaderNodesProject project = getProject(); + var project = getProject(); project.setMaterialDefContent(materialDefContent); project.updateTechniqueDefStates(defStates); @@ -292,13 +292,13 @@ protected void doSave(@NotNull final Path toStore) throws IOException { project.setMatParams(currentMaterial.getParams()); } - try (final OutputStream out = Files.newOutputStream(toStore)) { + try (var out = Files.newOutputStream(toStore)) { exporter.save(project, out); } } @Override - @FXThread + @FxThread protected void createEditorAreaPane() { super.createEditorAreaPane(); @@ -316,21 +316,24 @@ protected void createEditorAreaPane() { }); FXUtils.addToPane(splitPanel, editorAreaPane); - FXUtils.addClassTo(splitPanel, CSSClasses.FILE_EDITOR_TOOL_SPLIT_PANE); + FXUtils.addClassTo(splitPanel, CssClasses.FILE_EDITOR_TOOL_SPLIT_PANE); } @Override - @FXThread + @FxThread protected void createToolComponents(@NotNull final EditorToolComponent container, @NotNull final StackPane root) { super.createToolComponents(container, root); - fragmentPreview = new FragmentShaderCodePreviewComponent(EDITOR.getAssetManager(), EDITOR.getRenderManager()); + final AssetManager assetManager = EditorUtil.getAssetManager(); + final RenderManager renderManager = EditorUtil.getRenderManager(); + + fragmentPreview = new FragmentShaderCodePreviewComponent(assetManager, renderManager); fragmentPreview.prefHeightProperty().bind(root.heightProperty()); - vertexPreview = new VertexShaderCodePreviewComponent(EDITOR.getAssetManager(), EDITOR.getRenderManager()); + vertexPreview = new VertexShaderCodePreviewComponent(assetManager, renderManager); vertexPreview.prefHeightProperty().bind(root.heightProperty()); - matDefPreview = new MaterialDefCodePreviewComponent(EDITOR.getAssetManager(), EDITOR.getRenderManager()); + matDefPreview = new MaterialDefCodePreviewComponent(assetManager, renderManager); matDefPreview.prefHeightProperty().bind(root.heightProperty()); container.addComponent(vertexPreview, PluginMessages.SNS_EDITOR_TOOL_VERTEX); @@ -359,7 +362,7 @@ protected void createToolComponents(@NotNull final EditorToolComponent container * * @return the fragment preview component. */ - @FXThread + @FxThread private @NotNull ShaderCodePreviewComponent getFragmentPreview() { return notNull(fragmentPreview); } @@ -369,7 +372,7 @@ protected void createToolComponents(@NotNull final EditorToolComponent container * * @return the vertex preview component. */ - @FXThread + @FxThread private @NotNull ShaderCodePreviewComponent getVertexPreview() { return notNull(vertexPreview); } @@ -379,13 +382,13 @@ protected void createToolComponents(@NotNull final EditorToolComponent container * * @return the material definition preview component. */ - @FXThread + @FxThread private @NotNull MaterialDefCodePreviewComponent getMatDefPreview() { return notNull(matDefPreview); } @Override - @FXThread + @FxThread protected void createActions(@NotNull final HBox container) { super.createActions(container); @@ -401,12 +404,12 @@ protected void createActions(@NotNull final HBox container) { FXUtils.addToPane(exportAction, importAction, container); - FXUtils.addClassesTo(exportAction, importAction, CSSClasses.FLAT_BUTTON, CSSClasses.FILE_EDITOR_TOOLBAR_BUTTON); + FXUtils.addClassesTo(exportAction, importAction, CssClasses.FLAT_BUTTON, CssClasses.FILE_EDITOR_TOOLBAR_BUTTON); DynamicIconSupport.addSupport(exportAction, importAction); } @Override - @FXThread + @FxThread protected void createToolbar(@NotNull final HBox container) { super.createToolbar(container); @@ -433,15 +436,15 @@ protected void createToolbar(@NotNull final HBox container) { FXUtils.addToPane(lightModeLabel, lightModeComboBox, container); FXUtils.addToPane(techniqueLabel, techniqueComboBox, addTechnique, container); - FXUtils.addClassTo(techniqueLabel, lightModeLabel, CSSClasses.FILE_EDITOR_TOOLBAR_LABEL); - FXUtils.addClassTo(techniqueComboBox, lightModeComboBox, CSSClasses.FILE_EDITOR_TOOLBAR_FIELD); - FXUtils.addClassesTo(addTechnique, CSSClasses.FLAT_BUTTON, CSSClasses.FILE_EDITOR_TOOLBAR_BUTTON); + FXUtils.addClassTo(techniqueLabel, lightModeLabel, CssClasses.FILE_EDITOR_TOOLBAR_LABEL); + FXUtils.addClassTo(techniqueComboBox, lightModeComboBox, CssClasses.FILE_EDITOR_TOOLBAR_FIELD); + FXUtils.addClassesTo(addTechnique, CssClasses.FLAT_BUTTON, CssClasses.FILE_EDITOR_TOOLBAR_BUTTON); } /** * Add new technique. */ - @FXThread + @FxThread private void addTechnique() { final Array definitions = ArrayFactory.newArray(PropertyDefinition.class); @@ -452,7 +455,7 @@ private void addTechnique() { dialog.show(); } - @FXThread + @FxThread private boolean validateTechnique(@NotNull final VarTable vars) { final String name = vars.getString(PROP_TECHNIQUE_NAME); final MaterialDef materialDef = getMaterialDef(); @@ -460,7 +463,7 @@ private boolean validateTechnique(@NotNull final VarTable vars) { return techniqueDefs == null && !name.isEmpty(); } - @FXThread + @FxThread private void addTechnique(@NotNull final VarTable vars) { final ShaderNodeVariable vertexGlobal = new ShaderNodeVariable("vec4", "Global", "position", null, ""); @@ -514,19 +517,19 @@ private void addTechnique(@NotNull final VarTable vars) { /** * Export the result material definition as a file. */ - @FXThread + @FxThread private void export() { - UIUtils.openSaveAsDialog(this::export, FileExtensions.JME_MATERIAL_DEFINITION, ACTION_TESTER); + UiUtils.openSaveAsDialog(this::export, FileExtensions.JME_MATERIAL_DEFINITION, ACTION_TESTER); } /** * Import other material definition file to this project. */ - @FXThread + @FxThread private void importMatDef() { final ResourceManager resourceManager = ResourceManager.getInstance(); final Array resources = resourceManager.getAvailableResources(FileExtensions.JME_MATERIAL_DEFINITION); - UIUtils.openResourceAssetDialog(this::importMatDef, this::validateMatDef, resources); + UiUtils.openResourceAssetDialog(this::importMatDef, this::validateMatDef, resources); } /** @@ -535,7 +538,7 @@ private void importMatDef() { * @param assetPath the asset path. * @return the message or null if it's ok. */ - @FXThread + @FxThread private String validateMatDef(@NotNull final String assetPath) { final String message = StringVirtualAssetEditorDialog.DEFAULT_VALIDATOR.apply(assetPath); @@ -543,7 +546,7 @@ private String validateMatDef(@NotNull final String assetPath) { return message; } - final AssetManager assetManager = EDITOR.getAssetManager(); + final AssetManager assetManager = EditorUtil.getAssetManager(); final MaterialDef materialDef = (MaterialDef) assetManager.loadAsset(assetPath); final Collection techniqueDefsNames = materialDef.getTechniqueDefsNames(); @@ -564,7 +567,7 @@ private String validateMatDef(@NotNull final String assetPath) { * * @param path the file. */ - @FXThread + @FxThread private void export(@NotNull final Path path) { final J3mdExporter exporter = new J3mdExporter(); @@ -584,10 +587,10 @@ private void export(@NotNull final Path path) { * * @param resource the resource. */ - @FXThread + @FxThread private void importMatDef(@NotNull final String resource) { - final AssetManager assetManager = EDITOR.getAssetManager(); + final AssetManager assetManager = EditorUtil.getAssetManager(); final MaterialDef matDef = (MaterialDef) assetManager.loadAsset(resource); setMaterialDef(matDef); @@ -599,7 +602,7 @@ private void importMatDef(@NotNull final String resource) { * * @return the light modes combo box. */ - @FXThread + @FxThread private @NotNull ComboBox getLightModeComboBox() { return notNull(lightModeComboBox); } @@ -607,7 +610,7 @@ private void importMatDef(@NotNull final String resource) { /** * @return true if need to skip changes of light modes. */ - @FXThread + @FxThread private boolean isIgnoreLightModeChanges() { return ignoreLightModeChanges; } @@ -615,7 +618,7 @@ private boolean isIgnoreLightModeChanges() { /** * @param ignoreLightModeChanges true if need to skip changes of light modes. */ - @FXThread + @FxThread private void setIgnoreLightModeChanges(final boolean ignoreLightModeChanges) { this.ignoreLightModeChanges = ignoreLightModeChanges; } @@ -623,7 +626,7 @@ private void setIgnoreLightModeChanges(final boolean ignoreLightModeChanges) { /** * Handle changing the technique. */ - @FXThread + @FxThread private void changeTechnique(@Nullable final String newValue) { final Material currentMaterial = getCurrentMaterial(); @@ -657,7 +660,7 @@ private void changeTechnique(@Nullable final String newValue) { getFragmentPreview().load(techniqueDef); getVertexPreview().load(techniqueDef); - getEditor3DState().selectTechnique(currentMaterial, newValue); + getEditor3DPart().selectTechnique(currentMaterial, newValue); setIgnoreLightModeChanges(true); try { @@ -670,9 +673,12 @@ private void changeTechnique(@Nullable final String newValue) { /** * Handle changing the light mode of this current technique. */ - @FXThread + @FxThread private void changeLightMode(@Nullable final LightMode prevLightMode, @Nullable final LightMode newLightMode) { - if (isIgnoreLightModeChanges() || prevLightMode == null || newLightMode == null) return; + + if (isIgnoreLightModeChanges() || prevLightMode == null || newLightMode == null) { + return; + } final ComboBox techniqueComboBox = getTechniqueComboBox(); final String name = techniqueComboBox.getSelectionModel().getSelectedItem(); @@ -683,7 +689,7 @@ private void changeLightMode(@Nullable final LightMode prevLightMode, @Nullable /** * @return the project file. */ - @FXThread + @FxThread private @NotNull ShaderNodesProject getProject() { return notNull(project); } @@ -691,7 +697,7 @@ private void changeLightMode(@Nullable final LightMode prevLightMode, @Nullable /** * @param project the project file. */ - @FXThread + @FxThread private void setProject(@NotNull final ShaderNodesProject project) { this.project = project; } @@ -699,7 +705,7 @@ private void setProject(@NotNull final ShaderNodesProject project) { /** * @return the current built material. */ - @FXThread + @FxThread private @Nullable Material getCurrentMaterial() { return currentMaterial; } @@ -707,7 +713,7 @@ private void setProject(@NotNull final ShaderNodesProject project) { /** * @param currentMaterial the current built material. */ - @FXThread + @FxThread private void setCurrentMaterial(@Nullable final Material currentMaterial) { this.currentMaterial = currentMaterial; } @@ -717,7 +723,7 @@ private void setCurrentMaterial(@Nullable final Material currentMaterial) { * * @param materialDef the current edited material definition. */ - @FXThread + @FxThread private void setMaterialDef(@NotNull final MaterialDef materialDef) { this.materialDef = materialDef; } @@ -737,7 +743,7 @@ private void setMaterialDef(@NotNull final MaterialDef materialDef) { /** * Build material for shader nodes. */ - @FXThread + @FxThread private void buildMaterial() { final Material currentMaterial = getCurrentMaterial(); @@ -773,7 +779,7 @@ private void buildMaterial() { setCurrentMaterial(newMaterial); getShaderNodesContainer().notifyChangedMaterial(); - getEditor3DState().updateMaterial(newMaterial); + getEditor3DPart().updateMaterial(newMaterial); getMatDefPreview().load(newMaterial.getMaterialDef()); if (items.contains(currentTechnique)) { @@ -797,7 +803,7 @@ private void buildMaterial() { final Collection materialParams = materialDef.getMaterialParams(); final Collection techniqueDefsNames = materialDef.getTechniqueDefsNames(); - final MaterialDef newMaterialDef = new MaterialDef(EDITOR.getAssetManager(), materialDef.getAssetName()); + final MaterialDef newMaterialDef = new MaterialDef(EditorUtil.getAssetManager(), materialDef.getAssetName()); materialParams.stream() .filter(MatParamTexture.class::isInstance) @@ -827,96 +833,100 @@ private void buildMaterial() { } @Override - @FXThread + @FxThread public void notifyAddedMapping(@NotNull final ShaderNode shaderNode, @NotNull final VariableMapping mapping) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.refreshLines(); + handleChangeMapping(shaderNode); } @Override - @FXThread + @FxThread public void notifyRemovedMapping(@NotNull final ShaderNode shaderNode, @NotNull final VariableMapping mapping) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); + handleChangeMapping(shaderNode); + } + + /** + * Handle of changing mapping of the shader node. + * + * @param shaderNode the shader node. + */ + @FxThread + protected void handleChangeMapping(@NotNull final ShaderNode shaderNode) { + var container = getShaderNodesContainer(); + container.refreshShaderNode(shaderNode); container.refreshLines(); } @Override - @FXThread - public void notifyReplacedMapping(@NotNull final ShaderNode shaderNode, @NotNull final VariableMapping oldMapping, - @NotNull final VariableMapping newMapping) { + @FxThread + public void notifyReplacedMapping( + @NotNull final ShaderNode shaderNode, + @NotNull final VariableMapping oldMapping, + @NotNull final VariableMapping newMapping + ) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.refreshLines(); + handleChangeMapping(shaderNode); } - @FXThread + @FxThread @Override public void notifyAddedMatParameter(@NotNull final MatParam matParam, @NotNull final Vector2f location) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.addMatParam(matParam, location); + getShaderNodesContainer().addMatParam(matParam, location); } - @FXThread + @FxThread @Override public void notifyRemovedMatParameter(@NotNull final MatParam matParam) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.removeMatParam(matParam); + getShaderNodesContainer().removeMatParam(matParam); } - @FXThread + @FxThread @Override public void notifyAddedAttribute(@NotNull final ShaderNodeVariable variable, @NotNull final Vector2f location) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.addNodeElement(variable, location); + getShaderNodesContainer().addNodeElement(variable, location); } - @FXThread + @FxThread @Override public void notifyRemovedAttribute(@NotNull final ShaderNodeVariable variable) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.removeNodeElement(variable); + getShaderNodesContainer().removeNodeElement(variable); } @Override - @FXThread + @FxThread public void notifyAddedWorldParameter(@NotNull final UniformBinding binding, @NotNull final Vector2f location) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.addWorldParam(binding, location); + getShaderNodesContainer().addWorldParam(binding, location); } @Override - @FXThread + @FxThread public void notifyRemovedWorldParameter(@NotNull final UniformBinding binding) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.removeWorldParam(binding); + getShaderNodesContainer().removeWorldParam(binding); } @Override - @FXThread + @FxThread public void notifyAddedShaderNode(@NotNull final ShaderNode shaderNode, @NotNull final Vector2f location) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.addShaderNode(shaderNode, location); + getShaderNodesContainer().addShaderNode(shaderNode, location); } @Override - @FXThread + @FxThread public void notifyRemovedRemovedShaderNode(@NotNull final ShaderNode shaderNode) { buildMaterial(); - final ShaderNodesContainer container = getShaderNodesContainer(); - container.removeShaderNode(shaderNode); + getShaderNodesContainer().removeShaderNode(shaderNode); } @Override - @FXThread + @FxThread public void notifyChangeState(@NotNull final ShaderNode shaderNode, @NotNull final Vector2f location, final double width) { @@ -926,7 +936,7 @@ public void notifyChangeState(@NotNull final ShaderNode shaderNode, @NotNull fin } @Override - @FXThread + @FxThread public void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNull final Vector2f location, final double width) { @@ -936,7 +946,7 @@ public void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNu } @Override - @FXThread + @FxThread public @Nullable Vector2f getLocation(@NotNull final ShaderNode shaderNode) { final TechniqueDefState state = getTechniqueDefState(); if (state == null) return null; @@ -945,7 +955,7 @@ public void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNu } @Override - @FXThread + @FxThread public @Nullable Vector2f getLocation(@NotNull final ShaderNodeVariable variable) { final TechniqueDefState state = getTechniqueDefState(); if (state == null) return null; @@ -954,7 +964,7 @@ public void notifyChangeState(@NotNull final ShaderNodeVariable variable, @NotNu } @Override - @FXThread + @FxThread public double getWidth(@NotNull final ShaderNode shaderNode) { final TechniqueDefState state = getTechniqueDefState(); if (state == null) return 0D; @@ -963,7 +973,7 @@ public double getWidth(@NotNull final ShaderNode shaderNode) { } @Override - @FXThread + @FxThread public double getWidth(@NotNull final ShaderNodeVariable variable) { final TechniqueDefState state = getTechniqueDefState(); if (state == null) return 0D; @@ -972,7 +982,7 @@ public double getWidth(@NotNull final ShaderNodeVariable variable) { } @Override - @FXThread + @FxThread public @Nullable Vector2f getGlobalNodeLocation(final boolean input) { final TechniqueDefState state = getTechniqueDefState(); if (state == null) return null; @@ -980,7 +990,7 @@ public double getWidth(@NotNull final ShaderNodeVariable variable) { } @Override - @FXThread + @FxThread public double getGlobalNodeWidth(final boolean input) { final TechniqueDefState state = getTechniqueDefState(); if (state == null) return 0D; @@ -988,19 +998,19 @@ public double getGlobalNodeWidth(final boolean input) { } @Override - @FXThread + @FxThread public void notifyAddedTechnique(@NotNull final TechniqueDef techniqueDef) { buildMaterial(); } @Override - @FXThread + @FxThread public void notifyRemovedTechnique(@NotNull final TechniqueDef techniqueDef) { buildMaterial(); } @Override - @FXThread + @FxThread public void notifyChangeGlobalNodeState(final boolean input, @NotNull final Vector2f location, final double width) { final TechniqueDefState state = getTechniqueDefState(); @@ -1020,7 +1030,7 @@ public void notifyChangeGlobalNodeState(final boolean input, @NotNull final Vect * * @return the current technique definition state. */ - @FXThread + @FxThread private @Nullable TechniqueDefState getTechniqueDefState() { final ShaderNodesEditorState editorState = getEditorState(); @@ -1035,9 +1045,9 @@ public void notifyChangeGlobalNodeState(final boolean input, @NotNull final Vect } @Override - @FXThread - public void notifyFXChangeProperty(@NotNull final Object object, @NotNull final String propertyName) { - super.notifyFXChangeProperty(object, propertyName); + @FxThread + public void notifyFxChangeProperty(@NotNull final Object object, @NotNull final String propertyName) { + super.notifyFxChangeProperty(object, propertyName); if (object instanceof MatParam) { final PropertyEditor propertyEditor = getPropertyEditor(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodeState.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodeState.java index e6118b4..58150ed 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodeState.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodeState.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.editor.state; import com.jme3.math.Vector2f; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.ui.component.editor.state.impl.AbstractEditorState; import org.jetbrains.annotations.NotNull; @@ -39,7 +39,7 @@ public ShaderNodeState() { this.location = Vector2f.ZERO; } - public ShaderNodeState(@NotNull final String name, @NotNull final Vector2f location, final int width) { + public ShaderNodeState(@NotNull String name, @NotNull Vector2f location, int width) { this.name = name; this.location = location; this.width = width; @@ -50,7 +50,7 @@ public ShaderNodeState(@NotNull final String name, @NotNull final Vector2f locat * * @return the name of a shader nodes. */ - @FXThread + @FxThread public @NotNull String getName() { return name; } @@ -60,8 +60,8 @@ public ShaderNodeState(@NotNull final String name, @NotNull final Vector2f locat * * @param name the name of a shader nodes. */ - @FXThread - public void setName(@NotNull final String name) { + @FxThread + public void setName(@NotNull String name) { this.name = name; } @@ -70,7 +70,7 @@ public void setName(@NotNull final String name) { * * @return the location of a shader nodes. */ - @FXThread + @FxThread public @NotNull Vector2f getLocation() { return location; } @@ -80,8 +80,8 @@ public void setName(@NotNull final String name) { * * @param location the location of a shader nodes. */ - @FXThread - public void setLocation(@NotNull final Vector2f location) { + @FxThread + public void setLocation(@NotNull Vector2f location) { this.location = location; } @@ -90,7 +90,7 @@ public void setLocation(@NotNull final Vector2f location) { * * @return the width of a shader nodes. */ - @FXThread + @FxThread public int getWidth() { return width; } @@ -100,8 +100,8 @@ public int getWidth() { * * @param width the width of a shader nodes. */ - @FXThread - public void setWidth(final int width) { + @FxThread + public void setWidth(int width) { this.width = width; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodeVariableState.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodeVariableState.java index 2619bec..9964c51 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodeVariableState.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodeVariableState.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.editor.state; import com.jme3.math.Vector2f; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.ui.component.editor.state.impl.AbstractEditorState; import org.jetbrains.annotations.NotNull; @@ -46,8 +46,12 @@ public ShaderNodeVariableState() { this.location = Vector2f.ZERO; } - public ShaderNodeVariableState(@NotNull final String name, @NotNull final String nameSpace, - @NotNull final Vector2f location, final int width) { + public ShaderNodeVariableState( + @NotNull String name, + @NotNull String nameSpace, + @NotNull Vector2f location, + int width + ) { this.name = name; this.nameSpace = nameSpace; this.location = location; @@ -60,7 +64,7 @@ public ShaderNodeVariableState(@NotNull final String name, @NotNull final String * * @return the name of a variable. */ - @FXThread + @FxThread public @NotNull String getName() { return name; } @@ -70,8 +74,8 @@ public ShaderNodeVariableState(@NotNull final String name, @NotNull final String * * @param name the name of a variable. */ - @FXThread - public void setName(@NotNull final String name) { + @FxThread + public void setName(@NotNull String name) { this.name = name; } @@ -80,7 +84,7 @@ public void setName(@NotNull final String name) { * * @return the namespace of a variable. */ - @FXThread + @FxThread public @NotNull String getNameSpace() { return nameSpace; } @@ -90,8 +94,8 @@ public void setName(@NotNull final String name) { * * @param nameSpace the namespace of a variable. */ - @FXThread - public void setNameSpace(@NotNull final String nameSpace) { + @FxThread + public void setNameSpace(@NotNull String nameSpace) { this.nameSpace = nameSpace; } @@ -100,7 +104,7 @@ public void setNameSpace(@NotNull final String nameSpace) { * * @return the location of a variable. */ - @FXThread + @FxThread public @NotNull Vector2f getLocation() { return location; } @@ -110,8 +114,8 @@ public void setNameSpace(@NotNull final String nameSpace) { * * @param location the location of a variable. */ - @FXThread - public void setLocation(@NotNull final Vector2f location) { + @FxThread + public void setLocation(@NotNull Vector2f location) { this.location = location; } @@ -120,7 +124,7 @@ public void setLocation(@NotNull final Vector2f location) { * * @return the width of a variable. */ - @FXThread + @FxThread public int getWidth() { return width; } @@ -130,8 +134,8 @@ public int getWidth() { * * @param width the width of a variable. */ - @FXThread - public void setWidth(final int width) { + @FxThread + public void setWidth(int width) { this.width = width; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodesEditorState.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodesEditorState.java index bdd69a1..3e4debc 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodesEditorState.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/ShaderNodesEditorState.java @@ -3,7 +3,7 @@ import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.material.MaterialDef; import com.jme3.material.TechniqueDef; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesFileEditor; import com.ss.editor.ui.component.editor.state.impl.EditorMaterialEditorState; import com.ss.rlib.logging.Logger; @@ -42,14 +42,14 @@ public ShaderNodesEditorState() { * * @return the states of technique definitions. */ - @FXThread + @FxThread public @NotNull List getTechniqueDefStates() { return techniqueDefStates; } @Override - @FXThread - public void setChangeHandler(@NotNull final Runnable changeHandler) { + @FxThread + public void setChangeHandler(@NotNull Runnable changeHandler) { super.setChangeHandler(changeHandler); techniqueDefStates.forEach(state -> state.setChangeHandler(changeHandler)); } @@ -60,10 +60,10 @@ public void setChangeHandler(@NotNull final Runnable changeHandler) { * @param techniqueDefName the name of a technique definition. * @return the state. */ - @FXThread - public @NotNull TechniqueDefState getState(@NotNull final String techniqueDefName) { + @FxThread + public @NotNull TechniqueDefState getState(@NotNull String techniqueDefName) { - final Optional result = techniqueDefStates.stream() + var result = techniqueDefStates.stream() .filter(state -> state.getName().equals(techniqueDefName)) .findAny(); @@ -71,7 +71,7 @@ public void setChangeHandler(@NotNull final Runnable changeHandler) { return result.get(); } - final TechniqueDefState newState = new TechniqueDefState(techniqueDefName); + var newState = new TechniqueDefState(techniqueDefName); newState.setChangeHandler(notNull(getChangeHandler())); techniqueDefStates.add(newState); @@ -85,15 +85,15 @@ public void setChangeHandler(@NotNull final Runnable changeHandler) { * * @param materialDef the material definition. */ - @FXThread - public void cleanUp(@NotNull final MaterialDef materialDef) { + @FxThread + public void cleanUp(@NotNull MaterialDef materialDef) { LOGGER.debug(this, editorState -> "The state before cleanup: " + editorState); - final Collection defsNames = materialDef.getTechniqueDefsNames(); + var defsNames = materialDef.getTechniqueDefsNames(); - for (Iterator iterator = techniqueDefStates.iterator(); iterator.hasNext(); ) { + for (var iterator = techniqueDefStates.iterator(); iterator.hasNext(); ) { - final TechniqueDefState state = iterator.next(); + var state = iterator.next(); if (!defsNames.contains(state.getName())) { iterator.remove(); @@ -101,8 +101,8 @@ public void cleanUp(@NotNull final MaterialDef materialDef) { continue; } - final List techniqueDefs = materialDef.getTechniqueDefs(state.getName()); - final TechniqueDef techniqueDef = techniqueDefs.get(0); + var techniqueDefs = materialDef.getTechniqueDefs(state.getName()); + var techniqueDef = techniqueDefs.get(0); state.cleanUp(materialDef, techniqueDef); } @@ -113,9 +113,9 @@ public void cleanUp(@NotNull final MaterialDef materialDef) { @Override public String toString() { - final StringBuilder builder = new StringBuilder("ShaderNodesEditorState:\n"); + var builder = new StringBuilder("ShaderNodesEditorState:\n"); - for (final TechniqueDefState defState : techniqueDefStates) { + for (var defState : techniqueDefStates) { builder.append("\t").append(defState).append('\n'); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/TechniqueDefState.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/TechniqueDefState.java index 23e881e..a2d9198 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/TechniqueDefState.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/editor/state/TechniqueDefState.java @@ -8,7 +8,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.UniformBinding; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.AttributeShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.MaterialShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.WorldShaderNodeElement; @@ -78,7 +78,7 @@ public class TechniqueDefState extends AbstractEditorState { */ private int inputNodeWidth; - public TechniqueDefState(@NotNull final String name) { + public TechniqueDefState(@NotNull String name) { this.name = name; this.shaderNodeStates = new ArrayList<>(); this.shaderVariableStates = new ArrayList<>(); @@ -92,16 +92,16 @@ public TechniqueDefState(@NotNull final String name) { * @param materialDef the material definition. * @param techniqueDef the technique definition. */ - @FXThread - public void cleanUp(@NotNull final MaterialDef materialDef, @NotNull final TechniqueDef techniqueDef) { + @FxThread + public void cleanUp(@NotNull MaterialDef materialDef, @NotNull TechniqueDef techniqueDef) { - for (final Iterator iterator = shaderVariableStates.iterator(); iterator.hasNext(); ) { + for (var iterator = shaderVariableStates.iterator(); iterator.hasNext(); ) { - final ShaderNodeVariableState state = iterator.next(); + var state = iterator.next(); if (MaterialShaderNodeElement.NAMESPACE.equals(state.getNameSpace())) { - final MatParam parameter = findMatParameterByName(materialDef, state.getName()); + var parameter = findMatParameterByName(materialDef, state.getName()); if (parameter == null) { iterator.remove(); @@ -110,7 +110,7 @@ public void cleanUp(@NotNull final MaterialDef materialDef, @NotNull final Techn } else if (WorldShaderNodeElement.NAMESPACE.equals(state.getNameSpace())) { - final UniformBinding binding = findWorldBindingByName(techniqueDef, state.getName()); + var binding = findWorldBindingByName(techniqueDef, state.getName()); if (binding == null) { iterator.remove(); @@ -119,7 +119,7 @@ public void cleanUp(@NotNull final MaterialDef materialDef, @NotNull final Techn } else if (AttributeShaderNodeElement.NAMESPACE.equals(state.getNameSpace())) { - final ShaderNodeVariable attribute = findAttributeByName(techniqueDef, state.getName()); + var attribute = findAttributeByName(techniqueDef, state.getName()); if (attribute == null) { iterator.remove(); @@ -128,10 +128,10 @@ public void cleanUp(@NotNull final MaterialDef materialDef, @NotNull final Techn } } - for (final Iterator iterator = shaderNodeStates.iterator(); iterator.hasNext(); ) { + for (var iterator = shaderNodeStates.iterator(); iterator.hasNext(); ) { - final ShaderNodeState state = iterator.next(); - final ShaderNode shaderNode = findByName(techniqueDef, state.getName()); + var state = iterator.next(); + var shaderNode = findByName(techniqueDef, state.getName()); if (shaderNode == null) { iterator.remove(); @@ -147,19 +147,22 @@ public void cleanUp(@NotNull final MaterialDef materialDef, @NotNull final Techn * @param location the location. * @param width the width. */ - @FXThread - public void notifyChange(@NotNull final ShaderNodeVariable variable, @NotNull final Vector2f location, - final double width) { + @FxThread + public void notifyChange( + @NotNull ShaderNodeVariable variable, + @NotNull Vector2f location, + double width + ) { LOGGER.debug(variable, location, (var, pos) -> "Changed shader node variable: " + var + " to location " + pos); - final Optional state = shaderVariableStates.stream() + var state = shaderVariableStates.stream() .filter(variableState -> variableState.getNameSpace().equals(variable.getNameSpace())) .filter(variableState -> variableState.getName().equals(variable.getName())) .findAny(); if (state.isPresent()) { - final ShaderNodeVariableState variableState = state.get(); + var variableState = state.get(); variableState.setLocation(location); variableState.setWidth((int) width); } else { @@ -179,18 +182,21 @@ public void notifyChange(@NotNull final ShaderNodeVariable variable, @NotNull fi * @param location the location. * @param width the width. */ - @FXThread - public void notifyChange(@NotNull final ShaderNode shaderNode, @NotNull final Vector2f location, - final double width) { + @FxThread + public void notifyChange( + @NotNull ShaderNode shaderNode, + @NotNull Vector2f location, + double width + ) { LOGGER.debug(shaderNode, location, (node, pos) -> "Changed shader node: " + node + " to location " + pos); - final Optional state = shaderNodeStates.stream() + var state = shaderNodeStates.stream() .filter(variableState -> variableState.getName().equals(shaderNode.getName())) .findAny(); if (state.isPresent()) { - final ShaderNodeState nodeState = state.get(); + var nodeState = state.get(); nodeState.setLocation(location); nodeState.setWidth((int) width); } else { @@ -208,9 +214,10 @@ public void notifyChange(@NotNull final ShaderNode shaderNode, @NotNull final Ve * @param shaderNode the shader nodes. * @return the state or null. */ - @FXThread - public @Nullable ShaderNodeState getState(@NotNull final ShaderNode shaderNode) { - return shaderNodeStates.stream().filter(variableState -> variableState.getName().equals(shaderNode.getName())) + @FxThread + public @Nullable ShaderNodeState getState(@NotNull ShaderNode shaderNode) { + return shaderNodeStates.stream() + .filter(varState -> varState.getName().equals(shaderNode.getName())) .findAny().orElse(null); } @@ -220,8 +227,8 @@ public void notifyChange(@NotNull final ShaderNode shaderNode, @NotNull final Ve * @param variable the shader nodes variable. * @return the state or null. */ - @FXThread - public @Nullable ShaderNodeVariableState getState(@Nullable final ShaderNodeVariable variable) { + @FxThread + public @Nullable ShaderNodeVariableState getState(@Nullable ShaderNodeVariable variable) { if (variable == null) return null; return shaderVariableStates.stream() .filter(variableState -> variableState.getNameSpace().equals(variable.getNameSpace())) @@ -234,7 +241,7 @@ public void notifyChange(@NotNull final ShaderNode shaderNode, @NotNull final Ve * * @return the name of technique definition. */ - @FXThread + @FxThread public @NotNull String getName() { return name; } @@ -244,7 +251,7 @@ public void notifyChange(@NotNull final ShaderNode shaderNode, @NotNull final Ve * * @return the location of input nodes. */ - @FXThread + @FxThread public @NotNull Vector2f getInputNodeLocation() { return inputNodeLocation; } @@ -254,7 +261,7 @@ public void notifyChange(@NotNull final ShaderNode shaderNode, @NotNull final Ve * * @return the location of output nodes. */ - @FXThread + @FxThread public @NotNull Vector2f getOutputNodeLocation() { return outputNodeLocation; } @@ -264,9 +271,9 @@ public void notifyChange(@NotNull final ShaderNode shaderNode, @NotNull final Ve * * @param inputNodeLocation the location of input nodes. */ - @FXThread - public void setInputNodeLocation(@NotNull final Vector2f inputNodeLocation) { - final Vector2f prev = getInputNodeLocation(); + @FxThread + public void setInputNodeLocation(@NotNull Vector2f inputNodeLocation) { + var prev = getInputNodeLocation(); this.inputNodeLocation = inputNodeLocation; if (!prev.equals(inputNodeLocation)) notifyChange(); } @@ -276,9 +283,9 @@ public void setInputNodeLocation(@NotNull final Vector2f inputNodeLocation) { * * @param outputNodeLocation the location of output nodes. */ - @FXThread - public void setOutputNodeLocation(@NotNull final Vector2f outputNodeLocation) { - final Vector2f prev = getOutputNodeLocation(); + @FxThread + public void setOutputNodeLocation(@NotNull Vector2f outputNodeLocation) { + var prev = getOutputNodeLocation(); this.outputNodeLocation = outputNodeLocation; if (!prev.equals(outputNodeLocation)) notifyChange(); } @@ -288,7 +295,7 @@ public void setOutputNodeLocation(@NotNull final Vector2f outputNodeLocation) { * * @return the width of output nodes. */ - @FXThread + @FxThread public int getOutputNodeWidth() { return outputNodeWidth; } @@ -298,7 +305,7 @@ public int getOutputNodeWidth() { * * @return the width of input nodes. */ - @FXThread + @FxThread public int getInputNodeWidth() { return inputNodeWidth; } @@ -308,9 +315,9 @@ public int getInputNodeWidth() { * * @param outputNodeWidth the width of output nodes. */ - @FXThread - public void setOutputNodeWidth(final int outputNodeWidth) { - final int prev = getOutputNodeWidth(); + @FxThread + public void setOutputNodeWidth(int outputNodeWidth) { + var prev = getOutputNodeWidth(); this.outputNodeWidth = outputNodeWidth; if (prev != outputNodeWidth) notifyChange(); } @@ -320,9 +327,9 @@ public void setOutputNodeWidth(final int outputNodeWidth) { * * @param inputNodeWidth the width of input nodes. */ - @FXThread - public void setInputNodeWidth(final int inputNodeWidth) { - final int prev = getInputNodeWidth(); + @FxThread + public void setInputNodeWidth(int inputNodeWidth) { + var prev = getInputNodeWidth(); this.inputNodeWidth = inputNodeWidth; if (prev != inputNodeWidth) notifyChange(); } @@ -330,13 +337,13 @@ public void setInputNodeWidth(final int inputNodeWidth) { @Override public String toString() { - final StringBuilder builder = new StringBuilder("TechniqueDefState"); + var builder = new StringBuilder("TechniqueDefState"); builder.append("(name:").append(name).append(")"); if (!shaderNodeStates.isEmpty()) { builder.append("\n\t\tShader Nodes:\n"); - for (final ShaderNodeState state : shaderNodeStates) { + for (var state : shaderNodeStates) { builder.append("\t\t\t").append(state).append("\n"); } @@ -346,7 +353,7 @@ public String toString() { if (!shaderVariableStates.isEmpty()) { builder.append("\n\t\tShader Variables:\n"); - for (final ShaderNodeVariableState state : shaderVariableStates) { + for (var state : shaderVariableStates) { builder.append("\t\t\t").append(state).append("\n"); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/CodePreviewComponent.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/CodePreviewComponent.java index 77c7938..8b9063c 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/CodePreviewComponent.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/CodePreviewComponent.java @@ -3,7 +3,7 @@ import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.asset.AssetManager; import com.jme3.renderer.RenderManager; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.ui.control.code.BaseCodeArea; import javafx.scene.layout.VBox; import org.jetbrains.annotations.NotNull; @@ -40,7 +40,7 @@ public CodePreviewComponent(@NotNull final AssetManager assetManager, @NotNull f createComponents(); } - @FXThread + @FxThread protected abstract void createComponents(); /** @@ -48,7 +48,7 @@ public CodePreviewComponent(@NotNull final AssetManager assetManager, @NotNull f * * @return the render manager. */ - @FXThread + @FxThread protected @NotNull RenderManager getRenderManager() { return renderManager; } @@ -58,7 +58,7 @@ public CodePreviewComponent(@NotNull final AssetManager assetManager, @NotNull f * * @return the asset manager. */ - @FXThread + @FxThread protected @NotNull AssetManager getAssetManager() { return assetManager; } @@ -68,7 +68,7 @@ public CodePreviewComponent(@NotNull final AssetManager assetManager, @NotNull f * * @return the code area. */ - @FXThread + @FxThread protected @NotNull BaseCodeArea getCodeArea() { return notNull(codeArea); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/material/definition/MaterialDefCodePreviewComponent.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/material/definition/MaterialDefCodePreviewComponent.java index 4fe63f0..a4800c5 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/material/definition/MaterialDefCodePreviewComponent.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/material/definition/MaterialDefCodePreviewComponent.java @@ -6,7 +6,7 @@ import com.jme3.material.MaterialDef; import com.jme3.material.plugin.export.materialdef.J3mdExporter; import com.jme3.renderer.RenderManager; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.preview.CodePreviewComponent; import com.ss.editor.ui.control.code.BaseCodeArea; import com.ss.editor.ui.control.code.MaterialDefinitionCodeArea; @@ -29,7 +29,7 @@ public MaterialDefCodePreviewComponent(@NotNull final AssetManager assetManager, } @Override - @FXThread + @FxThread protected void createComponents() { codeArea = new MaterialDefinitionCodeArea(); @@ -45,7 +45,7 @@ protected void createComponents() { * * @param materialDef the material definition. */ - @FXThread + @FxThread public void load(@NotNull final MaterialDef materialDef) { final ByteArrayOutputStream bout = new ByteArrayOutputStream(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/FragmentShaderCodePreviewComponent.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/FragmentShaderCodePreviewComponent.java index 8ac28a6..8b3b0f5 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/FragmentShaderCodePreviewComponent.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/FragmentShaderCodePreviewComponent.java @@ -3,7 +3,7 @@ import com.jme3.asset.AssetManager; import com.jme3.renderer.RenderManager; import com.jme3.shader.Shader; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import org.jetbrains.annotations.NotNull; /** @@ -19,7 +19,7 @@ public FragmentShaderCodePreviewComponent(@NotNull final AssetManager assetManag } @Override - @FXThread + @FxThread protected @NotNull Shader.ShaderType getShaderType() { return Shader.ShaderType.Fragment; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/ShaderCodePreviewComponent.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/ShaderCodePreviewComponent.java index 212e86f..83d6ed6 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/ShaderCodePreviewComponent.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/ShaderCodePreviewComponent.java @@ -1,6 +1,6 @@ package com.ss.editor.shader.nodes.ui.component.preview.shader; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_CODE_PREVIEW_CONTAINER; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_CODE_PREVIEW_CONTAINER; import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.asset.AssetManager; import com.jme3.material.TechniqueDef; @@ -10,14 +10,14 @@ import com.jme3.shader.Shader; import com.jme3.shader.ShaderGenerator; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.manager.ExecutorManager; import com.ss.editor.shader.nodes.ui.component.preview.CodePreviewComponent; import com.ss.editor.ui.control.code.BaseCodeArea; import com.ss.editor.ui.control.code.GLSLCodeArea; -import com.ss.editor.ui.css.CSSClasses; +import com.ss.editor.ui.css.CssClasses; import com.ss.rlib.ui.util.FXUtils; import javafx.collections.ObservableList; import javafx.scene.control.ComboBox; @@ -55,7 +55,7 @@ public ShaderCodePreviewComponent(@NotNull final AssetManager assetManager, } @Override - @FXThread + @FxThread protected void createComponents() { final Label languageLabel = new Label(Messages.MODEL_PROPERTY_LANGUAGE + ":"); @@ -77,7 +77,7 @@ protected void createComponents() { FXUtils.addToPane(languageContainer, this); FXUtils.addToPane(codeArea, this); - FXUtils.addClassTo(languageContainer, CSSClasses.DEF_HBOX); + FXUtils.addClassTo(languageContainer, CssClasses.DEF_HBOX); } /** @@ -85,7 +85,7 @@ protected void createComponents() { * * @return the shader type. */ - @FXThread + @FxThread protected abstract @NotNull Shader.ShaderType getShaderType(); /** @@ -93,7 +93,7 @@ protected void createComponents() { * * @param newValue the new shader language or null. */ - @FXThread + @FxThread private void changeLanguage(@Nullable final String newValue) { final BaseCodeArea codeArea = getCodeArea(); @@ -126,7 +126,7 @@ private void changeLanguage(@Nullable final String newValue) { @FromAnyThread public void load(@NotNull final TechniqueDef techniqueDef) { final ExecutorManager executorManager = ExecutorManager.getInstance(); - executorManager.addJMETask(() -> generateShader(techniqueDef)); + executorManager.addJmeTask(() -> generateShader(techniqueDef)); } /** @@ -134,7 +134,7 @@ public void load(@NotNull final TechniqueDef techniqueDef) { * * @param techniqueDef the technique definition. */ - @JMEThread + @JmeThread private void generateShader(@NotNull final TechniqueDef techniqueDef) { final Renderer renderer = getRenderManager().getRenderer(); @@ -145,13 +145,13 @@ private void generateShader(@NotNull final TechniqueDef techniqueDef) { this.shader = abstractShaderGenerator.generateShader(""); final ExecutorManager executorManager = ExecutorManager.getInstance(); - executorManager.addFXTask(this::loadShader); + executorManager.addFxTask(this::loadShader); } /** * Load languages from the generated shader. */ - @FXThread + @FxThread private void loadShader() { final ComboBox languageBox = getLanguageBox(); @@ -173,7 +173,7 @@ private void loadShader() { * * @return the box with language options. */ - @FXThread + @FxThread private @NotNull ComboBox getLanguageBox() { return notNull(languageBox); } @@ -183,7 +183,7 @@ private void loadShader() { * * @return the current shader. */ - @FXThread + @FxThread protected @NotNull Shader getShader() { return notNull(shader); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/VertexShaderCodePreviewComponent.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/VertexShaderCodePreviewComponent.java index f62ebd1..291a9f3 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/VertexShaderCodePreviewComponent.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/preview/shader/VertexShaderCodePreviewComponent.java @@ -3,7 +3,7 @@ import com.jme3.asset.AssetManager; import com.jme3.renderer.RenderManager; import com.jme3.shader.Shader; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import org.jetbrains.annotations.NotNull; /** @@ -19,7 +19,7 @@ public VertexShaderCodePreviewComponent(@NotNull final AssetManager assetManager } @Override - @FXThread + @FxThread protected @NotNull Shader.ShaderType getShaderType() { return Shader.ShaderType.Vertex; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/ShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/ShaderNodeElement.java index f2be49c..03a2bd3 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/ShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/ShaderNodeElement.java @@ -1,11 +1,11 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_HEADER; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_HEADER; import static com.ss.editor.shader.nodes.util.ShaderNodeUtils.*; import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.remove.RemoveRelationShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.line.VariableLine; @@ -13,6 +13,7 @@ import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.OutputShaderNodeParameter; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.SocketElement; +import com.ss.editor.shader.nodes.util.ShaderNodeUtils; import com.ss.rlib.ui.util.FXUtils; import com.ss.rlib.util.StringUtils; import javafx.beans.property.BooleanProperty; @@ -22,6 +23,7 @@ import javafx.scene.Cursor; import javafx.scene.Parent; import javafx.scene.control.Label; +import javafx.scene.control.Tooltip; import javafx.scene.input.ContextMenuEvent; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; @@ -30,6 +32,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Optional; + /** * The base implementation of shader nodes. * @@ -106,15 +110,16 @@ public String getName() { public ShaderNodeElement(@NotNull final ShaderNodesContainer container, @NotNull final T object) { this.container = container; + this.object = object; + this.parametersContainer = new VBox(); setOnMousePressed(this::handleMousePressed); setOnMouseDragged(this::handleMouseDragged); setOnMouseMoved(this::handleMouseMoved); setOnMouseReleased(this::handleMouseReleased); setOnContextMenuRequested(this::handleContextMenuRequested); - this.object = object; - this.parametersContainer = new VBox(); createContent(); setPrefWidth(200); + createTooltip().ifPresent(tooltip -> Tooltip.install(this, tooltip)); FXUtils.addClassTo(this, SHADER_NODE); } @@ -123,21 +128,29 @@ public ShaderNodeElement(@NotNull final ShaderNodesContainer container, @NotNull * * @return the container of nodes parameters. */ - @FXThread + @FxThread protected @NotNull VBox getParametersContainer() { return parametersContainer; } + /** + * Create a tooltip of this node element. + * + * @return the tooltip. + */ + @FxThread + protected @NotNull Optional createTooltip() { + return Optional.empty(); + } + /** * Handle the context menu requested events. * * @param event the context menu requested event. */ - @FXThread + @FxThread private void handleContextMenuRequested(@NotNull final ContextMenuEvent event) { - final ShaderNodesContainer container = getContainer(); - container.handleContextMenuEvent(event); - event.consume(); + getContainer().handleContextMenuEvent(event); } /** @@ -147,7 +160,7 @@ private void handleContextMenuRequested(@NotNull final ContextMenuEvent event) { * @param outputParameter the output parameter. * @return true of we can attach. */ - @FXThread + @FxThread public boolean canAttach(@NotNull final InputShaderNodeParameter inputParameter, @NotNull final OutputShaderNodeParameter outputParameter) { @@ -155,11 +168,10 @@ public boolean canAttach(@NotNull final InputShaderNodeParameter inputParameter, return false; } - final ShaderNodeVariable inVar = inputParameter.getVariable(); - final ShaderNodeVariable outVar = outputParameter.getVariable(); - - final String inType = inVar.getType(); - final String outType = outVar.getType(); + var inVar = inputParameter.getVariable(); + var outVar = outputParameter.getVariable(); + var inType = inVar.getType(); + var outType = outVar.getType(); return isAccessibleType(inType, outType) || !StringUtils.isEmpty(calculateRightSwizzling(inVar, outVar)) || !StringUtils.isEmpty(calculateLeftSwizzling(inVar, outVar)); @@ -171,23 +183,27 @@ public boolean canAttach(@NotNull final InputShaderNodeParameter inputParameter, * @param inputParameter the input parameter. * @param outputParameter the output parameter. */ - @FXThread + @FxThread public void attach(@NotNull final InputShaderNodeParameter inputParameter, @NotNull final OutputShaderNodeParameter outputParameter) { } /** + * Get the container of this nodes. + * * @return the container of this nodes. */ - @FXThread + @FxThread public @NotNull ShaderNodesContainer getContainer() { return container; } /** + * Get the shader object. + * * @return the shader object. */ - @FXThread + @FxThread public @NotNull T getObject() { return object; } @@ -200,13 +216,14 @@ public void attach(@NotNull final InputShaderNodeParameter inputParameter, * @param input true if the variable is input variable. * @return the parameter or null. */ - @FXThread + @FxThread public @Nullable ShaderNodeParameter parameterFor(@NotNull final ShaderNodeVariable variable, - final boolean fromOutputMapping, final boolean input) { + final boolean fromOutputMapping, + final boolean input) { return parametersContainer.getChildren().stream() .filter(ShaderNodeParameter.class::isInstance) - .filter(node -> input ? node instanceof InputShaderNodeParameter : node instanceof OutputShaderNodeParameter) .map(ShaderNodeParameter.class::cast) + .filter(node -> input == isInput(node)) .filter(parameter -> parameter.getVariable().getName().equals(variable.getName())) .findAny().orElse(null); } @@ -216,7 +233,7 @@ public void attach(@NotNull final InputShaderNodeParameter inputParameter, * * @return the title text of this nodes. */ - @FXThread + @FxThread protected @NotNull String getTitleText() { return "Title"; } @@ -224,11 +241,11 @@ public void attach(@NotNull final InputShaderNodeParameter inputParameter, /** * Create UI content of this nodes. */ - @FXThread + @FxThread protected void createContent() { - final StackPane header = new StackPane(); - final Label titleLabel = new Label(getTitleText()); + var header = new StackPane(); + var titleLabel = new Label(getTitleText()); FXUtils.addClassTo(header, SHADER_NODE_HEADER); @@ -242,22 +259,33 @@ protected void createContent() { /** * Reset layout of this nodes. */ - @FXThread + @FxThread public void resetLayout() { - final double layoutX = getLayoutX(); - final double layoutY = getLayoutY(); + var layoutX = getLayoutX(); + var layoutY = getLayoutY(); setLayoutX(-1D); setLayoutY(-1D); setLayoutX(layoutX); setLayoutY(layoutY); } + /** + * Refresh this component. + */ + @FxThread + public void refresh() { + getParametersContainer().getChildren() + .stream() + .map(ShaderNodeParameter.class::cast) + .forEach(ShaderNodeParameter::refresh); + } + /** * Fill parameters of this nodes. * * @param container the parameters container. */ - @FXThread + @FxThread protected void fillParameters(@NotNull final VBox container) { } @@ -266,7 +294,7 @@ protected void fillParameters(@NotNull final VBox container) { * * @param event the mouse event. */ - @FXThread + @FxThread private void handleMouseDragged(@NotNull final MouseEvent event) { if (event.getTarget() instanceof SocketElement) { @@ -274,17 +302,16 @@ private void handleMouseDragged(@NotNull final MouseEvent event) { } if (isResizing()) { - final double mouseX = event.getX(); + var mouseX = event.getX(); setPrefWidth(getPrefWidth() + (mouseX - x)); resetLayout(); x = mouseX; } else { - final Parent parent = getParent(); - final Point2D parentCoords = parent.sceneToLocal(event.getSceneX(), event.getSceneY()); - - double offsetX = parentCoords.getX() - mouseX; - double offsetY = parentCoords.getY() - mouseY; + var parent = getParent(); + var posInParent = parent.sceneToLocal(event.getSceneX(), event.getSceneY()); + var offsetX = posInParent.getX() - mouseX; + var offsetY = posInParent.getY() - mouseY; x = Math.max(x + offsetX, 10D); y = Math.max(y + offsetY, 10D); @@ -294,8 +321,8 @@ private void handleMouseDragged(@NotNull final MouseEvent event) { setDragging(true); // again set current Mouse x AND y position - mouseX = parentCoords.getX(); - mouseY = parentCoords.getY(); + mouseX = posInParent.getX(); + mouseY = posInParent.getY(); } event.consume(); @@ -306,7 +333,7 @@ private void handleMouseDragged(@NotNull final MouseEvent event) { * * @param event the mouse released event. */ - @FXThread + @FxThread private void handleMouseReleased(@NotNull final MouseEvent event) { if (isResizing()) { setResizing(false); @@ -324,7 +351,7 @@ private void handleMouseReleased(@NotNull final MouseEvent event) { * * @param event the mouse moved event. */ - @FXThread + @FxThread private void handleMouseMoved(@NotNull final MouseEvent event) { if (event.getTarget() instanceof SocketElement) { @@ -344,7 +371,7 @@ private void handleMouseMoved(@NotNull final MouseEvent event) { * * @param selected true if this nodes is selected. */ - @FXThread + @FxThread public void setSelected(final boolean selected) { this.selected.setValue(selected); } @@ -354,12 +381,14 @@ public void setSelected(final boolean selected) { * * @param event the mouse pressed event. */ - @FXThread + @FxThread private void handleMousePressed(@NotNull final MouseEvent event) { if (event.getTarget() instanceof SocketElement) { return; - } else if (event.getButton() != MouseButton.MIDDLE) { + } + + if (event.getButton() != MouseButton.MIDDLE) { container.requestSelect(this); } @@ -368,12 +397,12 @@ private void handleMousePressed(@NotNull final MouseEvent event) { x = event.getX(); } else { - final Parent parent = getParent(); - final Point2D parentCoords = parent.sceneToLocal(event.getSceneX(), event.getSceneY()); + final var parent = getParent(); + final var posInParent = parent.sceneToLocal(event.getSceneX(), event.getSceneY()); // record the current mouse X and Y position on Node - mouseX = parentCoords.getX(); - mouseY = parentCoords.getY(); + mouseX = posInParent.getX(); + mouseY = posInParent.getY(); x = getLayoutX(); y = getLayoutY(); @@ -388,39 +417,47 @@ private void handleMousePressed(@NotNull final MouseEvent event) { * @param event the mouse event. * @return true if we can start to resize. */ - @FXThread + @FxThread protected boolean isInResizableZone(@NotNull final MouseEvent event) { return event.getX() > (getWidth() - RESIZE_MARGIN); } /** + * Return true if this nodes is dragging now. + * * @return true if this nodes is dragging now. */ - @FXThread + @FxThread protected boolean isDragging() { return dragging; } /** + * Set true if this nodes is dragging now. + * * @param dragging true if this nodes is dragging now. */ - @FXThread + @FxThread protected void setDragging(final boolean dragging) { this.dragging = dragging; } /** + * Return true if this nodes is resizing now. + * * @return true if this nodes is resizing now. */ - @FXThread + @FxThread protected boolean isResizing() { return resizing; } /** + * Set true if this nodes is resizing now. + * * @param resizing true if this nodes is resizing now. */ - @FXThread + @FxThread protected void setResizing(final boolean resizing) { this.resizing = resizing; } @@ -430,7 +467,7 @@ protected void setResizing(final boolean resizing) { * * @return the action or null. */ - @FXThread + @FxThread public @Nullable ShaderNodeAction getDeleteAction() { return null; } @@ -441,7 +478,7 @@ protected void setResizing(final boolean resizing) { * @param line the line. * @return the action or null. */ - @FXThread + @FxThread public @Nullable ShaderNodeAction getDetachAction(@NotNull final VariableLine line) { return new RemoveRelationShaderNodeAction(getContainer(), line, Vector2f.ZERO); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/ShaderNodesContainer.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/ShaderNodesContainer.java index 1e7191e..09de574 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/ShaderNodesContainer.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/ShaderNodesContainer.java @@ -1,30 +1,29 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODES_ROOT; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODES_ROOT; import static com.ss.editor.shader.nodes.util.ShaderNodeUtils.hasInMappingByRightVar; import static com.ss.editor.shader.nodes.util.ShaderNodeUtils.hasOutMappingByLeftVar; import static com.ss.rlib.util.ObjectUtils.notNull; import static java.util.stream.Collectors.toList; import com.jme3.material.MatParam; import com.jme3.material.MaterialDef; -import com.jme3.material.ShaderGenerationInfo; import com.jme3.material.TechniqueDef; import com.jme3.math.Vector2f; import com.jme3.shader.*; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.manager.ExecutorManager; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; -import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.add.*; -import com.ss.editor.shader.nodes.ui.component.shader.nodes.global.GlobalShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.global.InputGlobalShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.global.OutputGlobalShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.line.TempLine; import com.ss.editor.shader.nodes.ui.component.shader.nodes.line.VariableLine; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.*; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.InputShaderNodeParameter; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.SocketElement; import com.ss.editor.shader.nodes.util.MaterialDefUtils; +import com.ss.editor.shader.nodes.util.ShaderNodeUtils; import com.ss.rlib.logging.Logger; import com.ss.rlib.logging.LoggerManager; import com.ss.rlib.ui.util.FXUtils; @@ -32,14 +31,11 @@ import com.ss.rlib.util.array.Array; import com.ss.rlib.util.array.ArrayFactory; import javafx.collections.ObservableList; -import javafx.geometry.Bounds; -import javafx.geometry.Point2D; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.control.ContextMenu; import javafx.scene.control.Menu; -import javafx.scene.control.MenuItem; import javafx.scene.control.ScrollPane; import javafx.scene.input.*; import javafx.scene.layout.Pane; @@ -48,11 +44,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.function.Predicate; +import java.util.stream.Collectors; /** * The container of all shader nodes. @@ -133,7 +127,7 @@ public ShaderNodesContainer(@NotNull final ShaderNodesChangeConsumer changeConsu FXUtils.addClassTo(root, SHADER_NODES_ROOT); - final VBox centered = new VBox(zoomNode); + var centered = new VBox(zoomNode); centered.setAlignment(Pos.CENTER); setPannable(true); @@ -148,7 +142,7 @@ public ShaderNodesContainer(@NotNull final ShaderNodesChangeConsumer changeConsu /** * Notify about changed preview material. */ - @FXThread + @FxThread public void notifyChangedMaterial() { getNodeElements().stream() .filter(MaterialShaderNodeElement.class::isInstance) @@ -161,7 +155,7 @@ public void notifyChangedMaterial() { * * @return all current nodes elements. */ - @FXThread + @FxThread private @NotNull Array> getNodeElements() { return nodeElements; } @@ -169,7 +163,7 @@ public void notifyChangedMaterial() { /** * @return the change consumer. */ - @FXThread + @FxThread public @NotNull ShaderNodesChangeConsumer getChangeConsumer() { return changeConsumer; } @@ -177,13 +171,13 @@ public void notifyChangedMaterial() { /** * Reset all layouts. */ - @FXThread + @FxThread private void invalidateSizes() { - final ShaderNodesChangeConsumer consumer = getChangeConsumer(); - final Array> nodeElements = getNodeElements(); + var consumer = getChangeConsumer(); + var nodeElements = getNodeElements(); - for (final ShaderNodeElement nodeElement : nodeElements) { + for (var nodeElement : nodeElements) { nodeElement.resetLayout(); final Object object = nodeElement.getObject(); @@ -209,21 +203,20 @@ private void invalidateSizes() { nodeElement.resize(width, nodeElement.getHeight()); } - EXECUTOR_MANAGER.addFXTask(this::invalidateLayout); + EXECUTOR_MANAGER.addFxTask(this::invalidateLayout); } /** * Update all layouts. */ - @FXThread + @FxThread private void invalidateLayout() { - final ShaderNodesChangeConsumer consumer = getChangeConsumer(); - final Array> nodeElements = getNodeElements(); + var consumer = getChangeConsumer(); + var nodeElements = getNodeElements(); + var skipped = 0; - int skipped = 0; - - for (final ShaderNodeElement nodeElement : nodeElements) { + for (var nodeElement : nodeElements) { nodeElement.resetLayout(); final Object object = nodeElement.getObject(); @@ -260,15 +253,15 @@ private void invalidateLayout() { /** * Layout nodes. */ - @FXThread + @FxThread private void layoutNodes() { - final Array> nodeElements = getNodeElements(); - final ShaderNodeElement inputElement = nodeElements.stream() + var nodeElements = getNodeElements(); + var inputElement = nodeElements.stream() .filter(InputGlobalShaderNodeElement.class::isInstance) .findAny().orElse(null); - final ShaderNodeElement outputElement = nodeElements.stream() + var outputElement = nodeElements.stream() .filter(OutputGlobalShaderNodeElement.class::isInstance) .findAny().orElse(null); @@ -276,22 +269,22 @@ private void layoutNodes() { isInput = isInput.or(MaterialShaderNodeElement.class::isInstance) .or(WorldShaderNodeElement.class::isInstance); - final List> inputNodes = nodeElements.stream() + var inputNodes = nodeElements.stream() .filter(isInput) .sorted((first, second) -> StringUtils.compare(first.getClass().getName(), second.getClass().getName())) .collect(toList()); - final List> vertexNodes = nodeElements.stream() + var vertexNodes = nodeElements.stream() .filter(VertexShaderNodeElement.class::isInstance) .collect(toList()); - final List> fragmentNodes = nodeElements.stream() + var fragmentNodes = nodeElements.stream() .filter(FragmentShaderNodeElement.class::isInstance) .collect(toList()); - float inputElementStartX = 10F; - float inputElementStartY = 10F; - float inputElementEndY = inputElementStartY; + var inputElementStartX = 10F; + var inputElementStartY = 10F; + var inputElementEndY = inputElementStartY; if (inputElement != null) { inputElement.autosize(); @@ -304,10 +297,10 @@ private void layoutNodes() { inputElementEndY = (float) (inputElementStartY + inputElement.getHeight() + 30F); } - float inputNodeStartY = inputElementEndY; - float maxInputParameterWidth = 0; + var inputNodeStartY = inputElementEndY; + var maxInputParameterWidth = 0F; - for (final ShaderNodeElement inNode : inputNodes) { + for (var inNode : inputNodes) { inNode.autosize(); inNode.setLayoutX(inputElementStartX); @@ -320,12 +313,12 @@ private void layoutNodes() { maxInputParameterWidth = (float) Math.max(maxInputParameterWidth, inNode.getWidth() + 80D); } - float vertexNodeStartX = inputElementStartX + maxInputParameterWidth; - float vertexNodeStartY = inputElementEndY - 10F; - float maxVertexNodeWidth = 0F; - float maxVertexHeight = 0F; + var vertexNodeStartX = inputElementStartX + maxInputParameterWidth; + var vertexNodeStartY = inputElementEndY - 10F; + var maxVertexNodeWidth = 0F; + var maxVertexHeight = 0F; - for (final ShaderNodeElement vertexNode : vertexNodes) { + for (var vertexNode : vertexNodes) { vertexNode.autosize(); vertexNode.setLayoutX(vertexNodeStartX); @@ -339,12 +332,12 @@ private void layoutNodes() { maxVertexHeight = (float) Math.max(maxVertexHeight, vertexNode.getHeight() + 10D); } - float fragmentNodeStartX = inputElementStartX + maxInputParameterWidth + 40F; - float fragmentNodeStartY = inputElementEndY + 70F + maxVertexHeight; - float maxFragmentNodeWidth = 0F; - float maxFragmentHeight = 0F; + var fragmentNodeStartX = inputElementStartX + maxInputParameterWidth + 40F; + var fragmentNodeStartY = inputElementEndY + 70F + maxVertexHeight; + var maxFragmentNodeWidth = 0F; + var maxFragmentHeight = 0F; - for (final ShaderNodeElement fragmentNode : fragmentNodes) { + for (var fragmentNode : fragmentNodes) { fragmentNode.autosize(); fragmentNode.setLayoutX(fragmentNodeStartX); @@ -358,10 +351,10 @@ private void layoutNodes() { maxFragmentHeight = (float) Math.max(maxFragmentHeight, fragmentNode.getHeight() + 10D); } - float outputStartX = Math.max(fragmentNodeStartX, vertexNodeStartX); + var outputStartX = Math.max(fragmentNodeStartX, vertexNodeStartX); outputStartX += 10D; - float outputStartY = vertexNodeStartY + maxVertexHeight; + var outputStartY = vertexNodeStartY + maxVertexHeight; if (outputElement != null) { outputElement.autosize(); @@ -376,10 +369,9 @@ private void layoutNodes() { /** * Reset all layouts. */ - @FXThread + @FxThread private void resetLayout() { - final Array> nodeElements = getNodeElements(); - nodeElements.forEach(ShaderNodeElement::resetLayout); + getNodeElements().forEach(ShaderNodeElement::resetLayout); } /** @@ -387,7 +379,7 @@ private void resetLayout() { * * @return the temp line to show a process of binding variables. */ - @FXThread + @FxThread private @Nullable TempLine getTempLine() { return tempLine; } @@ -397,7 +389,7 @@ private void resetLayout() { * * @param tempLine the temp line to show a process of binding variables. */ - @FXThread + @FxThread private void setTempLine(@Nullable final TempLine tempLine) { this.tempLine = tempLine; } @@ -407,11 +399,10 @@ private void setTempLine(@Nullable final TempLine tempLine) { * * @param sourceSocket the source socket. */ - @FXThread + @FxThread public void startAttaching(@NotNull final SocketElement sourceSocket) { - TempLine tempLine = getTempLine(); - + var tempLine = getTempLine(); if (tempLine != null) { FXUtils.removeFromParent(tempLine, root); setTempLine(null); @@ -428,7 +419,7 @@ public void startAttaching(@NotNull final SocketElement sourceSocket) { * * @param dragEvent the drag over event. */ - @FXThread + @FxThread private void handleDragOver(@NotNull final DragEvent dragEvent) { if (dragEvent.getGestureSource() instanceof SocketElement) { updateAttaching(dragEvent.getSceneX(), dragEvent.getSceneY()); @@ -441,7 +432,7 @@ private void handleDragOver(@NotNull final DragEvent dragEvent) { * * @param event the mouse event. */ - @FXThread + @FxThread private void handleMouseClicked(@NotNull final MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY && contextMenu.isShowing()) { contextMenu.hide(); @@ -453,25 +444,26 @@ private void handleMouseClicked(@NotNull final MouseEvent event) { * * @param event the context menu event. */ - @FXThread + @FxThread public void handleContextMenuEvent(@NotNull final ContextMenuEvent event) { - final Object source = event.getSource(); + var source = event.getSource(); if (contextMenu.isShowing()) { contextMenu.hide(); } - final Vector2f location = new Vector2f((float) event.getX(), (float) event.getY()); - final TechniqueDef techniqueDef = getTechniqueDef(); - final MaterialDef materialDef = getChangeConsumer().getMaterialDef(); + var location = new Vector2f((float) event.getX(), (float) event.getY()); + var techniqueDef = getTechniqueDef(); + var materialDef = getChangeConsumer().getMaterialDef(); - final ObservableList items = contextMenu.getItems(); + var items = contextMenu.getItems(); items.clear(); if (source == root) { - final Menu menu = new Menu("Add"); + //FIXME localization + var menu = new Menu("Add"); menu.getItems().addAll(new AddMaterialParamShaderNodeAction(this, materialDef, location), new AddMaterialTextureShaderNodeAction(this, materialDef, location), new AddWorldParamShaderNodeAction(this, techniqueDef, location), @@ -482,8 +474,8 @@ public void handleContextMenuEvent(@NotNull final ContextMenuEvent event) { } else if (source instanceof ShaderNodeElement) { - final ShaderNodeElement nodeElement = (ShaderNodeElement) source; - final ShaderNodeAction deleteAction = nodeElement.getDeleteAction(); + var nodeElement = (ShaderNodeElement) source; + var deleteAction = nodeElement.getDeleteAction(); if(deleteAction != null) { items.add(deleteAction); @@ -491,9 +483,9 @@ public void handleContextMenuEvent(@NotNull final ContextMenuEvent event) { } else if (source instanceof VariableLine) { - final ShaderNodeParameter parameter = ((VariableLine) source).getInParameter(); - final ShaderNodeElement nodeElement = parameter.getNodeElement(); - final ShaderNodeAction detachAction = nodeElement.getDetachAction((VariableLine) source); + var parameter = ((VariableLine) source).getInParameter(); + var nodeElement = parameter.getNodeElement(); + var detachAction = nodeElement.getDetachAction((VariableLine) source); if (detachAction != null) { items.add(detachAction); @@ -501,6 +493,8 @@ public void handleContextMenuEvent(@NotNull final ContextMenuEvent event) { } contextMenu.show(root, event.getScreenX(), event.getScreenY()); + + event.consume(); } /** @@ -509,24 +503,28 @@ public void handleContextMenuEvent(@NotNull final ContextMenuEvent event) { * @param sceneX the sceneX. * @param sceneY the sceneY. */ - @FXThread + @FxThread public void updateAttaching(final double sceneX, final double sceneY) { - final TempLine tempLine = getTempLine(); - if (tempLine == null) return; + var tempLine = getTempLine(); + if (tempLine == null) { + return; + } - final Point2D localCoords = root.sceneToLocal(sceneX, sceneY); + var localCoords = root.sceneToLocal(sceneX, sceneY); tempLine.updateEnd(localCoords.getX(), localCoords.getY()); } /** * Handle finish the process of attaching. */ - @FXThread + @FxThread public void finishAttaching() { - final TempLine tempLine = getTempLine(); - if (tempLine == null) return; + var tempLine = getTempLine(); + if (tempLine == null) { + return; + } FXUtils.removeFromParent(tempLine, root); setTempLine(null); @@ -537,14 +535,14 @@ public void finishAttaching() { * * @param requester the nodes to select. */ - @FXThread + @FxThread public void requestSelect(@NotNull final ShaderNodeElement requester) { - final ObservableList children = root.getChildren(); - children.stream().filter(node -> node != requester) - .filter(ShaderNodeElement.class::isInstance) - .map(node -> (ShaderNodeElement) node) - .forEach(element -> element.setSelected(false)); + root.getChildren().stream() + .filter(node -> node != requester) + .filter(ShaderNodeElement.class::isInstance) + .map(node -> (ShaderNodeElement) node) + .forEach(element -> element.setSelected(false)); requester.setSelected(true); } @@ -554,7 +552,7 @@ public void requestSelect(@NotNull final ShaderNodeElement requester) { * * @return the root component to place all nodes. */ - @FXThread + @FxThread private @NotNull Pane getRoot() { return root; } @@ -564,32 +562,35 @@ public void requestSelect(@NotNull final ShaderNodeElement requester) { * * @param techniqueDef the technique. */ - @FXThread + @FxThread public void show(@NotNull final TechniqueDef techniqueDef) { - if (techniqueDef.equals(this.techniqueDef)) return; + + if (techniqueDef.equals(this.techniqueDef)) { + return; + } this.techniqueDef = techniqueDef; - final ShaderGenerationInfo shaderGenerationInfo = techniqueDef.getShaderGenerationInfo(); - final Pane root = getRoot(); + var shaderGenerationInfo = techniqueDef.getShaderGenerationInfo(); + var root = getRoot(); root.getChildren().clear(); - final Array> nodeElements = getNodeElements(); + var nodeElements = getNodeElements(); nodeElements.clear(); - final ShaderNodesChangeConsumer consumer = getChangeConsumer(); - final MaterialDef materialDef = consumer.getMaterialDef(); + var consumer = getChangeConsumer(); + var materialDef = consumer.getMaterialDef(); - final Map matParams = MaterialDefUtils.getMatParams(materialDef); - final List worldBindings = techniqueDef.getWorldBindings(); + var matParams = MaterialDefUtils.getMatParams(materialDef); + var worldBindings = techniqueDef.getWorldBindings(); final List uniforms = new ArrayList<>(); - for (final MatParam matParam : matParams.values()) { + for (var matParam : matParams.values()) { uniforms.add(MaterialShaderNodeElement.toVariable(matParam)); } - for (final UniformBinding worldBinding : worldBindings) { + for (var worldBinding : worldBindings) { uniforms.add(WorldShaderNodeElement.toVariable(worldBinding)); } @@ -598,17 +599,14 @@ public void show(@NotNull final TechniqueDef techniqueDef) { nodeElements.add(new InputGlobalShaderNodeElement(this, shaderGenerationInfo)); nodeElements.add(new OutputGlobalShaderNodeElement(this, shaderGenerationInfo)); - for (final ShaderNodeVariable variable : uniforms) { - final ShaderNodeElement nodeElement = createNodeElement(variable); - if (nodeElement != null) { - nodeElements.add(nodeElement); - } + for (var variable : uniforms) { + createNodeElement(variable).ifPresent(nodeElements::add); } - final List shaderNodes = techniqueDef.getShaderNodes(); + var shaderNodes = techniqueDef.getShaderNodes(); - for (final ShaderNode shaderNode : shaderNodes) { - final ShaderNodeDefinition definition = shaderNode.getDefinition(); + for (var shaderNode : shaderNodes) { + var definition = shaderNode.getDefinition(); if (definition.getType() == Shader.ShaderType.Vertex) { nodeElements.add(new VertexShaderNodeElement(this, shaderNode)); } else if (definition.getType() == Shader.ShaderType.Fragment) { @@ -616,10 +614,12 @@ public void show(@NotNull final TechniqueDef techniqueDef) { } } - nodeElements.forEach(root.getChildren(), (nodeElement, nodes) -> nodes.add(nodeElement)); + nodeElements.forEach(root.getChildren(), + (nodeElement, nodes) -> nodes.add(nodeElement)); + refreshLines(); - EXECUTOR_MANAGER.addFXTask(this::invalidateSizes); + EXECUTOR_MANAGER.addFxTask(this::invalidateSizes); } /** @@ -628,7 +628,7 @@ public void show(@NotNull final TechniqueDef techniqueDef) { * @param leftVariable the left variable. * @return the list of nodes. */ - @FXThread + @FxThread public @NotNull List findWithLeftOutputVar(@NotNull final ShaderNodeVariable leftVariable) { return root.getChildren().stream() .filter(MainShaderNodeElement.class::isInstance) @@ -642,13 +642,12 @@ public void show(@NotNull final TechniqueDef techniqueDef) { * Find a shader node by the name. * * @param name the name. - * @return the found shader node or null. + * @return the optional of the shader node. */ - @FXThread - public @Nullable ShaderNode findShaderNodeByName(@NotNull final String name) { + @FxThread + private ShaderNode findShaderNodeByName(@NotNull final String name) { - if (MaterialShaderNodeElement.NAMESPACE.equals(name) || GlobalShaderNodeElement.NAMESPACE.equals(name) || - WorldShaderNodeElement.NAMESPACE.equals(name) || AttributeShaderNodeElement.NAMESPACE.equals(name)) { + if (ShaderNodeUtils.isUserShaderNode(name)) { return null; } @@ -660,25 +659,39 @@ public void show(@NotNull final TechniqueDef techniqueDef) { .findAny().orElse(null); } + /** + * Find a variable line for the shader node input parameter. + * + * @param parameter the input parameter. + * @return a variable line for the shader node input parameter. + */ + public @NotNull Optional findLineByInParameter(@NotNull final InputShaderNodeParameter parameter) { + return root.getChildren().stream() + .filter(VariableLine.class::isInstance) + .map(VariableLine.class::cast) + .filter(line -> line.getInParameter() == parameter) + .findAny(); + } + /** * Find all shader nodes which are used from the shader node. * * @param shaderNode the shader node. * @return the list of used shader nodes. */ - @FXThread + @FxThread public @NotNull List findUsedFrom(@NotNull final ShaderNode shaderNode) { return findUsedFrom(new ArrayList<>(), shaderNode); } - @FXThread + @FxThread private @NotNull List findUsedFrom(@NotNull final List result, @NotNull final ShaderNode shaderNode) { - for (final VariableMapping mapping : shaderNode.getInputMapping()) { + for (var mapping : shaderNode.getInputMapping()) { - final ShaderNodeVariable rightVariable = mapping.getRightVariable(); - final ShaderNode usedNode = findShaderNodeByName(rightVariable.getNameSpace()); + var rightVariable = mapping.getRightVariable(); + var usedNode = findShaderNodeByName(rightVariable.getNameSpace()); if (usedNode == null || result.contains(usedNode)) { continue; @@ -698,7 +711,7 @@ public void show(@NotNull final TechniqueDef techniqueDef) { * @param type the type. * @return the list of nodes. */ - @FXThread + @FxThread public @NotNull List findWithRightInputVar(@NotNull final ShaderNodeVariable rightVariable, @NotNull final Class type) { return root.getChildren().stream() @@ -713,30 +726,30 @@ public void show(@NotNull final TechniqueDef techniqueDef) { * Find a nodes element by the variable. * * @param variable the variable. - * @return the nodes element or null. + * @return the node element. */ - @FXThread - private @Nullable ShaderNodeElement findNodeElementByVariable(@NotNull final ShaderNodeVariable variable) { - return (ShaderNodeElement) root.getChildren().stream() + @FxThread + private @NotNull Optional> findNodeElementByVariable(@NotNull final ShaderNodeVariable variable) { + return root.getChildren().stream() .filter(ShaderNodeElement.class::isInstance) - .map(ShaderNodeElement.class::cast) + .map(sne -> (ShaderNodeElement) sne) .filter(element -> element.getObject().equals(variable)) - .findAny().orElse(null); + .findAny(); } /** * Find a nodes element by the object. * * @param object the object. - * @return the nodes element or null. + * @return the node element. */ - @FXThread - private @Nullable ShaderNodeElement findNodeElementByObject(@NotNull final Object object) { - return (ShaderNodeElement) root.getChildren().stream() + @FxThread + private @NotNull Optional> findNodeElementByObject(@NotNull final Object object) { + return root.getChildren().stream() .filter(ShaderNodeElement.class::isInstance) - .map(ShaderNodeElement.class::cast) + .map(sne -> (ShaderNodeElement) sne) .filter(element -> element.getObject().equals(object)) - .findAny().orElse(null); + .findAny(); } /** @@ -747,13 +760,14 @@ public void show(@NotNull final TechniqueDef techniqueDef) { * @param input true if the variable is input variable. * @return the parameter or null. */ - @FXThread + @FxThread private @Nullable ShaderNodeParameter findByVariable(@NotNull final ShaderNodeVariable variable, - final boolean fromOutputMapping, final boolean input) { + final boolean fromOutputMapping, + final boolean input) { return root.getChildren().stream() .filter(ShaderNodeElement.class::isInstance) .map(ShaderNodeElement.class::cast) - .map(shaderNodeElement -> shaderNodeElement.parameterFor(variable, fromOutputMapping, input)) + .map(sne -> sne.parameterFor(variable, fromOutputMapping, input)) .filter(Objects::nonNull) .findAny().orElse(null); } @@ -764,7 +778,7 @@ public void show(@NotNull final TechniqueDef techniqueDef) { * @param matParam the new material parameter. * @param location the location. */ - @FXThread + @FxThread public void addMatParam(@NotNull final MatParam matParam, @NotNull final Vector2f location) { addNodeElement(MaterialShaderNodeElement.toVariable(matParam), location); } @@ -775,7 +789,7 @@ public void addMatParam(@NotNull final MatParam matParam, @NotNull final Vector2 * @param binding the binding. * @param location the location. */ - @FXThread + @FxThread public void addWorldParam(@NotNull final UniformBinding binding, @NotNull final Vector2f location) { addNodeElement(WorldShaderNodeElement.toVariable(binding), location); } @@ -786,10 +800,11 @@ public void addWorldParam(@NotNull final UniformBinding binding, @NotNull final * @param shaderNode the new shader nodes. * @param location the location. */ - @FXThread + @FxThread public void addShaderNode(@NotNull final ShaderNode shaderNode, @NotNull final Vector2f location) { - final ShaderNodeDefinition definition = shaderNode.getDefinition(); + var definition = shaderNode.getDefinition(); + final MainShaderNodeElement nodeElement; if (definition.getType() == Shader.ShaderType.Vertex) { @@ -809,15 +824,9 @@ public void addShaderNode(@NotNull final ShaderNode shaderNode, @NotNull final V * @param variable the new shader nodes variable. * @param location the location. */ - @FXThread + @FxThread public void addNodeElement(@NotNull final ShaderNodeVariable variable, @NotNull final Vector2f location) { - - final ShaderNodeElement nodeElement = createNodeElement(variable); - if (nodeElement == null) { - return; - } - - addNodeElement(nodeElement, location); + createNodeElement(variable).ifPresent(element -> addNodeElement(element, location)); } /** @@ -826,19 +835,19 @@ public void addNodeElement(@NotNull final ShaderNodeVariable variable, @NotNull * @param nodeElement the new nodes element. * @param location the location. */ - @FXThread + @FxThread private void addNodeElement(@NotNull final ShaderNodeElement nodeElement, @NotNull final Vector2f location) { - final ObservableList children = root.getChildren(); + var children = root.getChildren(); children.add(nodeElement); - final Array> nodeElements = getNodeElements(); + var nodeElements = getNodeElements(); nodeElements.add(nodeElement); refreshLines(); EXECUTOR_MANAGER.schedule(() -> { - EXECUTOR_MANAGER.addFXTask(() -> { + EXECUTOR_MANAGER.addFxTask(() -> { nodeElement.setLayoutX(location.getX()); nodeElement.setLayoutY(location.getY()); }); @@ -850,7 +859,7 @@ private void addNodeElement(@NotNull final ShaderNodeElement nodeElement, @No * * @param matParam the material parameter. */ - @FXThread + @FxThread public void removeMatParam(@NotNull final MatParam matParam) { removeNodeElement(MaterialShaderNodeElement.toVariable(matParam)); } @@ -860,21 +869,31 @@ public void removeMatParam(@NotNull final MatParam matParam) { * * @param binding the world parameter. */ - @FXThread + @FxThread public void removeWorldParam(@NotNull final UniformBinding binding) { removeNodeElement(WorldShaderNodeElement.toVariable(binding)); } /** - * Remove the shader nodes. + * Remove the shader node. * - * @param shaderNode the shader nodes. + * @param shaderNode the shader node. */ - @FXThread + @FxThread public void removeShaderNode(@NotNull final ShaderNode shaderNode) { - final ShaderNodeElement nodeElement = findNodeElementByObject(shaderNode); - if (nodeElement == null) return; - removeNodeElement(nodeElement); + findNodeElementByObject(shaderNode) + .ifPresent(this::removeNodeElement); + } + + /** + * Refresh the shader node. + * + * @param shaderNode the shader node. + */ + @FxThread + public void refreshShaderNode(@NotNull final ShaderNode shaderNode) { + findNodeElementByObject(shaderNode) + .ifPresent(ShaderNodeElement::refresh); } /** @@ -882,15 +901,9 @@ public void removeShaderNode(@NotNull final ShaderNode shaderNode) { * * @param variable the variable. */ - @FXThread + @FxThread public void removeNodeElement(@NotNull final ShaderNodeVariable variable) { - - final ShaderNodeElement nodeElement = findNodeElementByVariable(variable); - if (nodeElement == null) { - return; - } - - removeNodeElement(nodeElement); + findNodeElementByVariable(variable).ifPresent(this::removeNodeElement); } /** @@ -898,7 +911,7 @@ public void removeNodeElement(@NotNull final ShaderNodeVariable variable) { * * @param nodeElement the nodes element. */ - @FXThread + @FxThread private void removeNodeElement(@NotNull final ShaderNodeElement nodeElement) { root.getChildren().remove(nodeElement); getNodeElements().slowRemove(nodeElement); @@ -909,22 +922,11 @@ private void removeNodeElement(@NotNull final ShaderNodeElement nodeElement) * Create a nodes element for the variable. * * @param variable the variable. - * @return the nodes element. + * @return the optional of shader node element. */ - @FXThread - private @Nullable ShaderNodeElement createNodeElement(@NotNull ShaderNodeVariable variable) { - - ShaderNodeElement nodeElement = null; - - final String nameSpace = variable.getNameSpace(); - if (MaterialShaderNodeElement.NAMESPACE.equals(nameSpace)) { - nodeElement = new MaterialShaderNodeElement(this, variable); - } else if (WorldShaderNodeElement.NAMESPACE.equals(nameSpace)) { - nodeElement = new WorldShaderNodeElement(this, variable); - } else if (AttributeShaderNodeElement.NAMESPACE.equals(nameSpace)) { - nodeElement = new AttributeShaderNodeElement(this, variable); - } - return nodeElement; + @FxThread + private @NotNull Optional> createNodeElement(@NotNull final ShaderNodeVariable variable) { + return ShaderNodeUtils.createNodeElement(this, variable); } /** @@ -932,7 +934,7 @@ private void removeNodeElement(@NotNull final ShaderNodeElement nodeElement) * * @return the current technique definition. */ - @FXThread + @FxThread public @NotNull TechniqueDef getTechniqueDef() { return notNull(techniqueDef); } @@ -942,7 +944,7 @@ private void removeNodeElement(@NotNull final ShaderNodeElement nodeElement) * * @return the current material definition. */ - @FXThread + @FxThread public @NotNull MaterialDef getMaterialDef() { return getChangeConsumer().getMaterialDef(); } @@ -950,30 +952,32 @@ private void removeNodeElement(@NotNull final ShaderNodeElement nodeElement) /** * Refresh all lines. */ - @FXThread + @FxThread public void refreshLines() { - final ObservableList children = root.getChildren(); - final List lines = children.stream() + var children = root.getChildren(); + var lines = children.stream() .filter(VariableLine.class::isInstance) .collect(toList()); children.removeAll(lines); - final List shaderNodes = getTechniqueDef().getShaderNodes(); + var shaderNodes = getTechniqueDef().getShaderNodes(); - for (final ShaderNode shaderNode : shaderNodes) { + for (var shaderNode : shaderNodes) { - final List inputMapping = shaderNode.getInputMapping(); - final List outputMapping = shaderNode.getOutputMapping(); + var inputMapping = shaderNode.getInputMapping(); + var outputMapping = shaderNode.getOutputMapping(); buildLines(children, inputMapping, false); buildLines(children, outputMapping, true); } - final List toBack = children.stream() - .filter(VariableLine.class::isInstance) - .collect(toList()); + // we need to copy lines to a separated list, + // because the method Node.toBack modifies the children's list. + var toBack = children.stream() + .filter(VariableLine.class::isInstance) + .collect(toList()); toBack.forEach(Node::toBack); } @@ -985,17 +989,22 @@ public void refreshLines() { * @param mappings the mappings. * @param fromOutputMapping true if it's from output mapping. */ - @FXThread - private void buildLines(@NotNull final ObservableList children, @NotNull final List mappings, + @FxThread + private void buildLines(@NotNull final ObservableList children, + @NotNull final List mappings, final boolean fromOutputMapping) { - for (final VariableMapping variableMapping : mappings) { + for (var variableMapping : mappings) { + + var leftVariable = variableMapping.getLeftVariable(); + var rightVariable = variableMapping.getRightVariable(); - final ShaderNodeVariable leftVariable = variableMapping.getLeftVariable(); - final ShaderNodeVariable rightVariable = variableMapping.getRightVariable(); + if (rightVariable == null) { + continue; + } - final ShaderNodeParameter leftParameter = findByVariable(leftVariable, fromOutputMapping, true); - final ShaderNodeParameter rightParameter = findByVariable(rightVariable, fromOutputMapping, false); + var leftParameter = findByVariable(leftVariable, fromOutputMapping, true); + var rightParameter = findByVariable(rightVariable, fromOutputMapping, false); if (leftParameter == null || rightParameter == null) { LOGGER.warning("not found parameters for " + leftVariable + " and " + rightVariable); @@ -1009,7 +1018,7 @@ private void buildLines(@NotNull final ObservableList children, @NotNull f /** * Update scale value. */ - @FXThread + @FxThread private void updateScale() { root.setScaleX(scaleValue); root.setScaleY(scaleValue); @@ -1020,33 +1029,33 @@ private void updateScale() { * * @param event the scroll event. */ - @FXThread + @FxThread private void handleScrollEvent(@NotNull final ScrollEvent event) { - final double zoomFactor = event.getDeltaY() * ZOOM_INTENSITY; - final double newScale = scaleValue + zoomFactor; + var zoomFactor = event.getDeltaY() * ZOOM_INTENSITY; + var newScale = scaleValue + zoomFactor; - final Region content = (Region) getContent(); - final Point2D positionInRoot = root.sceneToLocal(event.getSceneX(), event.getSceneY()); - final Point2D positionInContent = content.sceneToLocal(root.localToScene(positionInRoot)); + var content = (Region) getContent(); + var positionInRoot = root.sceneToLocal(event.getSceneX(), event.getSceneY()); + var positionInContent = content.sceneToLocal(root.localToScene(positionInRoot)); scaleValue = Math.min(Math.max(newScale, 0.2F), 1F); updateScale(); requestLayout(); layout(); - final Point2D newPositionInContent = content.sceneToLocal(root.localToScene(positionInRoot)); - final Point2D diff = newPositionInContent.subtract(positionInContent); + var newPositionInContent = content.sceneToLocal(root.localToScene(positionInRoot)); + var diff = newPositionInContent.subtract(positionInContent); - final Bounds viewport = getViewportBounds(); - final Bounds contentBounds = content.getLayoutBounds(); + var viewport = getViewportBounds(); + var contentBounds = content.getLayoutBounds(); - final double viewScaleX = viewport.getWidth() / contentBounds.getWidth(); - final double viewScaleY = viewport.getHeight() / contentBounds.getHeight(); - final double viewX = diff.getX() * viewScaleX; - final double viewY = diff.getY() * viewScaleY; - final double newHValue = viewX / viewport.getWidth(); - final double newYValue = viewY / viewport.getHeight(); + var viewScaleX = viewport.getWidth() / contentBounds.getWidth(); + var viewScaleY = viewport.getHeight() / contentBounds.getHeight(); + var viewX = diff.getX() * viewScaleX; + var viewY = diff.getY() * viewScaleY; + var newHValue = viewX / viewport.getWidth(); + var newYValue = viewY / viewport.getHeight(); setHvalue(getHvalue() + newHValue); setVvalue(getVvalue() + newYValue); @@ -1058,7 +1067,7 @@ private void handleScrollEvent(@NotNull final ScrollEvent event) { * * @param nodeElement the nodes element. */ - @FXThread + @FxThread public void notifyMoved(@NotNull final ShaderNodeElement nodeElement) { notifyResized(nodeElement); } @@ -1068,14 +1077,14 @@ public void notifyMoved(@NotNull final ShaderNodeElement nodeElement) { * * @param nodeElement the nodes element. */ - @FXThread + @FxThread public void notifyResized(@NotNull final ShaderNodeElement nodeElement) { - final Object object = nodeElement.getObject(); - final ShaderNodesChangeConsumer consumer = getChangeConsumer(); - final double width = nodeElement.getPrefWidth(); + var object = nodeElement.getObject(); + var consumer = getChangeConsumer(); + var width = nodeElement.getPrefWidth(); - final Vector2f location = new Vector2f((float) nodeElement.getLayoutX(), (float) nodeElement.getLayoutY()); + var location = new Vector2f((float) nodeElement.getLayoutX(), (float) nodeElement.getLayoutY()); if (object instanceof ShaderNode) { consumer.notifyChangeState((ShaderNode) object, location, width); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/ShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/ShaderNodeAction.java index 8414da0..bb3558c 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/ShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/ShaderNodeAction.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.action; import com.jme3.math.Vector2f; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import javafx.scene.control.MenuItem; import javafx.scene.image.Image; @@ -34,8 +34,10 @@ public abstract class ShaderNodeAction extends MenuItem { @NotNull private final Vector2f location; - public ShaderNodeAction(@NotNull final ShaderNodesContainer container, @NotNull final T object, + public ShaderNodeAction(@NotNull final ShaderNodesContainer container, + @NotNull final T object, @NotNull final Vector2f location) { + this.container = container; this.object = object; this.location = location; @@ -43,58 +45,63 @@ public ShaderNodeAction(@NotNull final ShaderNodesContainer container, @NotNull setOnAction(event -> process()); setText(getName()); - final Image icon = getIcon(); - + var icon = getIcon(); if (icon != null) { setGraphic(new ImageView(icon)); } } /** + * Get the location. + * * @return the location. */ - @FXThread + @FxThread public @NotNull Vector2f getLocation() { return location; } /** + * Get the shader nodes container. + * * @return the shader nodes container. */ - @FXThread + @FxThread public @NotNull ShaderNodesContainer getContainer() { return container; } /** + * Get the additional object. + * * @return the additional object. */ - @FXThread + @FxThread public @NotNull T getObject() { return object; } /** - * Gets name. + * Get the name of this action. * * @return the name of this action. */ - @FXThread + @FxThread protected abstract @NotNull String getName(); /** * Execute this action. */ - @FXThread + @FxThread protected void process() { } /** * The icon of this action. * - * @return he icon or null. + * @return the icon or null. */ - @FXThread + @FxThread protected @Nullable Image getIcon() { return null; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddAttributeShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddAttributeShaderNodeAction.java index 5e54723..1c57bce 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddAttributeShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddAttributeShaderNodeAction.java @@ -7,7 +7,7 @@ import com.jme3.math.Vector2f; import com.jme3.scene.VertexBuffer; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.add.AddAttributeOperation; @@ -52,19 +52,19 @@ public AddAttributeShaderNodeAction(@NotNull final ShaderNodesContainer containe } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.VERTEX_ATTRIBUTE; } @Override - @FXThread + @FxThread protected @NotNull String getDialogTitle() { return PluginMessages.ACTION_ADD_VERTEX_ATTRIBUTE_TITLE; } @Override - @FXThread + @FxThread protected void addParameter(@NotNull final VarTable vars) { final ShaderNodesContainer container = getContainer(); @@ -72,7 +72,7 @@ protected void addParameter(@NotNull final VarTable vars) { final TechniqueDef techniqueDef = getObject(); final String name = vars.getString(PROP_NAME); - final String attributeUIType = getAttributeUIType(VertexBuffer.Type.valueOf(name.substring(2, name.length()))); + final String attributeUIType = getAttributeUiType(VertexBuffer.Type.valueOf(name.substring(2, name.length()))); final String glslType = uiTypeToType(attributeUIType); final ShaderNodeVariable variable = new ShaderNodeVariable(glslType, NAMESPACE, name, null, ""); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddMaterialParamShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddMaterialParamShaderNodeAction.java index 81ded75..456f44d 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddMaterialParamShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddMaterialParamShaderNodeAction.java @@ -9,7 +9,7 @@ import com.jme3.math.Vector4f; import com.jme3.shader.VarType; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.plugin.api.dialog.GenericFactoryDialog; import com.ss.editor.plugin.api.property.PropertyDefinition; @@ -48,7 +48,7 @@ public class AddMaterialParamShaderNodeAction extends ShaderNodeAction VAR_TYPES = ArrayFactory.newArray(String.class); + private static final Array VAR_TYPES = ArrayFactory.newArray(String.class); static { for (final VarType varType : VarType.values()) { @@ -65,13 +65,13 @@ public AddMaterialParamShaderNodeAction(@NotNull final ShaderNodesContainer cont } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.MATERIAL_PARAMETER; } @Override - @FXThread + @FxThread protected void process() { super.process(); @@ -87,7 +87,7 @@ protected void process() { * * @return the list of required properties. */ - @FXThread + @FxThread protected @NotNull Array getDefinitions() { final Array varTypes = getVarTypes(); @@ -135,7 +135,7 @@ protected boolean needDefaultValue() { * * @param vars the variables. */ - @FXThread + @FxThread protected void addParam(@NotNull final VarTable vars) { final ShaderNodesContainer container = getContainer(); @@ -191,7 +191,7 @@ protected void addParam(@NotNull final VarTable vars) { * @param vars the variables. * @return true if the values are valid. */ - @FXThread + @FxThread protected boolean validate(@NotNull final VarTable vars) { final String name = vars.getString(PROP_NAME); return getObject().getMaterialParam(name) == null; diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddMaterialTextureShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddMaterialTextureShaderNodeAction.java index 61b1e0f..bc5d2eb 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddMaterialTextureShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddMaterialTextureShaderNodeAction.java @@ -7,7 +7,7 @@ import com.jme3.shader.VarType; import com.jme3.texture.image.ColorSpace; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.plugin.api.property.PropertyDefinition; import com.ss.editor.shader.nodes.PluginMessages; @@ -50,13 +50,13 @@ protected boolean needDefaultValue() { } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.MATERIAL_TEXTURE; } @Override - @FXThread + @FxThread protected @NotNull Array getDefinitions() { final Array definitions = super.getDefinitions(); definitions.add(new PropertyDefinition(ENUM, Messages.MODEL_PROPERTY_COLOR_SPACE, PROP_COLOR_SPACE, ColorSpace.Linear)); @@ -76,7 +76,7 @@ protected boolean needDefaultValue() { } @Override - @FXThread + @FxThread protected void addParam(@NotNull final VarTable vars) { final ShaderNodesContainer container = getContainer(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddNodeShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddNodeShaderNodeAction.java index 8151304..f8c18f5 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddNodeShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddNodeShaderNodeAction.java @@ -8,10 +8,9 @@ import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.Editor; import com.ss.editor.FileExtensions; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.manager.ResourceManager; import com.ss.editor.plugin.api.dialog.GenericFactoryDialog; import com.ss.editor.plugin.api.property.PropertyDefinition; @@ -20,7 +19,8 @@ import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.add.AddShaderNodeOperation; -import com.ss.editor.ui.util.UIUtils; +import com.ss.editor.ui.util.UiUtils; +import com.ss.editor.util.EditorUtil; import com.ss.rlib.util.array.Array; import com.ss.rlib.util.array.ArrayFactory; import org.jetbrains.annotations.NotNull; @@ -34,12 +34,10 @@ */ public class AddNodeShaderNodeAction extends ShaderNodeAction { - @NotNull - private static final ResourceManager RESOURCE_MANAGER = ResourceManager.getInstance(); + public static final String PROP_DEFINITION = "definition"; @NotNull - private static final Editor EDITOR = Editor.getInstance(); - public static final String PROP_DEFINITION = "definition"; + private static final ResourceManager RESOURCE_MANAGER = ResourceManager.getInstance(); public AddNodeShaderNodeAction(@NotNull final ShaderNodesContainer container, @NotNull final TechniqueDef techniqueDef, @NotNull final Vector2f location) { @@ -47,17 +45,17 @@ public AddNodeShaderNodeAction(@NotNull final ShaderNodesContainer container, } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.SHADER_NODE; } @Override - @FXThread + @FxThread protected void process() { super.process(); final Array resources = RESOURCE_MANAGER.getAvailableResources(FileExtensions.JME_SHADER_NODE); - UIUtils.openResourceAssetDialog(this::addNode, resources); + UiUtils.openResourceAssetDialog(this::addNode, resources); } /** @@ -65,13 +63,13 @@ protected void process() { * * @param resource the selected resource. */ - @FXThread + @FxThread private void addNode(@NotNull final String resource) { final ShaderNodeDefinitionKey key = new ShaderNodeDefinitionKey(resource); - key.setLoadDocumentation(false); + key.setLoadDocumentation(true); - final AssetManager assetManager = EDITOR.getAssetManager(); + final AssetManager assetManager = EditorUtil.getAssetManager(); final List definitions = assetManager.loadAsset(key); if (definitions.isEmpty()) { @@ -108,7 +106,7 @@ private void addNode(@NotNull final String resource) { * * @param definition the new definition. */ - @FXThread + @FxThread private void addDefinition(final ShaderNodeDefinition definition) { final TechniqueDef techniqueDef = getObject(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddTechniqueDefParameterShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddTechniqueDefParameterShaderNodeAction.java index fb84f77..3fd101a 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddTechniqueDefParameterShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddTechniqueDefParameterShaderNodeAction.java @@ -4,7 +4,7 @@ import com.jme3.material.TechniqueDef; import com.jme3.math.Vector2f; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.plugin.api.dialog.GenericFactoryDialog; import com.ss.editor.plugin.api.property.PropertyDefinition; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; @@ -45,7 +45,7 @@ public AddTechniqueDefParameterShaderNodeAction(@NotNull final ShaderNodesContai } @Override - @FXThread + @FxThread protected void process() { super.process(); @@ -62,7 +62,7 @@ protected void process() { * * @return the dialog title. */ - @FXThread + @FxThread protected @NotNull String getDialogTitle() { throw new RuntimeException("unsupported"); } @@ -73,7 +73,7 @@ protected void process() { * @param vars the variables. * @return true if the values are valid. */ - @FXThread + @FxThread protected boolean validate(@NotNull final VarTable vars) { return available.contains(vars.getString(PROP_NAME)); } @@ -83,6 +83,6 @@ protected boolean validate(@NotNull final VarTable vars) { * * @param vars the variables. */ - @FXThread + @FxThread protected abstract void addParameter(@NotNull final VarTable vars); } \ No newline at end of file diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddWorldParamShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddWorldParamShaderNodeAction.java index 699d041..87fcbc8 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddWorldParamShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/add/AddWorldParamShaderNodeAction.java @@ -3,7 +3,7 @@ import com.jme3.material.TechniqueDef; import com.jme3.math.Vector2f; import com.jme3.shader.UniformBinding; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.add.AddWorldParameterOperation; @@ -43,19 +43,19 @@ public AddWorldParamShaderNodeAction(@NotNull final ShaderNodesContainer contain } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.WORLD_PARAMETER; } @Override - @FXThread + @FxThread protected @NotNull String getDialogTitle() { return PluginMessages.ACTION_ADD_WORLD_PARAMETER_TITLE; } @Override - @FXThread + @FxThread protected void addParameter(@NotNull final VarTable vars) { final ShaderNodesContainer container = getContainer(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveAttributeShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveAttributeShaderNodeAction.java index a5aa8de..be804b4 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveAttributeShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveAttributeShaderNodeAction.java @@ -5,7 +5,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.MainShaderNodeElement; @@ -29,23 +29,22 @@ public RemoveAttributeShaderNodeAction(@NotNull final ShaderNodesContainer conta } @Override - @FXThread + @FxThread protected @NotNull String getName() { return Messages.MODEL_NODE_TREE_ACTION_REMOVE; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final ShaderNodesContainer container = getContainer(); - final TechniqueDef techniqueDef = container.getTechniqueDef(); - final ShaderNodeVariable variable = getObject(); + var container = getContainer(); + var techniqueDef = container.getTechniqueDef(); + var variable = getObject(); + var usingNodes = container.findWithRightInputVar(variable, MainShaderNodeElement.class); - final List usingNodes = container.findWithRightInputVar(variable, MainShaderNodeElement.class); - - final ShaderNodesChangeConsumer consumer = container.getChangeConsumer(); - consumer.execute(new RemoveAttributeVariableOperation(usingNodes, techniqueDef, variable, getLocation())); + container.getChangeConsumer() + .execute(new RemoveAttributeVariableOperation(usingNodes, techniqueDef, variable, getLocation())); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveMaterialParamShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveMaterialParamShaderNodeAction.java index a3a4678..0e895b9 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveMaterialParamShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveMaterialParamShaderNodeAction.java @@ -7,7 +7,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.MainShaderNodeElement; @@ -31,26 +31,26 @@ public RemoveMaterialParamShaderNodeAction(@NotNull final ShaderNodesContainer c } @Override - @FXThread + @FxThread protected @NotNull String getName() { return Messages.MODEL_NODE_TREE_ACTION_REMOVE; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final ShaderNodesContainer container = getContainer(); - final MaterialDef materialDef = container.getMaterialDef(); - final TechniqueDef techniqueDef = container.getTechniqueDef(); - final ShaderNodeVariable variable = getObject(); - final MatParam matParam = materialDef.getMaterialParam(variable.getName()); + var container = getContainer(); + var materialDef = container.getMaterialDef(); + var techniqueDef = container.getTechniqueDef(); + var variable = getObject(); + var matParam = materialDef.getMaterialParam(variable.getName()); - final List usingNodes = container.findWithRightInputVar(variable, MainShaderNodeElement.class); + var usingNodes = container.findWithRightInputVar(variable, MainShaderNodeElement.class); - final ShaderNodesChangeConsumer consumer = container.getChangeConsumer(); - consumer.execute(new RemoveMaterialParameterVariableOperation(usingNodes, materialDef, techniqueDef, + container.getChangeConsumer() + .execute(new RemoveMaterialParameterVariableOperation(usingNodes, materialDef, techniqueDef, matParam, variable, getLocation())); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveRelationShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveRelationShaderNodeAction.java index 7ac2788..0275b9a 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveRelationShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveRelationShaderNodeAction.java @@ -7,7 +7,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.VariableMapping; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; @@ -28,43 +28,44 @@ public class RemoveRelationShaderNodeAction extends ShaderNodeAction { public RemoveRelationShaderNodeAction(@NotNull final ShaderNodesContainer container, - @NotNull final VariableLine variableLine, @NotNull final Vector2f location) { + @NotNull final VariableLine variableLine, + @NotNull final Vector2f location) { super(container, variableLine, location); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return Messages.MODEL_NODE_TREE_ACTION_REMOVE; } @Override - @FXThread - protected void process() { + @FxThread + public void process() { super.process(); - final ShaderNodesContainer container = getContainer(); - final VariableLine variableLine = getObject(); + var container = getContainer(); + var variableLine = getObject(); - final ShaderNodeParameter inParameter = variableLine.getInParameter(); - final ShaderNodeElement nodeElement = inParameter.getNodeElement(); + var inParameter = variableLine.getInParameter(); + var nodeElement = inParameter.getNodeElement(); - final ShaderNodeParameter outParameter = variableLine.getOutParameter(); - final ShaderNodeElement outNodeElement = outParameter.getNodeElement(); + var outParameter = variableLine.getOutParameter(); + var outNodeElement = outParameter.getNodeElement(); - final ShaderNodesChangeConsumer consumer = container.getChangeConsumer(); + var consumer = container.getChangeConsumer(); if (nodeElement instanceof OutputGlobalShaderNodeElement && outNodeElement instanceof MainShaderNodeElement) { - final ShaderNode shaderNode = ((MainShaderNodeElement) outNodeElement).getObject(); - final VariableMapping mapping = notNull(findOutMappingByNNLeftVar(shaderNode, inParameter.getVariable())); + var shaderNode = ((MainShaderNodeElement) outNodeElement).getObject(); + var mapping = notNull(findOutMappingByNNLeftVar(shaderNode, inParameter.getVariable())); consumer.execute(new OutputDetachShaderNodeOperation(shaderNode, mapping)); } else if (nodeElement instanceof MainShaderNodeElement) { - final ShaderNode shaderNode = ((MainShaderNodeElement) nodeElement).getObject(); - final VariableMapping mapping = notNull(findInMappingByNNLeftVar(shaderNode, + var shaderNode = ((MainShaderNodeElement) nodeElement).getObject(); + var mapping = notNull(findInMappingByNNLeftVar(shaderNode, inParameter.getVariable(), shaderNode.getName())); consumer.execute(new InputDetachShaderNodeOperation(shaderNode, mapping)); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveShaderNodeAction.java index cec95d7..04af47a 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveShaderNodeAction.java @@ -1,22 +1,17 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.action.remove; -import com.jme3.material.TechniqueDef; import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNode; -import com.jme3.shader.ShaderNodeDefinition; -import com.jme3.shader.ShaderNodeVariable; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.MainShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.remove.RemoveShaderNodeOperation; -import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import com.ss.rlib.util.Utils; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.List; /** * The action to delete an old world param. @@ -25,38 +20,38 @@ */ public class RemoveShaderNodeAction extends ShaderNodeAction { - public RemoveShaderNodeAction(@NotNull final ShaderNodesContainer container, @NotNull final ShaderNode shaderNode, + public RemoveShaderNodeAction(@NotNull final ShaderNodesContainer container, + @NotNull final ShaderNode shaderNode, @NotNull final Vector2f location) { super(container, shaderNode, location); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return Messages.MODEL_NODE_TREE_ACTION_REMOVE; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final ShaderNodesContainer container = getContainer(); - final TechniqueDef techniqueDef = container.getTechniqueDef(); - final ShaderNode shaderNode = getObject(); + var container = getContainer(); + var techniqueDef = container.getTechniqueDef(); + var shaderNode = getObject(); + var usingNodes = new ArrayList(); - final List usingNodes = new ArrayList<>(); + var definition = shaderNode.getDefinition(); + var outputs = definition.getOutputs(); - final ShaderNodeDefinition definition = shaderNode.getDefinition(); - final List outputs = definition.getOutputs(); - - for (final ShaderNodeVariable outVar : outputs) { - final ShaderNodeVariable toFind = Utils.get(outVar::clone); + for (var outVar : outputs) { + var toFind = Utils.get(outVar::clone); toFind.setNameSpace(shaderNode.getName()); usingNodes.addAll(container.findWithRightInputVar(toFind, MainShaderNodeElement.class)); } - final ShaderNodesChangeConsumer consumer = container.getChangeConsumer(); - consumer.execute(new RemoveShaderNodeOperation(usingNodes, techniqueDef, shaderNode, getLocation())); + container.getChangeConsumer() + .execute(new RemoveShaderNodeOperation(usingNodes, techniqueDef, shaderNode, getLocation())); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveWorldParamShaderNodeAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveWorldParamShaderNodeAction.java index faa8b68..bb781aa 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveWorldParamShaderNodeAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/action/remove/RemoveWorldParamShaderNodeAction.java @@ -6,7 +6,7 @@ import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.UniformBinding; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.MainShaderNodeElement; @@ -30,25 +30,24 @@ public RemoveWorldParamShaderNodeAction(@NotNull final ShaderNodesContainer cont } @Override - @FXThread + @FxThread protected @NotNull String getName() { return Messages.MODEL_NODE_TREE_ACTION_REMOVE; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final ShaderNodesContainer container = getContainer(); - final TechniqueDef techniqueDef = container.getTechniqueDef(); - final ShaderNodeVariable variable = getObject(); - final UniformBinding binding = UniformBinding.valueOf(variable.getName()); + var container = getContainer(); + var techniqueDef = container.getTechniqueDef(); + var variable = getObject(); + var binding = UniformBinding.valueOf(variable.getName()); + var usingNodes = container.findWithRightInputVar(variable, MainShaderNodeElement.class); - final List usingNodes = container.findWithRightInputVar(variable, MainShaderNodeElement.class); - - final ShaderNodesChangeConsumer consumer = container.getChangeConsumer(); - consumer.execute(new RemoveWorldParameterVariableOperation(usingNodes, techniqueDef, + container.getChangeConsumer() + .execute(new RemoveWorldParameterVariableOperation(usingNodes, techniqueDef, binding, variable, getLocation())); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/GlobalShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/GlobalShaderNodeElement.java index a6b5e38..de71910 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/GlobalShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/GlobalShaderNodeElement.java @@ -2,7 +2,7 @@ import com.jme3.material.ShaderGenerationInfo; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; @@ -24,10 +24,14 @@ public GlobalShaderNodeElement(@NotNull final ShaderNodesContainer container, @N } @Override - @FXThread + @FxThread public @Nullable ShaderNodeParameter parameterFor(@NotNull final ShaderNodeVariable variable, final boolean fromOutputMapping, final boolean input) { - if (!NAMESPACE.equals(variable.getNameSpace())) return null; + + if (!NAMESPACE.equals(variable.getNameSpace())) { + return null; + } + return super.parameterFor(variable, fromOutputMapping, input); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/InputGlobalShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/InputGlobalShaderNodeElement.java index ebf90f1..29c8029 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/InputGlobalShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/InputGlobalShaderNodeElement.java @@ -2,7 +2,7 @@ import com.jme3.material.ShaderGenerationInfo; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.OutputShaderNodeParameter; @@ -26,21 +26,25 @@ public InputGlobalShaderNodeElement(@NotNull final ShaderNodesContainer containe } @Override - @FXThread + @FxThread protected @NotNull String getTitleText() { return PluginMessages.NODE_ELEMENT_GLOBAL_INPUT; } @Override - @FXThread + @FxThread public @Nullable ShaderNodeParameter parameterFor(final @NotNull ShaderNodeVariable variable, final boolean fromOutputMapping, final boolean input) { - if (fromOutputMapping) return null; + + if (fromOutputMapping) { + return null; + } + return super.parameterFor(variable, fromOutputMapping, input); } @Override - @FXThread + @FxThread protected void fillParameters(@NotNull final VBox container) { super.fillParameters(container); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/OutputGlobalShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/OutputGlobalShaderNodeElement.java index bc5e699..e1698b8 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/OutputGlobalShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/global/OutputGlobalShaderNodeElement.java @@ -6,7 +6,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; @@ -38,13 +38,13 @@ public OutputGlobalShaderNodeElement(@NotNull final ShaderNodesContainer contain } @Override - @FXThread + @FxThread protected @NotNull String getTitleText() { return PluginMessages.NODE_ELEMENT_GLOBAL_OUTPUT; } @Override - @FXThread + @FxThread public @Nullable ShaderNodeParameter parameterFor(final @NotNull ShaderNodeVariable variable, final boolean fromOutputMapping, final boolean input) { if (!fromOutputMapping) return null; @@ -52,7 +52,7 @@ public OutputGlobalShaderNodeElement(@NotNull final ShaderNodesContainer contain } @Override - @FXThread + @FxThread protected void fillParameters(@NotNull final VBox container) { super.fillParameters(container); @@ -68,7 +68,7 @@ protected void fillParameters(@NotNull final VBox container) { } @Override - @FXThread + @FxThread public boolean canAttach(@NotNull final InputShaderNodeParameter inputParameter, @NotNull final OutputShaderNodeParameter outputParameter) { @@ -89,7 +89,7 @@ public boolean canAttach(@NotNull final InputShaderNodeParameter inputParameter, } @Override - @FXThread + @FxThread public void attach(@NotNull final InputShaderNodeParameter inputParameter, @NotNull final OutputShaderNodeParameter outputParameter) { super.attach(inputParameter, outputParameter); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/line/TempLine.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/line/TempLine.java index bb38898..b548948 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/line/TempLine.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/line/TempLine.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.line; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_TEMP_LINE; -import com.ss.editor.annotation.FXThread; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_TEMP_LINE; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.SocketElement; import javafx.scene.shape.CubicCurve; import javafx.scene.shape.StrokeLineCap; @@ -26,7 +26,7 @@ public TempLine(@NotNull final SocketElement sourceSocket) { /** * Configure the line. */ - @FXThread + @FxThread private void configureLine() { startXProperty().bind(sourceSocket.centerXPropertyProperty()); startYProperty().bind(sourceSocket.centerYPropertyProperty()); @@ -44,7 +44,7 @@ private void configureLine() { * @param x the X coord. * @param y the Y coord. */ - @FXThread + @FxThread public void updateEnd(final double x, final double y) { setEndX(x); setEndY(y); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/line/VariableLine.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/line/VariableLine.java index c42179a..fb44566 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/line/VariableLine.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/line/VariableLine.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.line; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_LINE; -import com.ss.editor.annotation.FXThread; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_LINE; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; @@ -18,9 +18,15 @@ */ public class VariableLine extends CubicCurve { + /** + * The output parameter. + */ @NotNull private final ShaderNodeParameter outParameter; + /** + * The imput parameter. + */ @NotNull private final ShaderNodeParameter inParameter; @@ -38,10 +44,10 @@ public VariableLine(@NotNull final ShaderNodeParameter outParameter, * * @param event the menu requested event. */ - @FXThread + @FxThread private void handleContextMenuRequested(@NotNull final ContextMenuEvent event) { - final ShaderNodeElement nodeElement = inParameter.getNodeElement(); - final ShaderNodesContainer container = nodeElement.getContainer(); + var nodeElement = inParameter.getNodeElement(); + var container = nodeElement.getContainer(); container.handleContextMenuEvent(event); event.consume(); } @@ -51,7 +57,7 @@ private void handleContextMenuRequested(@NotNull final ContextMenuEvent event) { * * @return the input parameter. */ - @FXThread + @FxThread public @NotNull ShaderNodeParameter getInParameter() { return inParameter; } @@ -61,7 +67,7 @@ private void handleContextMenuRequested(@NotNull final ContextMenuEvent event) { * * @return the output parameter. */ - @FXThread + @FxThread public @NotNull ShaderNodeParameter getOutParameter() { return outParameter; } @@ -69,11 +75,11 @@ private void handleContextMenuRequested(@NotNull final ContextMenuEvent event) { /** * Configure the line. */ - @FXThread + @FxThread private void configureLine() { - final SocketElement outSocket = outParameter.getSocket(); - final SocketElement inSocket = inParameter.getSocket(); + var outSocket = outParameter.getSocket(); + var inSocket = inParameter.getSocket(); startXProperty().bind(outSocket.centerXPropertyProperty()); startYProperty().bind(outSocket.centerYPropertyProperty()); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/AttributeShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/AttributeShaderNodeElement.java index 417b94c..b7ea9f2 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/AttributeShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/AttributeShaderNodeElement.java @@ -2,7 +2,7 @@ import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; @@ -26,19 +26,19 @@ public AttributeShaderNodeElement(@NotNull final ShaderNodesContainer container, } @Override - @FXThread + @FxThread protected @NotNull String getTitleText() { return PluginMessages.NODE_ELEMENT_VERTEX_ATTRIBUTE; } @Override - @FXThread + @FxThread protected @NotNull String getNameSpace() { return NAMESPACE; } @Override - @FXThread + @FxThread public @Nullable ShaderNodeAction getDeleteAction() { return new RemoveAttributeShaderNodeAction(getContainer(), getObject(), new Vector2f((float) getLayoutX(), (float) getLayoutY())); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/FragmentShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/FragmentShaderNodeElement.java index 6de68a2..7696060 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/FragmentShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/FragmentShaderNodeElement.java @@ -2,7 +2,7 @@ import com.jme3.material.ShaderGenerationInfo; import com.jme3.shader.ShaderNode; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.global.InputGlobalShaderNodeElement; @@ -22,7 +22,7 @@ public FragmentShaderNodeElement(@NotNull final ShaderNodesContainer container, } @Override - @FXThread + @FxThread public boolean canAttach(@NotNull final InputShaderNodeParameter inputParameter, @NotNull final OutputShaderNodeParameter outputParameter) { diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/MainShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/MainShaderNodeElement.java index f2df7e4..b9968ec 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/MainShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/MainShaderNodeElement.java @@ -1,10 +1,10 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.main; import static com.ss.editor.shader.nodes.util.ShaderNodeUtils.*; -import com.jme3.material.TechniqueDef; + import com.jme3.math.Vector2f; import com.jme3.shader.*; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; @@ -17,14 +17,15 @@ import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.InputShaderNodeParameter; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.OutputShaderNodeParameter; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; -import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.tooltip.SndDocumentationTooltip; import com.ss.rlib.ui.util.FXUtils; import com.ss.rlib.util.StringUtils; +import javafx.scene.control.Tooltip; import javafx.scene.layout.VBox; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; +import java.util.Optional; /** * The implementation of shader element to present shader nodes. @@ -38,18 +39,24 @@ public MainShaderNodeElement(@NotNull final ShaderNodesContainer container, @Not } @Override - @FXThread + @FxThread protected @NotNull String getTitleText() { return getObject().getDefinition().getName(); } + @Override + @FxThread + protected @NotNull Optional createTooltip() { + return Optional.of(new SndDocumentationTooltip(getObject().getDefinition())); + } - @FXThread + @FxThread @Override public @Nullable ShaderNodeParameter parameterFor(@NotNull final ShaderNodeVariable variable, - final boolean fromOutputMapping, final boolean input) { + final boolean fromOutputMapping, + final boolean input) { - final ShaderNode shaderNode = getObject(); + var shaderNode = getObject(); if (!shaderNode.getName().equals(variable.getNameSpace())) { return null; } @@ -57,39 +64,47 @@ public MainShaderNodeElement(@NotNull final ShaderNodesContainer container, @Not return super.parameterFor(variable, fromOutputMapping, input); } - @FXThread + @FxThread @Override protected void fillParameters(@NotNull final VBox container) { super.fillParameters(container); - final ShaderNode shaderNode = getObject(); - final ShaderNodeDefinition definition = shaderNode.getDefinition(); - final List inputs = definition.getInputs(); - final List outputs = definition.getOutputs(); + var shaderNode = getObject(); + var definition = shaderNode.getDefinition(); + var inputs = definition.getInputs(); + var outputs = definition.getOutputs(); - for (final ShaderNodeVariable variable : inputs) { + for (var variable : inputs) { FXUtils.addToPane(new InputShaderNodeParameter(this, variable), container); } - for (final ShaderNodeVariable variable : outputs) { + for (var variable : outputs) { FXUtils.addToPane(new OutputShaderNodeParameter(this, variable), container); } } @Override - @FXThread + public boolean canAttach(@NotNull final InputShaderNodeParameter inputParameter, + @NotNull final OutputShaderNodeParameter outputParameter) { + + return !inputParameter.isUsedExpression() && + super.canAttach(inputParameter, outputParameter); + } + + @Override + @FxThread public void attach(@NotNull final InputShaderNodeParameter inputParameter, @NotNull final OutputShaderNodeParameter outputParameter) { - super.attach(inputParameter, outputParameter); - final ShaderNodeElement nodeElement = outputParameter.getNodeElement(); + super.attach(inputParameter, outputParameter); - final ShaderNodeVariable inVar = inputParameter.getVariable(); - final ShaderNodeVariable outVar = outputParameter.getVariable(); - final ShaderNode shaderNode = getObject(); + var nodeElement = outputParameter.getNodeElement(); + var inVar = inputParameter.getVariable(); + var outVar = outputParameter.getVariable(); + var shaderNode = getObject(); + var currentMapping = findInMappingByNLeftVar(shaderNode, inVar); - final VariableMapping currentMapping = findInMappingByNLeftVar(shaderNode, inVar); - final VariableMapping newMapping = makeMapping(inputParameter, outputParameter); + var newMapping = makeMapping(inputParameter, outputParameter); newMapping.setRightSwizzling(calculateRightSwizzling(inVar, outVar)); if (StringUtils.isEmpty(newMapping.getRightSwizzling())) { @@ -100,7 +115,7 @@ public void attach(@NotNull final InputShaderNodeParameter inputParameter, return; } - final ShaderNodesChangeConsumer changeConsumer = getContainer().getChangeConsumer(); + final var changeConsumer = getContainer().getChangeConsumer(); if (nodeElement instanceof InputGlobalShaderNodeElement) { changeConsumer.execute(new AttachGlobalToShaderNodeOperation(shaderNode, newMapping, currentMapping)); @@ -109,26 +124,27 @@ public void attach(@NotNull final InputShaderNodeParameter inputParameter, return; } - final ShaderNodesContainer container = nodeElement.getContainer(); - final TechniqueDef techniqueDef = container.getTechniqueDef(); + var container = nodeElement.getContainer(); + var techniqueDef = container.getTechniqueDef(); if (nodeElement instanceof MainShaderNodeElement) { - final ShaderNode outShaderNode = ((MainShaderNodeElement) nodeElement).getObject(); + var outShaderNode = ((MainShaderNodeElement) nodeElement).getObject(); changeConsumer.execute(new AttachVarToShaderNodeOperation(shaderNode, newMapping, - currentMapping, techniqueDef, outShaderNode)); + currentMapping, techniqueDef, outShaderNode)); } else if (nodeElement instanceof MaterialShaderNodeElement || nodeElement instanceof WorldShaderNodeElement) { - final Shader.ShaderType type = shaderNode.getDefinition().getType(); + var type = shaderNode.getDefinition().getType(); if (type == Shader.ShaderType.Vertex) { - final List fragmentNodes = container.findWithRightInputVar(newMapping.getLeftVariable(), - FragmentShaderNodeElement.class); + var fragmentNodes = container.findWithRightInputVar(newMapping.getLeftVariable(), + FragmentShaderNodeElement.class); - newMapping.getLeftVariable().setShaderOutput(!fragmentNodes.isEmpty()); + newMapping.getLeftVariable() + .setShaderOutput(!fragmentNodes.isEmpty()); } changeConsumer.execute(new AttachUniformToShaderNodeOperation(shaderNode, outVar, techniqueDef, @@ -137,7 +153,7 @@ public void attach(@NotNull final InputShaderNodeParameter inputParameter, } @Override - @FXThread + @FxThread public @Nullable ShaderNodeAction getDeleteAction() { return new RemoveShaderNodeAction(getContainer(), getObject(), new Vector2f((float) getLayoutX(), (float) getLayoutY())); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/MaterialShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/MaterialShaderNodeElement.java index a1dcb10..76012fc 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/MaterialShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/MaterialShaderNodeElement.java @@ -9,17 +9,17 @@ import com.jme3.math.Vector4f; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.VarType; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.PluginMessages; +import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.remove.RemoveMaterialParamShaderNodeAction; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.EditableMaterialShaderNodeParameter; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.OutputShaderNodeParameter; -import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import com.ss.editor.ui.control.property.PropertyControl; import com.ss.editor.ui.control.property.impl.*; import org.jetbrains.annotations.NotNull; @@ -42,29 +42,28 @@ public class MaterialShaderNodeElement extends OutputVariableShaderNodeElement { * @return the shader nodes variable. */ @FromAnyThread - public static @NotNull ShaderNodeVariable toVariable(@NotNull final MatParam matParam) { - final VarType type = matParam.getVarType(); - final String glslType = type.getGlslType(); - final String resultType = glslType.contains("|") ? glslType.split("[|]")[0] : glslType; + public static @NotNull ShaderNodeVariable toVariable(@NotNull MatParam matParam) { + var type = matParam.getVarType(); + var glslType = type.getGlslType(); + var resultType = glslType.contains("|") ? glslType.split("[|]")[0] : glslType; return new ShaderNodeVariable(resultType, NAMESPACE, matParam.getName(), null, "m_"); } - public MaterialShaderNodeElement(@NotNull final ShaderNodesContainer container, - @NotNull final ShaderNodeVariable variable) { + public MaterialShaderNodeElement(@NotNull ShaderNodesContainer container, @NotNull ShaderNodeVariable variable) { super(container, variable); } @Override - @FXThread + @FxThread protected @NotNull OutputShaderNodeParameter newParameter() { - final ShaderNodeVariable variable = getObject(); - final ShaderNodesContainer container = getContainer(); - final MaterialDef materialDef = container.getMaterialDef(); - final MatParam materialParam = materialDef.getMaterialParam(variable.getName()); + var variable = getObject(); + var container = getContainer(); + var materialDef = container.getMaterialDef(); + var materialParam = materialDef.getMaterialParam(variable.getName()); - final PropertyControl control = buildControl(container.getChangeConsumer(), materialParam); + var control = buildControl(container.getChangeConsumer(), materialParam); if (control == null) { return super.newParameter(); } @@ -88,18 +87,19 @@ public MaterialShaderNodeElement(@NotNull final ShaderNodesContainer container, /** * Notify about changed preview material. */ - @FXThread + @FxThread public void notifyChangedMaterial() { getParametersContainer().getChildren().stream() .filter(EditableMaterialShaderNodeParameter.class::isInstance) .map(EditableMaterialShaderNodeParameter.class::cast) - .forEach(EditableMaterialShaderNodeParameter::sync); + .forEach(EditableMaterialShaderNodeParameter::requestLayout); } - @FXThread - private @Nullable PropertyControl buildControl(@NotNull final ChangeConsumer consumer, - @NotNull final MatParam param) { - + @FxThread + private @Nullable PropertyControl buildControl( + @NotNull ChangeConsumer consumer, + @NotNull MatParam param + ) { switch (param.getVarType()) { case Boolean: { @@ -138,33 +138,32 @@ public void notifyChangedMaterial() { return null; } - @FXThread - private T getCurrentValue(@NotNull final MatParam matParam) { - - final ShaderNodesChangeConsumer changeConsumer = getContainer().getChangeConsumer(); - final Material material = changeConsumer.getPreviewMaterial(); + @FxThread + private T getCurrentValue(@NotNull MatParam matParam) { + var changeConsumer = getContainer().getChangeConsumer(); + var material = changeConsumer.getPreviewMaterial(); if (material == null) { return null; } - final MatParam param = material.getParam(matParam.getName()); - final T value = param == null ? null : unsafeCast(param.getValue()); + var param = material.getParam(matParam.getName()); + T value = param == null ? null : unsafeCast(param.getValue()); if (value instanceof Vector4f) { - final Vector4f vector4f = (Vector4f) value; - return unsafeCast(new ColorRGBA(vector4f.getX(), vector4f.getY(), vector4f.getZ(), vector4f.getW())); + var vector4f = (Vector4f) value; + return unsafeCast(new ColorRGBA(vector4f.getX(), vector4f.getY(), + vector4f.getZ(), vector4f.getW())); } return value; } - @JMEThread - private void applyValue(@NotNull final MatParam matParam, @Nullable T value) { - - final ShaderNodesChangeConsumer changeConsumer = getContainer().getChangeConsumer(); - final Material material = changeConsumer.getPreviewMaterial(); + @JmeThread + private void applyValue(@NotNull MatParam matParam, @Nullable T value) { + var changeConsumer = getContainer().getChangeConsumer(); + var material = changeConsumer.getPreviewMaterial(); if (material == null) { return; } @@ -177,19 +176,19 @@ private void applyValue(@NotNull final MatParam matParam, @Nullable T value) } @Override - @FXThread + @FxThread protected @NotNull String getTitleText() { return PluginMessages.NODE_ELEMENT_MATERIAL_PARAMETER; } @Override - @FXThread + @FxThread protected @NotNull String getNameSpace() { return NAMESPACE; } @Override - @FXThread + @FxThread public @Nullable ShaderNodeAction getDeleteAction() { return new RemoveMaterialParamShaderNodeAction(getContainer(), getObject(), new Vector2f((float) getLayoutX(), (float) getLayoutY())); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/OutputVariableShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/OutputVariableShaderNodeElement.java index b92f54f..3c406a9 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/OutputVariableShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/OutputVariableShaderNodeElement.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.main; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.OutputShaderNodeParameter; import com.ss.rlib.ui.util.FXUtils; @@ -21,7 +21,7 @@ public OutputVariableShaderNodeElement(@NotNull final ShaderNodesContainer conta } @Override - @FXThread + @FxThread protected void fillParameters(@NotNull final VBox container) { super.fillParameters(container); FXUtils.addToPane(newParameter(), container); @@ -32,7 +32,7 @@ protected void fillParameters(@NotNull final VBox container) { * * @return the output parameter. */ - @FXThread + @FxThread protected @NotNull OutputShaderNodeParameter newParameter() { return new OutputShaderNodeParameter(this, getObject()); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/VariableShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/VariableShaderNodeElement.java index 7e14527..46de34e 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/VariableShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/VariableShaderNodeElement.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.main; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; @@ -20,11 +20,15 @@ public VariableShaderNodeElement(@NotNull final ShaderNodesContainer container, super(container, variable); } - @FXThread + @FxThread @Override public @Nullable ShaderNodeParameter parameterFor(@NotNull final ShaderNodeVariable variable, final boolean fromOutputMapping, final boolean input) { - if (!getNameSpace().equals(variable.getNameSpace())) return null; + + if (!getNameSpace().equals(variable.getNameSpace())) { + return null; + } + return super.parameterFor(variable, fromOutputMapping, input); } @@ -33,7 +37,7 @@ public VariableShaderNodeElement(@NotNull final ShaderNodesContainer container, * * @return the namespace. */ - @FXThread + @FxThread protected @NotNull String getNameSpace() { return "unknown"; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/VertexShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/VertexShaderNodeElement.java index 5245083..e21d50e 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/VertexShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/VertexShaderNodeElement.java @@ -2,7 +2,7 @@ import com.jme3.material.ShaderGenerationInfo; import com.jme3.shader.ShaderNode; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.global.InputGlobalShaderNodeElement; @@ -22,7 +22,7 @@ public VertexShaderNodeElement(@NotNull final ShaderNodesContainer container, @N } @Override - @FXThread + @FxThread public boolean canAttach(@NotNull final InputShaderNodeParameter inputParameter, @NotNull final OutputShaderNodeParameter outputParameter) { diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/WorldShaderNodeElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/WorldShaderNodeElement.java index 144f8ec..3d2e9d3 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/WorldShaderNodeElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/main/WorldShaderNodeElement.java @@ -3,7 +3,7 @@ import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.UniformBinding; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.action.ShaderNodeAction; @@ -38,19 +38,19 @@ public WorldShaderNodeElement(@NotNull final ShaderNodesContainer container, } @Override - @FXThread + @FxThread protected @NotNull String getTitleText() { return PluginMessages.NODE_ELEMENT_WORLD_PARAMETER; } @Override - @FXThread + @FxThread protected @NotNull String getNameSpace() { return NAMESPACE; } @Override - @FXThread + @FxThread public @Nullable ShaderNodeAction getDeleteAction() { return new RemoveWorldParamShaderNodeAction(getContainer(), getObject(), new Vector2f((float) getLayoutX(), (float) getLayoutY())); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/ChangeLightModeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/ChangeLightModeOperation.java index 1f9d17c..fc7fc3f 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/ChangeLightModeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/ChangeLightModeOperation.java @@ -4,7 +4,7 @@ import com.jme3.material.TechniqueDef; import com.jme3.material.logic.*; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,9 +39,9 @@ public ChangeLightModeOperation(@NotNull final String techniqueName, } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); final MaterialDef materialDef = editor.getMaterialDef(); final List techniqueDefs = materialDef.getTechniqueDefs(techniqueName); @@ -55,13 +55,13 @@ protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer edito createLogic(techniqueDef); - editor.notifyFXChangeProperty(techniqueDef, Messages.MODEL_PROPERTY_LIGHT_MODE); + editor.notifyFxChangeProperty(techniqueDef, Messages.MODEL_PROPERTY_LIGHT_MODE); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); final MaterialDef materialDef = editor.getMaterialDef(); final List techniqueDefs = materialDef.getTechniqueDefs(techniqueName); @@ -75,7 +75,7 @@ protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer edito createLogic(techniqueDef); - editor.notifyFXChangeProperty(techniqueDef, Messages.MODEL_PROPERTY_LIGHT_MODE); + editor.notifyFxChangeProperty(techniqueDef, Messages.MODEL_PROPERTY_LIGHT_MODE); } /** @@ -83,7 +83,7 @@ protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer edito * * @param techniqueDef the technique def. */ - @FXThread + @FxThread private void createLogic(@NotNull final TechniqueDef techniqueDef) { switch (techniqueDef.getLightMode()) { case SinglePass: { diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/ShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/ShaderNodeOperation.java index 58fba92..f0af465 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/ShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/ShaderNodeOperation.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.operation; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -14,40 +14,40 @@ public class ShaderNodeOperation extends AbstractEditorOperation { @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ShaderNodesChangeConsumer editor) { - EXECUTOR_MANAGER.addJMETask(() -> { - redoImplInJMEThread(editor); - EXECUTOR_MANAGER.addFXTask(() -> redoImplInFXThread(editor)); + EXECUTOR_MANAGER.addJmeTask(() -> { + redoImplInJmeThread(editor); + EXECUTOR_MANAGER.addFxTask(() -> redoImplInFxThread(editor)); }); } - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { } - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ShaderNodesChangeConsumer editor) { - EXECUTOR_MANAGER.addJMETask(() -> { - undoImplInJMEThread(editor); - EXECUTOR_MANAGER.addFXTask(() -> undoImplInFXThread(editor)); + EXECUTOR_MANAGER.addJmeTask(() -> { + undoImplInJmeThread(editor); + EXECUTOR_MANAGER.addFxTask(() -> undoImplInFxThread(editor)); }); } - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { } - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddAttributeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddAttributeOperation.java index 41520c9..09b41a8 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddAttributeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddAttributeOperation.java @@ -4,8 +4,8 @@ import com.jme3.material.TechniqueDef; import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.ShaderNodeOperation; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -45,34 +45,34 @@ public AddAttributeOperation(@NotNull final TechniqueDef techniqueDef, @NotNull } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); final List attributes = generationInfo.getAttributes(); attributes.add(variable); } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyAddedAttribute(variable, location); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); final List attributes = generationInfo.getAttributes(); attributes.remove(variable); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyRemovedAttribute(variable); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddMaterialParameterOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddMaterialParameterOperation.java index da38a49..1c25f6d 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddMaterialParameterOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddMaterialParameterOperation.java @@ -4,8 +4,8 @@ import com.jme3.material.MatParam; import com.jme3.material.MaterialDef; import com.jme3.math.Vector2f; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.ShaderNodeOperation; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -45,35 +45,35 @@ public AddMaterialParameterOperation(@NotNull final MaterialDef materialDef, @No } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final Map matParams = getMatParams(materialDef); matParams.put(matParam.getName(), matParam); } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyAddedMatParameter(matParam, location); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final Map matParams = getMatParams(materialDef); matParams.remove(matParam.getName()); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyRemovedMatParameter(matParam); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddShaderNodeOperation.java index fba8bab..40c3155 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddShaderNodeOperation.java @@ -5,8 +5,8 @@ import com.jme3.math.Vector2f; import com.jme3.shader.Shader; import com.jme3.shader.ShaderNode; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.ShaderNodeOperation; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -54,9 +54,9 @@ public AddShaderNodeOperation(@NotNull final TechniqueDef techniqueDef, @NotNull } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final List shaderNodes = techniqueDef.getShaderNodes(); previousShaderNodes = new ArrayList<>(shaderNodes); @@ -83,16 +83,16 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyAddedShaderNode(shaderNode, location); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final List shaderNodes = techniqueDef.getShaderNodes(); shaderNodes.clear(); shaderNodes.addAll(previousShaderNodes); @@ -100,9 +100,9 @@ protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyRemovedRemovedShaderNode(shaderNode); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddTechniqueOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddTechniqueOperation.java index ac1e237..e1160d1 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddTechniqueOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddTechniqueOperation.java @@ -2,8 +2,8 @@ import com.jme3.material.MaterialDef; import com.jme3.material.TechniqueDef; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.ShaderNodeOperation; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -35,32 +35,32 @@ public AddTechniqueOperation(@NotNull final MaterialDef materialDef, @NotNull fi } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); materialDef.addTechniqueDef(techniqueDef); } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyAddedTechnique(techniqueDef); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final List techniqueDefs = materialDef.getTechniqueDefs(techniqueDef.getName()); techniqueDefs.remove(techniqueDef); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyRemovedTechnique(techniqueDef); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddWorldParameterOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddWorldParameterOperation.java index b2829f7..a734723 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddWorldParameterOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/add/AddWorldParameterOperation.java @@ -3,8 +3,8 @@ import com.jme3.material.TechniqueDef; import com.jme3.math.Vector2f; import com.jme3.shader.UniformBinding; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.ShaderNodeOperation; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -42,30 +42,30 @@ public AddWorldParameterOperation(@NotNull final TechniqueDef techniqueDef, @Not } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); techniqueDef.getWorldBindings().add(binding); } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyAddedWorldParameter(binding, location); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); techniqueDef.getWorldBindings().remove(binding); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyRemovedWorldParameter(binding); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachAttributeToShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachAttributeToShaderNodeOperation.java index 15382d6..58c892e 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachAttributeToShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachAttributeToShaderNodeOperation.java @@ -2,7 +2,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,9 +23,9 @@ public AttachAttributeToShaderNodeOperation(@NotNull final ShaderNode shaderNode } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final List inputMapping = getShaderNode().getInputMapping(); @@ -39,9 +39,9 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final List inputMapping = getShaderNode().getInputMapping(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachGlobalToShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachGlobalToShaderNodeOperation.java index 7681689..400101a 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachGlobalToShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachGlobalToShaderNodeOperation.java @@ -2,7 +2,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,9 +23,9 @@ public AttachGlobalToShaderNodeOperation(@NotNull final ShaderNode shaderNode, } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final List inputMapping = getShaderNode().getInputMapping(); @@ -39,9 +39,9 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final List inputMapping = getShaderNode().getInputMapping(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachShaderNodeOperation.java index cfcc415..3473921 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachShaderNodeOperation.java @@ -2,10 +2,10 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; -import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.ShaderNodeOperation; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.ShaderNodeOperation; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,9 +34,11 @@ public class AttachShaderNodeOperation extends ShaderNodeOperation { @Nullable private final VariableMapping oldMapping; - protected AttachShaderNodeOperation(@NotNull final ShaderNode shaderNode, - @Nullable final VariableMapping newMapping, - @Nullable final VariableMapping oldMapping) { + protected AttachShaderNodeOperation( + @NotNull final ShaderNode shaderNode, + @Nullable final VariableMapping newMapping, + @Nullable final VariableMapping oldMapping + ) { this.shaderNode = shaderNode; this.newMapping = newMapping; this.oldMapping = oldMapping; @@ -73,23 +75,25 @@ protected AttachShaderNodeOperation(@NotNull final ShaderNode shaderNode, } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); notify(editor, oldMapping, newMapping); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); notify(editor, newMapping, oldMapping); } - @FXThread - protected void notify(@NotNull final ShaderNodesChangeConsumer editor, @Nullable final VariableMapping oldMapping, - @Nullable final VariableMapping newMapping) { - + @FxThread + protected void notify( + @NotNull final ShaderNodesChangeConsumer editor, + @Nullable final VariableMapping oldMapping, + @Nullable final VariableMapping newMapping + ) { if (oldMapping != null && newMapping != null) { editor.notifyReplacedMapping(shaderNode, oldMapping, newMapping); } else if (oldMapping != null) { diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachUniformToShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachUniformToShaderNodeOperation.java index 2abbf1c..bc9f6df 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachUniformToShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachUniformToShaderNodeOperation.java @@ -6,7 +6,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,9 +48,9 @@ public AttachUniformToShaderNodeOperation(@NotNull final ShaderNode shaderNode, } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final ShaderNode shaderNode = getShaderNode(); final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); @@ -79,9 +79,9 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final ShaderNode shaderNode = getShaderNode(); final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarExpressionToShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarExpressionToShaderNodeOperation.java new file mode 100644 index 0000000..5d7be5c --- /dev/null +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarExpressionToShaderNodeOperation.java @@ -0,0 +1,59 @@ +package com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.attach; + +import com.jme3.shader.ShaderNode; +import com.jme3.shader.VariableMapping; +import com.ss.editor.annotation.JmeThread; +import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The implementation of attaching a variable to a shader nodes. + * + * @author JavaSaBr + */ +public class AttachVarExpressionToShaderNodeOperation extends AttachShaderNodeOperation { + + public AttachVarExpressionToShaderNodeOperation( + @NotNull final ShaderNode shaderNode, + @Nullable final VariableMapping newMapping, + @Nullable final VariableMapping oldMapping + ) { + super(shaderNode, newMapping, oldMapping); + } + + @Override + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); + + var shaderNode = getShaderNode(); + var newMapping = getNewMapping(); + var inputMapping = shaderNode.getInputMapping(); + + if (getOldMapping() != null) { + inputMapping.remove(getOldMapping()); + } + + if (newMapping != null) { + inputMapping.add(newMapping); + } + } + + @Override + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); + + var newMapping = getNewMapping(); + var inputMapping = getShaderNode().getInputMapping(); + + if (newMapping != null) { + inputMapping.remove(newMapping); + } + + if (getOldMapping() != null) { + inputMapping.add(getOldMapping()); + } + } +} diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarToGlobalNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarToGlobalNodeOperation.java index 9b6997b..f6f5dc4 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarToGlobalNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarToGlobalNodeOperation.java @@ -7,7 +7,7 @@ import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.VariableMapping; import com.ss.editor.annotation.FromAnyThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -69,9 +69,9 @@ public AttachVarToGlobalNodeOperation(@NotNull final TechniqueDef techniqueDef, } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final List outputMapping = getShaderNode().getOutputMapping(); final TechniqueDef techniqueDef = getTechniqueDef(); @@ -143,9 +143,9 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final TechniqueDef techniqueDef = getTechniqueDef(); final ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarToShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarToShaderNodeOperation.java index 1ba8ffa..3b4e1bf 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarToShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/attach/AttachVarToShaderNodeOperation.java @@ -8,7 +8,7 @@ import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.VariableMapping; import com.ss.editor.annotation.FromAnyThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -57,34 +57,36 @@ public class AttachVarToShaderNodeOperation extends AttachShaderNodeOperation { */ private boolean outShaderWasUnused; - public AttachVarToShaderNodeOperation(@NotNull final ShaderNode shaderNode, - @Nullable final VariableMapping newMapping, - @Nullable final VariableMapping oldMapping, - @NotNull final TechniqueDef techniqueDef, - @NotNull final ShaderNode outShaderNode) { + public AttachVarToShaderNodeOperation( + @NotNull final ShaderNode shaderNode, + @Nullable final VariableMapping newMapping, + @Nullable final VariableMapping oldMapping, + @NotNull final TechniqueDef techniqueDef, + @NotNull final ShaderNode outShaderNode + ) { super(shaderNode, newMapping, oldMapping); this.techniqueDef = techniqueDef; this.outShaderNode = outShaderNode; } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); - final ShaderNode shaderNode = getShaderNode(); - final Shader.ShaderType inType = shaderNode.getDefinition().getType(); + var shaderNode = getShaderNode(); + var inType = shaderNode.getDefinition().getType(); - final ShaderNode outShaderNode = getOutShaderNode(); - final Shader.ShaderType outType = outShaderNode.getDefinition().getType(); + var outShaderNode = getOutShaderNode(); + var outType = outShaderNode.getDefinition().getType(); - final VariableMapping newMapping = getNewMapping(); - final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); + var newMapping = getNewMapping(); + var generationInfo = techniqueDef.getShaderGenerationInfo(); if (newMapping != null && outType == Shader.ShaderType.Vertex && inType != Shader.ShaderType.Vertex) { - final List varyings = generationInfo.getVaryings(); - final ShaderNodeVariable rightVar = newMapping.getRightVariable(); + var varyings = generationInfo.getVaryings(); + var rightVar = newMapping.getRightVariable(); if (!varyings.contains(rightVar)) { varyings.add(rightVar); @@ -97,9 +99,9 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit toRevertOutput.getLeftVariable().setShaderOutput(true); } - final List shaderNodes = techniqueDef.getShaderNodes(); - final int outSnIndex = shaderNodes.indexOf(outShaderNode); - final int snIndex = shaderNodes.indexOf(shaderNode); + var shaderNodes = techniqueDef.getShaderNodes(); + var outSnIndex = shaderNodes.indexOf(outShaderNode); + var snIndex = shaderNodes.indexOf(shaderNode); if (outSnIndex > snIndex) { previousShaderOrder = new ArrayList<>(shaderNodes); @@ -107,13 +109,13 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit shaderNodes.add(snIndex, outShaderNode); } - final List unusedNodes = generationInfo.getUnusedNodes(); + var unusedNodes = generationInfo.getUnusedNodes(); if (unusedNodes.contains(outShaderNode.getName())) { unusedNodes.remove(outShaderNode.getName()); outShaderWasUnused = true; } - final List inputMapping = shaderNode.getInputMapping(); + var inputMapping = shaderNode.getInputMapping(); if (getOldMapping() != null) { inputMapping.remove(getOldMapping()); @@ -125,15 +127,15 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); - final VariableMapping newMapping = getNewMapping(); - final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); + var newMapping = getNewMapping(); + var generationInfo = techniqueDef.getShaderGenerationInfo(); if (newMapping != null && wasAddedToVaryings) { - final List varyings = generationInfo.getVaryings(); + var varyings = generationInfo.getVaryings(); varyings.remove(newMapping.getRightVariable()); wasAddedToVaryings = false; } @@ -144,20 +146,19 @@ protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } if (previousShaderOrder != null) { - final List shaderNodes = techniqueDef.getShaderNodes(); + var shaderNodes = techniqueDef.getShaderNodes(); shaderNodes.clear(); shaderNodes.addAll(previousShaderOrder); previousShaderOrder = null; } if (outShaderWasUnused) { - final List unusedNodes = generationInfo.getUnusedNodes(); + var unusedNodes = generationInfo.getUnusedNodes(); unusedNodes.add(outShaderNode.getName()); outShaderWasUnused = false; } - final List inputMapping = getShaderNode().getInputMapping(); - + var inputMapping = getShaderNode().getInputMapping(); if (newMapping != null) { inputMapping.remove(newMapping); } @@ -168,7 +169,9 @@ protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } /** - * @return the output shader nodes. + * Get the output shader node. + * + * @return the output shader node. */ @FromAnyThread private @NotNull ShaderNode getOutShaderNode() { diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/DetachShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/DetachShaderNodeOperation.java index 22f1863..4cdd24e 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/DetachShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/DetachShaderNodeOperation.java @@ -2,9 +2,9 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.ShaderNodeOperation; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -58,16 +58,16 @@ protected DetachShaderNodeOperation(@NotNull final ShaderNode shaderNode, } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); getMappings().remove(oldMapping); } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyRemovedMapping(shaderNode, oldMapping); } @@ -76,22 +76,22 @@ protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer edito * * @return the mapping list. */ - @JMEThread + @JmeThread protected @NotNull List getMappings() { throw new RuntimeException(); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); getMappings().add(oldMapping); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyAddedMapping(shaderNode, oldMapping); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/InputDetachShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/InputDetachShaderNodeOperation.java index b0a583c..f944876 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/InputDetachShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/InputDetachShaderNodeOperation.java @@ -2,7 +2,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -20,7 +20,7 @@ public InputDetachShaderNodeOperation(@NotNull final ShaderNode shaderNode, } @Override - @JMEThread + @JmeThread protected @NotNull List getMappings() { return getShaderNode().getInputMapping(); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/OutputDetachShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/OutputDetachShaderNodeOperation.java index 91bf3b8..42b500f 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/OutputDetachShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/detach/OutputDetachShaderNodeOperation.java @@ -2,7 +2,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -20,7 +20,7 @@ public OutputDetachShaderNodeOperation(@NotNull final ShaderNode shaderNode, } @Override - @JMEThread + @JmeThread protected @NotNull List getMappings() { return getShaderNode().getOutputMapping(); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveAttributeVariableOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveAttributeVariableOperation.java index 5d2fb69..ad5d06c 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveAttributeVariableOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveAttributeVariableOperation.java @@ -5,8 +5,8 @@ import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -26,34 +26,34 @@ public RemoveAttributeVariableOperation(@NotNull final List shaderNo } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); info.getAttributes().remove(variable); } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyRemovedAttribute(variable); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); info.getAttributes().add(variable); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyAddedAttribute(variable, location); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveMaterialParameterVariableOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveMaterialParameterVariableOperation.java index 19fed38..32e7834 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveMaterialParameterVariableOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveMaterialParameterVariableOperation.java @@ -7,8 +7,8 @@ import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -45,34 +45,34 @@ public RemoveMaterialParameterVariableOperation(@NotNull final List } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final Map matParams = getMatParams(materialDef); matParams.remove(matParam.getName()); } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyRemovedMatParameter(matParam); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final Map matParams = getMatParams(materialDef); matParams.put(matParam.getName(), matParam); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyAddedMatParameter(matParam, location); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveShaderNodeOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveShaderNodeOperation.java index 2f91534..ba39731 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveShaderNodeOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveShaderNodeOperation.java @@ -7,8 +7,8 @@ import com.jme3.shader.ShaderNodeDefinition; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -41,9 +41,9 @@ public RemoveShaderNodeOperation(@NotNull final List shaderNodes, @N } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); for (final ShaderNode otherNode : shaderNodes) { @@ -67,16 +67,16 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyRemovedRemovedShaderNode(shaderNode); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); for (final Map.Entry> entry : toRestore.entrySet()) { final ShaderNode shaderNode = entry.getKey(); @@ -90,9 +90,9 @@ protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyAddedShaderNode(shaderNode, location); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveUniformVariableOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveUniformVariableOperation.java index 622f890..2c8bef2 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveUniformVariableOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveUniformVariableOperation.java @@ -5,7 +5,7 @@ import com.jme3.math.Vector2f; import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,9 +38,9 @@ public RemoveUniformVariableOperation(@NotNull final List shaderNode } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); final ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); final List vertexUniforms = info.getVertexUniforms(); @@ -56,9 +56,9 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); final ShaderGenerationInfo info = techniqueDef.getShaderGenerationInfo(); final List vertexUniforms = info.getVertexUniforms(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveVariableOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveVariableOperation.java index 18da95c..6fe56ea 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveVariableOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveVariableOperation.java @@ -6,7 +6,7 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.VariableMapping; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -33,9 +33,9 @@ public RemoveVariableOperation(@NotNull final List shaderNodes, @Not } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); for (final ShaderNode shaderNode : shaderNodes) { final List mappings = findInMappingsByNNRightVar(shaderNode, variable); @@ -47,9 +47,9 @@ protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer edit } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); for (final Map.Entry> entry : toRestore.entrySet()) { final ShaderNode shaderNode = entry.getKey(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveWorldParameterVariableOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveWorldParameterVariableOperation.java index bf76c06..be8a7b7 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveWorldParameterVariableOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/operation/remove/RemoveWorldParameterVariableOperation.java @@ -5,8 +5,8 @@ import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; import com.jme3.shader.UniformBinding; -import com.ss.editor.annotation.FXThread; -import com.ss.editor.annotation.JMEThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.annotation.JmeThread; import com.ss.editor.shader.nodes.ui.component.editor.ShaderNodesChangeConsumer; import org.jetbrains.annotations.NotNull; @@ -34,30 +34,30 @@ public RemoveWorldParameterVariableOperation(@NotNull final List sha } @Override - @JMEThread - protected void redoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInJMEThread(editor); + @JmeThread + protected void redoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInJmeThread(editor); techniqueDef.getWorldBindings().remove(binding); } @Override - @FXThread - protected void redoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.redoImplInFXThread(editor); + @FxThread + protected void redoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.redoImplInFxThread(editor); editor.notifyRemovedWorldParameter(binding); } @Override - @JMEThread - protected void undoImplInJMEThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInJMEThread(editor); + @JmeThread + protected void undoImplInJmeThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInJmeThread(editor); techniqueDef.getWorldBindings().add(binding); } @Override - @FXThread - protected void undoImplInFXThread(@NotNull final ShaderNodesChangeConsumer editor) { - super.undoImplInFXThread(editor); + @FxThread + protected void undoImplInFxThread(@NotNull final ShaderNodesChangeConsumer editor) { + super.undoImplInFxThread(editor); editor.notifyAddedWorldParameter(binding, location); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/EditableMaterialShaderNodeParameter.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/EditableMaterialShaderNodeParameter.java index 6dfd6be..dcb1667 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/EditableMaterialShaderNodeParameter.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/EditableMaterialShaderNodeParameter.java @@ -1,9 +1,9 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_MATERIAL_OUTPUT_PARAMETER; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_MATERIAL_OUTPUT_PARAMETER; import com.jme3.material.MatParam; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.MaterialShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.OutputSocketElement; @@ -25,35 +25,37 @@ public class EditableMaterialShaderNodeParameter extends OutputShaderNodeParamet @NotNull private final PropertyControl propertyControl; - public EditableMaterialShaderNodeParameter(@NotNull final MaterialShaderNodeElement nodeElement, - @NotNull final ShaderNodeVariable variable, - @NotNull final PropertyControl propertyControl) { + public EditableMaterialShaderNodeParameter( + @NotNull MaterialShaderNodeElement nodeElement, + @NotNull ShaderNodeVariable variable, + @NotNull PropertyControl propertyControl + ) { super(nodeElement, variable); this.propertyControl = propertyControl; propertyControl.prefWidthProperty().bind(widthProperty()); - FXUtils.addToPane(propertyControl, this); - FXUtils.addToPane(getSocket(), this); + add(propertyControl, 0, 0); + add(getSocket(), 1, 0); + FXUtils.addClassTo(this, SHADER_NODE_MATERIAL_OUTPUT_PARAMETER); + refresh(); } - /** - * Sync the current value of this parameter. - */ - @FXThread - public void sync() { + @Override + public void refresh() { + super.refresh(); propertyControl.sync(); } @Override - @FXThread + @FxThread protected @NotNull SocketElement createSocket() { return new OutputSocketElement(this); } @Override - @FXThread + @FxThread protected void createContent() { } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/InputShaderNodeParameter.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/InputShaderNodeParameter.java index 88e3623..4cb7f37 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/InputShaderNodeParameter.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/InputShaderNodeParameter.java @@ -1,13 +1,30 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_INPUT_PARAMETER; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_INPUT_PARAMETER; +import static com.ss.editor.shader.nodes.util.ShaderNodeUtils.*; +import static com.ss.rlib.util.ObjectUtils.notNull; + +import com.jme3.shader.ShaderNode; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.shader.nodes.PluginMessages; +import com.ss.editor.shader.nodes.ui.PluginCssClasses; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.operation.attach.AttachVarExpressionToShaderNodeOperation; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.InputSocketElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.SocketElement; +import com.ss.editor.ui.css.CssClasses; import com.ss.rlib.ui.util.FXUtils; +import com.ss.rlib.util.StringUtils; +import javafx.event.ActionEvent; +import javafx.scene.control.CheckBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.layout.HBox; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * The implementation of input shader nodes parameter. @@ -16,24 +33,203 @@ */ public class InputShaderNodeParameter extends ShaderNodeParameter { - public InputShaderNodeParameter(@NotNull final ShaderNodeElement nodeElement, - @NotNull final ShaderNodeVariable variable) { + /** + * The check box to use expression. + */ + @Nullable + private CheckBox useExpression; + + /** + * The label to use an expression. + */ + @Nullable + private Label useExpressionLabel; + + /** + * The field with expression. + */ + @Nullable + private TextField expressionField; + + public InputShaderNodeParameter(@NotNull ShaderNodeElement nodeElement, @NotNull ShaderNodeVariable variable) { super(nodeElement, variable); FXUtils.addClassTo(this, SHADER_NODE_INPUT_PARAMETER); } + /** + * Get the checkbox of using expression. + * + * @return the checkbox of using expression. + */ + @FxThread + protected @NotNull CheckBox getUseExpression() { + return notNull(useExpression); + } + + /** + * Get the use expression label. + * + * @return the use expression label. + */ + @FxThread + protected @NotNull Label getUseExpressionLabel() { + return notNull(useExpressionLabel); + } + + /** + * Get the expression field. + * + * @return the expression field. + */ + @FxThread + protected @NotNull TextField getExpressionField() { + return notNull(expressionField); + } + @Override - @FXThread + @FxThread protected @NotNull SocketElement createSocket() { return new InputSocketElement(this); } + /** + * Return true if this parameter uses expression. + * + * @return true if this parameter uses expression. + */ + @FxThread + public boolean isUsedExpression() { + return getUseExpression().isSelected(); + } + @Override - @FXThread + @FxThread protected void createContent() { super.createContent(); - FXUtils.addToPane(getSocket(), this); - FXUtils.addToPane(getNameLabel(), this); - FXUtils.addToPane(getTypeLabel(), this); + + if (canUseExpression(getNodeElement(), getVariable())) { + + var element = getNodeElement(); + var shaderNode = (ShaderNode) element.getObject(); + var mapping = findInMappingByNLeftVar(shaderNode, getVariable()); + var selected = mapping != null && mapping.getRightExpression() != null; + var expression = mapping != null ? mapping.getRightExpression() : ""; + + useExpressionLabel = new Label(PluginMessages.NODE_ELEMENT_USE_EXPRESSION + ":"); + useExpression = new CheckBox(); + useExpression.setOnAction(this::handleChangeUseExpression); + useExpression.setSelected(selected); + expressionField = new TextField(expression); + expressionField.prefWidthProperty().bind(widthProperty()); + expressionField.setOnKeyReleased(this::handleChangeExpression); + expressionField.focusedProperty() + .addListener((observable, oldValue, newValue) -> handleChangeExpression(null)); + + var parameterContainer = new HBox(getSocket(), getNameLabel(), getTypeLabel()); + parameterContainer.prefWidthProperty().bind(widthProperty()); + + getSocket().disableProperty().bind(useExpression.selectedProperty()); + + var expressionContainer = new HBox(expressionField); + expressionContainer.managedProperty().bind(useExpression.selectedProperty()); + expressionContainer.visibleProperty().bind(useExpression.selectedProperty()); + expressionContainer.prefWidthProperty().bind(widthProperty()); + + add(parameterContainer, 0, 0); + add(getUseExpressionLabel(), 1, 0); + add(getUseExpression(), 2, 0); + add(expressionContainer, 0, 1, 3, 1); + + FXUtils.addClassTo(useExpressionLabel, PluginCssClasses.SHADER_NODE_INPUT_PARAMETER_EXPR_LABEL); + FXUtils.addClassTo(parameterContainer, PluginCssClasses.SHADER_NODE_INPUT_PARAMETER_CONTAINER); + FXUtils.addClassTo(expressionContainer, CssClasses.DEF_HBOX); + + } else { + add(getSocket(), 0, 0); + add(getNameLabel(), 1, 0); + add(getTypeLabel(), 2, 0); + } + } + + /** + * Handle of changing expression. + * + * @param event the key event or null. + */ + @FxThread + private void handleChangeExpression(@Nullable KeyEvent event) { + + if (isDisable() || event != null && event.getCode() != KeyCode.ENTER) { + return; + } + + var element = getNodeElement(); + var shaderNode = (ShaderNode) element.getObject(); + var container = element.getContainer(); + var expressionField = getExpressionField(); + var expr = expressionField.getText(); + var mapping = findInMappingByNLeftVar(shaderNode, getVariable()); + + if (mapping == null && StringUtils.isEmpty(expr)) { + return; + } else if (mapping != null && StringUtils.equals(expr, mapping.getRightExpression())) { + return; + } + + var newMapping = makeExpressionMapping(this, expr); + + container.getChangeConsumer() + .execute(new AttachVarExpressionToShaderNodeOperation(shaderNode, newMapping, mapping)); + + setDisable(true); + } + + @Override + public void refresh() { + super.refresh(); + + var element = getNodeElement(); + var object = element.getObject(); + + if (object instanceof ShaderNode) { + + var shaderNode = (ShaderNode) element.getObject(); + var mapping = findInMappingByNLeftVar(shaderNode, getVariable()); + var selected = mapping != null && mapping.getRightExpression() != null; + + getUseExpression().setSelected(selected); + + if (mapping != null) { + getExpressionField().setText(mapping.getRightExpression()); + } + } + + setDisable(false); + } + + /** + * Handle of using expression. + * + * @param event the action event. + */ + @FxThread + private void handleChangeUseExpression(@NotNull ActionEvent event) { + + var element = getNodeElement(); + var shaderNode = (ShaderNode) element.getObject(); + var useExpression = getUseExpression(); + var container = element.getContainer(); + var mapping = findInMappingByNLeftVar(shaderNode, getVariable()); + var expression = getExpressionField().getText(); + expression = expression == null ? "" : expression; + + if (useExpression.isSelected()) { + var newMapping = makeExpressionMapping(this, expression); + container.getChangeConsumer() + .execute(new AttachVarExpressionToShaderNodeOperation(shaderNode, newMapping, mapping)); + } else { + container.getChangeConsumer() + .execute(new AttachVarExpressionToShaderNodeOperation(shaderNode, null, mapping)); + } } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/OutputShaderNodeParameter.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/OutputShaderNodeParameter.java index 206abb3..257443b 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/OutputShaderNodeParameter.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/OutputShaderNodeParameter.java @@ -1,8 +1,8 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_OUTPUT_PARAMETER; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_OUTPUT_PARAMETER; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.OutputSocketElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.SocketElement; @@ -16,25 +16,23 @@ */ public class OutputShaderNodeParameter extends ShaderNodeParameter { - public OutputShaderNodeParameter(@NotNull final ShaderNodeElement nodeElement, - @NotNull final ShaderNodeVariable variable) { + public OutputShaderNodeParameter(@NotNull ShaderNodeElement nodeElement, @NotNull ShaderNodeVariable variable) { super(nodeElement, variable); FXUtils.addClassTo(this, SHADER_NODE_OUTPUT_PARAMETER); } @Override - @FXThread + @FxThread protected @NotNull SocketElement createSocket() { return new OutputSocketElement(this); } @Override - @FXThread + @FxThread protected void createContent() { super.createContent(); - - FXUtils.addToPane(getTypeLabel(), this); - FXUtils.addToPane(getNameLabel(), this); - FXUtils.addToPane(getSocket(), this); + add(getTypeLabel(), 0, 0); + add(getNameLabel(), 1, 0); + add(getSocket(), 2, 0); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/ShaderNodeParameter.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/ShaderNodeParameter.java index bc8a62b..ee01fc3 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/ShaderNodeParameter.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/ShaderNodeParameter.java @@ -1,14 +1,14 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_PARAMETER; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_PARAMETER_SOCKET; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_PARAMETER; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_PARAMETER_SOCKET; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket.SocketElement; import com.ss.rlib.ui.util.FXUtils; import javafx.scene.control.Label; -import javafx.scene.layout.HBox; +import javafx.scene.layout.GridPane; import org.jetbrains.annotations.NotNull; /** @@ -16,7 +16,7 @@ * * @author JavaSaBr */ -public class ShaderNodeParameter extends HBox { +public class ShaderNodeParameter extends GridPane { /** * The shader nodes element. @@ -48,8 +48,7 @@ public class ShaderNodeParameter extends HBox { @NotNull private final Label typeLabel; - public ShaderNodeParameter(@NotNull final ShaderNodeElement nodeElement, - @NotNull final ShaderNodeVariable variable) { + public ShaderNodeParameter(@NotNull ShaderNodeElement nodeElement, @NotNull ShaderNodeVariable variable) { this.nodeElement = nodeElement; this.variable = variable; this.socket = createSocket(); @@ -60,12 +59,19 @@ public ShaderNodeParameter(@NotNull final ShaderNodeElement nodeElement, FXUtils.addClassTo(socket, SHADER_NODE_PARAMETER_SOCKET); } + /** + * Refresh this parameter. + */ + @FxThread + public void refresh() { + } + /** * Get the shader nodes element. * * @return the shader nodes element. */ - @FXThread + @FxThread public @NotNull ShaderNodeElement getNodeElement() { return nodeElement; } @@ -75,39 +81,47 @@ public ShaderNodeParameter(@NotNull final ShaderNodeElement nodeElement, * * @return the socket element. */ - @FXThread + @FxThread protected @NotNull SocketElement createSocket() { return new SocketElement(this); } /** + * Get the type label. + * * @return the type label. */ - @FXThread + @FxThread protected @NotNull Label getTypeLabel() { return typeLabel; } /** + * Get the name label. + * * @return the name label. */ - @FXThread + @FxThread protected @NotNull Label getNameLabel() { return nameLabel; } /** + * Get the socket. + * * @return the socket. */ - @FXThread + @FxThread public @NotNull SocketElement getSocket() { return socket; } /** + * Get the variable. + * * @return the variable. */ - @FXThread + @FxThread public @NotNull ShaderNodeVariable getVariable() { return variable; } @@ -115,15 +129,10 @@ public ShaderNodeParameter(@NotNull final ShaderNodeElement nodeElement, /** * Create content of this parameter. */ - @FXThread + @FxThread protected void createContent() { - - final ShaderNodeVariable variable = getVariable(); - - final Label nameLabel = getNameLabel(); - nameLabel.setText(variable.getName()); - - final Label typeLabel = getTypeLabel(); - typeLabel.setText(variable.getType()); + var variable = getVariable(); + getNameLabel().setText(variable.getName()); + getTypeLabel().setText(variable.getType()); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/InputSocketElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/InputSocketElement.java index c1f11b4..de76c14 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/InputSocketElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/InputSocketElement.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_PARAMETER_INPUT_SOCKET; -import com.ss.editor.annotation.FXThread; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_PARAMETER_INPUT_SOCKET; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.InputShaderNodeParameter; @@ -74,7 +74,7 @@ public String getName() { } }; - public InputSocketElement(@NotNull final ShaderNodeParameter parameter) { + public InputSocketElement(@NotNull ShaderNodeParameter parameter) { super(parameter); setOnDragOver(this::handleDragOver); setOnDragDropped(this::handleDragDropped); @@ -88,8 +88,8 @@ public InputSocketElement(@NotNull final ShaderNodeParameter parameter) { * * @param dragEvent the drag event. */ - @FXThread - private void handleDragExited(@NotNull final DragEvent dragEvent) { + @FxThread + private void handleDragExited(@NotNull DragEvent dragEvent) { droppable.setValue(false); } @@ -98,20 +98,20 @@ private void handleDragExited(@NotNull final DragEvent dragEvent) { * * @param dragEvent the drag event. */ - @FXThread - private void handleDragDropped(@NotNull final DragEvent dragEvent) { + @FxThread + private void handleDragDropped(@NotNull DragEvent dragEvent) { droppable.setValue(false); - final InputShaderNodeParameter parameter = (InputShaderNodeParameter) getParameter(); - final ShaderNodeElement nodeElement = parameter.getNodeElement(); + var parameter = (InputShaderNodeParameter) getParameter(); + var nodeElement = parameter.getNodeElement(); - final Object gestureSource = dragEvent.getGestureSource(); + var gestureSource = dragEvent.getGestureSource(); if (!(gestureSource instanceof SocketElement)) { return; } - final SocketElement outputSocket = (SocketElement) gestureSource; - final OutputShaderNodeParameter outputParameter = (OutputShaderNodeParameter) outputSocket.getParameter(); + var outputSocket = (SocketElement) gestureSource; + var outputParameter = (OutputShaderNodeParameter) outputSocket.getParameter(); if (!nodeElement.canAttach(parameter, outputParameter)) { return; @@ -125,25 +125,26 @@ private void handleDragDropped(@NotNull final DragEvent dragEvent) { * * @param dragEvent the drag event. */ - @FXThread - private void handleDragOver(@NotNull final DragEvent dragEvent) { + @FxThread + private void handleDragOver(@NotNull DragEvent dragEvent) { - final InputShaderNodeParameter parameter = (InputShaderNodeParameter) getParameter(); - final ShaderNodeElement nodeElement = parameter.getNodeElement(); - final ShaderNodesContainer container = nodeElement.getContainer(); + var parameter = (InputShaderNodeParameter) getParameter(); + var nodeElement = parameter.getNodeElement(); + var container = nodeElement.getContainer(); container.updateAttaching(dragEvent.getSceneX(), dragEvent.getSceneY()); - final Object gestureSource = dragEvent.getGestureSource(); + var gestureSource = dragEvent.getGestureSource(); if (!(gestureSource instanceof SocketElement)) { return; } - final SocketElement outputSocket = (SocketElement) gestureSource; + var outputSocket = (SocketElement) gestureSource; if (!nodeElement.canAttach(parameter, (OutputShaderNodeParameter) outputSocket.getParameter())) { return; } - final Point2D scene = localToScene(getWidth() / 2, getHeight() / 2); + var scene = localToScene(getWidth() / 2, getHeight() / 2); + container.updateAttaching(scene.getX(), scene.getY()); dragEvent.acceptTransferModes(TransferMode.MOVE); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/OutputSocketElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/OutputSocketElement.java index 37eacef..95b2d74 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/OutputSocketElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/OutputSocketElement.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket; -import static com.ss.editor.shader.nodes.ui.PluginCSSClasses.SHADER_NODE_PARAMETER_OUTPUT_SOCKET; -import com.ss.editor.annotation.FXThread; +import static com.ss.editor.shader.nodes.ui.PluginCssClasses.SHADER_NODE_PARAMETER_OUTPUT_SOCKET; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; @@ -48,7 +48,7 @@ public String getName() { } }; - public OutputSocketElement(@NotNull final ShaderNodeParameter parameter) { + public OutputSocketElement(@NotNull ShaderNodeParameter parameter) { super(parameter); setOnDragDetected(this::handleStartDrag); setOnDragDone(this::handleStopDrag); @@ -59,16 +59,19 @@ public OutputSocketElement(@NotNull final ShaderNodeParameter parameter) { /** * Handle dragging. * - * @param mouseEvent the mouse event. + * @param event the mouse event. */ - @FXThread - private void handleMouseDragged(final MouseEvent mouseEvent) { - final ShaderNodeParameter parameter = getParameter(); - final ShaderNodeElement nodeElement = parameter.getNodeElement(); - final ShaderNodesContainer container = nodeElement.getContainer(); + @FxThread + private void handleMouseDragged(@NotNull MouseEvent event) { + + var container = getParameter() + .getNodeElement() + .getContainer(); + container.startAttaching(this); - container.updateAttaching(mouseEvent.getSceneX(), mouseEvent.getSceneY()); - mouseEvent.consume(); + container.updateAttaching(event.getSceneX(), event.getSceneY()); + + event.consume(); } /** @@ -76,16 +79,16 @@ private void handleMouseDragged(final MouseEvent mouseEvent) { * * @param dragEvent the drag event. */ - @FXThread - private void handleStopDrag(@NotNull final DragEvent dragEvent) { + @FxThread + private void handleStopDrag(@NotNull DragEvent dragEvent) { setCursor(Cursor.DEFAULT); - final ShaderNodeParameter parameter = getParameter(); - final ShaderNodeElement nodeElement = parameter.getNodeElement(); - final ShaderNodesContainer container = nodeElement.getContainer(); - container.finishAttaching(); + getParameter().getNodeElement() + .getContainer() + .finishAttaching(); dragEvent.consume(); + dragged.setValue(false); } @@ -94,23 +97,25 @@ private void handleStopDrag(@NotNull final DragEvent dragEvent) { * * @param mouseEvent the mouse event. */ - @FXThread - private void handleStartDrag(@NotNull final MouseEvent mouseEvent) { + @FxThread + private void handleStartDrag(@NotNull MouseEvent mouseEvent) { setCursor(Cursor.MOVE); - final ClipboardContent content = new ClipboardContent(); + var content = new ClipboardContent(); content.put(DATA_FORMAT, ""); - final Dragboard dragBoard = startDragAndDrop(TransferMode.MOVE); + var dragBoard = startDragAndDrop(TransferMode.MOVE); dragBoard.setContent(content); - final ShaderNodeParameter parameter = getParameter(); - final ShaderNodeElement nodeElement = parameter.getNodeElement(); - final ShaderNodesContainer container = nodeElement.getContainer(); + var parameter = getParameter(); + var nodeElement = parameter.getNodeElement(); + + var container = nodeElement.getContainer(); container.startAttaching(this); container.updateAttaching(mouseEvent.getSceneX(), mouseEvent.getSceneY()); dragged.setValue(true); + mouseEvent.consume(); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/SocketElement.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/SocketElement.java index d9409e5..b330365 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/SocketElement.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/parameter/socket/SocketElement.java @@ -1,6 +1,7 @@ package com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.socket; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.manager.ExecutorManager; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; import javafx.beans.property.DoubleProperty; @@ -20,6 +21,9 @@ */ public class SocketElement extends Pane { + @NotNull + private static final ExecutorManager EXECUTOR_MANAGER = ExecutorManager.getInstance(); + /** * The center X property. */ @@ -38,14 +42,16 @@ public class SocketElement extends Pane { @NotNull private final ShaderNodeParameter parameter; - public SocketElement(@NotNull final ShaderNodeParameter parameter) { + public SocketElement(@NotNull ShaderNodeParameter parameter) { this.parameter = parameter; this.centerXProperty = new SimpleDoubleProperty(); this.centerYProperty = new SimpleDoubleProperty(); - final ShaderNodeElement nodeElement = parameter.getNodeElement(); - nodeElement.layoutXProperty().addListener(this::updateCenterCoords); - nodeElement.layoutYProperty().addListener(this::updateCenterCoords); + var element = parameter.getNodeElement(); + element.layoutXProperty().addListener(this::updateCenterCoords); + element.layoutYProperty().addListener(this::updateCenterCoords); + element.heightProperty().addListener((observable, oldValue, newValue) -> + EXECUTOR_MANAGER.addFxTask(this::updateCenterCoords)); } /** @@ -53,11 +59,19 @@ public SocketElement(@NotNull final ShaderNodeParameter parameter) { * * @return the nodes parameter element. */ - @FXThread + @FxThread protected @NotNull ShaderNodeParameter getParameter() { return parameter; } + /** + * Update coords of this socket. + */ + @FxThread + public void updateCenterCoords() { + updateCenterCoords(null, null, null); + } + /** * Update coords of this socket. * @@ -65,37 +79,43 @@ public SocketElement(@NotNull final ShaderNodeParameter parameter) { * @param oldValue the old value. * @param newValue the new value. */ - @FXThread - private void updateCenterCoords(@Nullable final ObservableValue observable, - @Nullable final Number oldValue, @Nullable final Number newValue) { - - final ShaderNodeParameter parameter = getParameter(); - final ShaderNodeElement nodeElement = parameter.getNodeElement(); - final Parent parent = nodeElement.getParent(); + @FxThread + private void updateCenterCoords( + @Nullable ObservableValue observable, + @Nullable Number oldValue, + @Nullable Number newValue + ) { + var parameter = getParameter(); + var nodeElement = parameter.getNodeElement(); + var parent = nodeElement.getParent(); if (parent == null) { return; } - final Point2D scene = localToScene(getWidth() / 2, getHeight() / 2); - final Point2D local = parent.sceneToLocal(scene.getX(), scene.getY()); + var scene = localToScene(getWidth() / 2, getHeight() / 2); + var local = parent.sceneToLocal(scene.getX(), scene.getY()); centerXProperty.setValue(local.getX()); centerYProperty.setValue(local.getY()); } /** + * Get the center X property. + * * @return the center X property. */ - @FXThread + @FxThread public @NotNull ReadOnlyDoubleProperty centerXPropertyProperty() { return centerXProperty; } /** + * Get the center Y property. + * * @return the center Y property. */ - @FXThread + @FxThread public @NotNull ReadOnlyDoubleProperty centerYPropertyProperty() { return centerYProperty; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/tooltip/SndDocumentationTooltip.java b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/tooltip/SndDocumentationTooltip.java new file mode 100644 index 0000000..111b4f3 --- /dev/null +++ b/src/main/java/com/ss/editor/shader/nodes/ui/component/shader/nodes/tooltip/SndDocumentationTooltip.java @@ -0,0 +1,91 @@ +package com.ss.editor.shader.nodes.ui.component.shader.nodes.tooltip; + +import static com.ss.rlib.util.ObjectUtils.notNull; +import com.jme3.asset.AssetManager; +import com.jme3.asset.ShaderNodeDefinitionKey; +import com.jme3.shader.ShaderNodeDefinition; +import com.ss.editor.annotation.FxThread; +import com.ss.editor.shader.nodes.ui.PluginCssClasses; +import com.ss.editor.shader.nodes.ui.component.SndDocumentationArea; +import com.ss.editor.ui.tooltip.CustomTooltip; +import com.ss.editor.util.EditorUtil; +import com.ss.rlib.ui.util.FXUtils; +import com.ss.rlib.util.StringUtils; +import javafx.scene.layout.BorderPane; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * The tooltip with documentation of shader node definition. + * + * @author JavaSaBr + */ +public class SndDocumentationTooltip extends CustomTooltip { + + @NotNull + private final ShaderNodeDefinition definition; + + @Nullable + private SndDocumentationArea documentation; + + public SndDocumentationTooltip(@NotNull final ShaderNodeDefinition definition) { + this.definition = definition; + } + + @Override + @FxThread + protected @NotNull BorderPane createRoot() { + return new BorderPane(); + } + + @Override + @FxThread + protected void createContent(@NotNull final BorderPane root) { + super.createContent(root); + this.documentation = new SndDocumentationArea(); + this.documentation.setEditable(false); + root.setCenter(documentation); + FXUtils.addClassesTo(documentation, PluginCssClasses.SHADER_NODE_DEF_DOCUMENTATION_TOOLTIP); + } + + /** + * Get the definition. + * + * @return the definition. + */ + @FxThread + private @NotNull ShaderNodeDefinition getDefinition() { + return definition; + } + + /** + * Get the area to show documentation. + * + * @return the area to show documentation. + */ + @FxThread + private @NotNull SndDocumentationArea getDocumentation() { + return notNull(documentation); + } + + @Override + @FxThread + protected void show() { + + final ShaderNodeDefinition definition = getDefinition(); + final ShaderNodeDefinitionKey assetKey = new ShaderNodeDefinitionKey(definition.getPath()); + assetKey.setLoadDocumentation(true); + + final AssetManager assetManager = EditorUtil.getAssetManager(); + String documentation = assetManager.loadAsset(assetKey).stream() + .filter(def -> def.getName().equals(definition.getName())) + .map(ShaderNodeDefinition::getDocumentation) + .findAny().orElse(""); + + if (!StringUtils.isEmpty(documentation)) { + getDocumentation().reloadContent(documentation.trim()); + } + + super.show(); + } +} diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndAction.java index 072f0c9..04cfd1f 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndAction.java @@ -7,7 +7,7 @@ import com.jme3.shader.Shader.ShaderType; import com.jme3.shader.ShaderNodeDefinition; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.plugin.api.dialog.GenericFactoryDialog; import com.ss.editor.plugin.api.property.PropertyDefinition; @@ -40,24 +40,24 @@ public class AddSndAction extends AbstractNodeAction { @NotNull private static final String PROP_TYPE = "type"; - public AddSndAction(@NotNull final NodeTree nodeTree, @NotNull final TreeNode node) { + public AddSndAction(@NotNull NodeTree nodeTree, @NotNull TreeNode node) { super(nodeTree, node); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.ACTION_ADD_SHADER_NODE_DEFINITION; } @Override - @FXThread + @FxThread protected @Nullable Image getIcon() { return Icons.ADD_16; } @Override - @FXThread + @FxThread protected void process() { super.process(); @@ -66,7 +66,7 @@ protected void process() { definitions.add(new PropertyDefinition(STRING_FROM_LIST, Messages.MODEL_PROPERTY_TYPE, PROP_TYPE, ShaderType.Vertex.name(), AVAILABLE_TYPES)); - final GenericFactoryDialog dialog = new GenericFactoryDialog(definitions, this::addDefinition, this::validate); + var dialog = new GenericFactoryDialog(definitions, this::addDefinition, this::validate); dialog.setTitle(getName()); dialog.show(); } @@ -76,13 +76,13 @@ protected void process() { * * @param vars the vars of the definition. */ - @FXThread - private boolean validate(@NotNull final VarTable vars) { + @FxThread + private boolean validate(@NotNull VarTable vars) { - final String name = vars.getString(PROP_NAME); + var name = vars.getString(PROP_NAME); - final TreeNode node = getNode(); - final SndList element = (SndList) node.getElement(); + var node = getNode(); + var element = (SndList) node.getElement(); return element.getDefinitions().stream() .noneMatch(definition -> definition.getName().equals(name)); @@ -93,23 +93,23 @@ private boolean validate(@NotNull final VarTable vars) { * * @param vars the vars of the definition. */ - @FXThread - private void addDefinition(@NotNull final VarTable vars) { + @FxThread + private void addDefinition(@NotNull VarTable vars) { - final String definitionName = vars.getString(PROP_NAME); - final ShaderType type = vars.getEnum(PROP_TYPE, ShaderType.class); + var definitionName = vars.getString(PROP_NAME); + var type = vars.getEnum(PROP_TYPE, ShaderType.class); - final TreeNode node = getNode(); - final SndList element = (SndList) node.getElement(); + var node = getNode(); + var element = (SndList) node.getElement(); - final ShaderNodeDefinition definition = new ShaderNodeDefinition(); + var definition = new ShaderNodeDefinition(); definition.setName(definitionName); definition.setType(type); definition.setDocumentation(""); definition.setInputs(new ArrayList<>()); definition.setOutputs(new ArrayList<>()); - final ChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); + var changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(new AddSndOperation(element, definition)); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndInputParameterAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndInputParameterAction.java index 70f9a2c..34ef3fe 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndInputParameterAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndInputParameterAction.java @@ -2,7 +2,7 @@ import com.jme3.shader.ShaderNodeDefinition; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.ui.control.tree.NodeTree; import com.ss.editor.ui.control.tree.node.TreeNode; import org.jetbrains.annotations.NotNull; @@ -16,20 +16,22 @@ */ public class AddSndInputParameterAction extends AddSndParameterAction { - public AddSndInputParameterAction(@NotNull final NodeTree nodeTree, - @NotNull final TreeNode node) { + public AddSndInputParameterAction( + @NotNull NodeTree nodeTree, + @NotNull TreeNode node + ) { super(nodeTree, node); } @Override - @FXThread - protected @NotNull List getCurrentParameters(@NotNull final ShaderNodeDefinition definition) { + @FxThread + protected @NotNull List getCurrentParameters(@NotNull ShaderNodeDefinition definition) { return definition.getInputs(); } @Override - @FXThread - protected @NotNull List getOppositeParameters(@NotNull final ShaderNodeDefinition definition) { + @FxThread + protected @NotNull List getOppositeParameters(@NotNull ShaderNodeDefinition definition) { return definition.getOutputs(); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndOutputParameterAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndOutputParameterAction.java index 2495344..97d2c30 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndOutputParameterAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndOutputParameterAction.java @@ -2,7 +2,7 @@ import com.jme3.shader.ShaderNodeDefinition; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.ui.control.tree.NodeTree; import com.ss.editor.ui.control.tree.node.TreeNode; import org.jetbrains.annotations.NotNull; @@ -16,20 +16,22 @@ */ public class AddSndOutputParameterAction extends AddSndParameterAction { - public AddSndOutputParameterAction(@NotNull final NodeTree nodeTree, - @NotNull final TreeNode node) { + public AddSndOutputParameterAction( + @NotNull NodeTree nodeTree, + @NotNull TreeNode node + ) { super(nodeTree, node); } @Override - @FXThread - protected @NotNull List getCurrentParameters(@NotNull final ShaderNodeDefinition definition) { + @FxThread + protected @NotNull List getCurrentParameters(@NotNull ShaderNodeDefinition definition) { return definition.getOutputs(); } @Override - @FXThread - protected @NotNull List getOppositeParameters(@NotNull final ShaderNodeDefinition definition) { + @FxThread + protected @NotNull List getOppositeParameters(@NotNull ShaderNodeDefinition definition) { return definition.getInputs(); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndParameterAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndParameterAction.java index c5c5995..55bf3b4 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndParameterAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndParameterAction.java @@ -6,7 +6,7 @@ import com.jme3.shader.ShaderNodeDefinition; import com.jme3.shader.ShaderNodeVariable; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.plugin.api.dialog.GenericFactoryDialog; import com.ss.editor.plugin.api.property.PropertyDefinition; @@ -17,7 +17,7 @@ import com.ss.editor.ui.control.tree.NodeTree; import com.ss.editor.ui.control.tree.action.AbstractNodeAction; import com.ss.editor.ui.control.tree.node.TreeNode; -import com.ss.editor.util.GLSLType; +import com.ss.editor.util.GlslType; import com.ss.rlib.util.StringUtils; import com.ss.rlib.util.VarTable; import com.ss.rlib.util.array.Array; @@ -27,7 +27,6 @@ import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.Optional; /** * The action to add new parameter. @@ -42,18 +41,18 @@ public abstract class AddSndParameterAction extends AbstractNodeAction nodeTree, @NotNull final TreeNode node) { + public AddSndParameterAction(@NotNull NodeTree nodeTree, @NotNull TreeNode node) { super(nodeTree, node); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.ACTION_ADD_SND_PARAMETER; } @Override - @FXThread + @FxThread protected @Nullable Image getIcon() { return Icons.ADD_16; } @@ -64,9 +63,10 @@ public AddSndParameterAction(@NotNull final NodeTree nodeTree, @NotNull final * @param definition the definition. * @return the list of current parameters. */ - @FXThread + @FxThread protected abstract @NotNull List getCurrentParameters( - @NotNull final ShaderNodeDefinition definition); + @NotNull ShaderNodeDefinition definition + ); /** * Get the list of opposite parameters. @@ -74,20 +74,21 @@ public AddSndParameterAction(@NotNull final NodeTree nodeTree, @NotNull final * @param definition the definition. * @return the list of opposite parameters. */ - @FXThread + @FxThread protected abstract @NotNull List getOppositeParameters( - @NotNull final ShaderNodeDefinition definition); + @NotNull ShaderNodeDefinition definition + ); @Override - @FXThread + @FxThread protected void process() { super.process(); final Array definitions = ArrayFactory.newArray(PropertyDefinition.class); definitions.add(new PropertyDefinition(STRING, Messages.MODEL_PROPERTY_NAME, PROP_NAME, "newVar")); - definitions.add(new PropertyDefinition(ENUM, Messages.MODEL_PROPERTY_TYPE, PROP_TYPE, GLSLType.FLOAT)); + definitions.add(new PropertyDefinition(ENUM, Messages.MODEL_PROPERTY_TYPE, PROP_TYPE, GlslType.FLOAT)); - final GenericFactoryDialog dialog = new GenericFactoryDialog(definitions, this::addParameter, this::validate); + var dialog = new GenericFactoryDialog(definitions, this::addParameter, this::validate); dialog.setTitle(getName()); dialog.show(); } @@ -97,26 +98,26 @@ protected void process() { * * @param vars the vars of the new parameter. */ - @FXThread - private boolean validate(@NotNull final VarTable vars) { + @FxThread + private boolean validate(@NotNull VarTable vars) { - final TreeNode node = getNode(); - final SndParameters parameters = (SndParameters) node.getElement(); - final ShaderNodeDefinition definition = parameters.getDefinition(); + var node = getNode(); + var parameters = (SndParameters) node.getElement(); + var definition = parameters.getDefinition(); - final String name = vars.getString(PROP_NAME); - final boolean exists = getCurrentParameters(definition).stream() + var name = vars.getString(PROP_NAME); + var exists = getCurrentParameters(definition).stream() .anyMatch(variable -> variable.getName().equals(name)); if (exists) { return false; } - final GLSLType glslType = vars.getEnum(PROP_TYPE, GLSLType.class); - final String rawType = glslType.getRawType(); + var glslType = vars.getEnum(PROP_TYPE, GlslType.class); + var rawType = glslType.getRawType(); - final List oppositeParameters = getOppositeParameters(definition); - final Optional oppositeParameter = oppositeParameters.stream() + var oppositeParameters = getOppositeParameters(definition); + var oppositeParameter = oppositeParameters.stream() .filter(variable -> variable.getName().equals(name)) .findAny(); @@ -124,7 +125,7 @@ private boolean validate(@NotNull final VarTable vars) { return true; } - final ShaderNodeVariable variable = oppositeParameter.get(); + var variable = oppositeParameter.get(); return StringUtils.equals(rawType, variable.getType()); } @@ -133,18 +134,18 @@ private boolean validate(@NotNull final VarTable vars) { * * @param vars the vars of the parameter. */ - @FXThread - private void addParameter(@NotNull final VarTable vars) { + @FxThread + private void addParameter(@NotNull VarTable vars) { - final TreeNode node = getNode(); - final SndParameters parameters = (SndParameters) node.getElement(); + var node = getNode(); + var parameters = (SndParameters) node.getElement(); - final String name = vars.getString(PROP_NAME); - final GLSLType glslType = vars.getEnum(PROP_TYPE, GLSLType.class); + var name = vars.getString(PROP_NAME); + var GlslType = vars.getEnum(PROP_TYPE, GlslType.class); - final ShaderNodeVariable variable = new ShaderNodeVariable(glslType.getRawType(), name); + var variable = new ShaderNodeVariable(GlslType.getRawType(), name); - final ChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); + var changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(new AddSndParameterOperation(parameters, variable)); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndShaderSourceAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndShaderSourceAction.java index b5f2ba0..8304d11 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndShaderSourceAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/AddSndShaderSourceAction.java @@ -6,9 +6,7 @@ import static com.ss.editor.util.EditorUtil.toAssetPath; import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.renderer.Caps; -import com.jme3.shader.Shader; -import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.plugin.api.dialog.GenericFactoryDialog; import com.ss.editor.plugin.api.property.PropertyDefinition; @@ -42,31 +40,31 @@ public class AddSndShaderSourceAction extends AbstractNodeAction @NotNull private static final String PROP_SHADER_RESOURCE = "resource"; - public AddSndShaderSourceAction(@NotNull final NodeTree nodeTree, @NotNull final TreeNode node) { + public AddSndShaderSourceAction(@NotNull NodeTree nodeTree, @NotNull TreeNode node) { super(nodeTree, node); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.ACTION_ADD_SHADER_NODE_SOURCE; } @Override - @FXThread + @FxThread protected @Nullable Image getIcon() { return Icons.ADD_16; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final TreeNode node = getNode(); - final SndShaderSources shaderSources = (SndShaderSources) node.getElement(); - final ShaderNodeDefinition definition = shaderSources.getDefinition(); - final Shader.ShaderType type = definition.getType(); + var node = getNode(); + var shaderSources = (SndShaderSources) node.getElement(); + var definition = shaderSources.getDefinition(); + var type = definition.getType(); final Array definitions = ArrayFactory.newArray(PropertyDefinition.class); definitions.add(new PropertyDefinition(STRING_FROM_LIST, PluginMessages.SND_CREATOR_LANGUAGE, PROP_LANGUAGE, @@ -74,7 +72,7 @@ protected void process() { definitions.add(new PropertyDefinition(FILE_FROM_ASSET_FOLDER, PluginMessages.SND_CREATOR_SOURCE_FILE, PROP_SHADER_RESOURCE, null, type.getExtension())); - final GenericFactoryDialog dialog = new GenericFactoryDialog(definitions, this::addShaderSource, this::validate); + var dialog = new GenericFactoryDialog(definitions, this::addShaderSource, this::validate); dialog.setTitle(getName()); dialog.show(); } @@ -84,19 +82,19 @@ protected void process() { * * @param vars the vars of the definition. */ - @FXThread - private boolean validate(@NotNull final VarTable vars) { + @FxThread + private boolean validate(@NotNull VarTable vars) { if (!vars.has(PROP_SHADER_RESOURCE)) { return false; } - final TreeNode node = getNode(); - final SndShaderSources shaderSources = (SndShaderSources) node.getElement(); - final ShaderNodeDefinition definition = shaderSources.getDefinition(); + var node = getNode(); + var shaderSources = (SndShaderSources) node.getElement(); + var definition = shaderSources.getDefinition(); - final Path shaderFile = vars.get(PROP_SHADER_RESOURCE, Path.class); - final String shaderPath = toAssetPath(shaderFile); + var shaderFile = vars.get(PROP_SHADER_RESOURCE, Path.class); + var shaderPath = toAssetPath(shaderFile); return !definition.getShadersPath().contains(shaderPath); } @@ -106,19 +104,18 @@ private boolean validate(@NotNull final VarTable vars) { * * @param vars the vars of the source. */ - @FXThread - private void addShaderSource(@NotNull final VarTable vars) { + @FxThread + private void addShaderSource(@NotNull VarTable vars) { - final String language = vars.getString(PROP_LANGUAGE); - final Path shaderFile = vars.get(PROP_SHADER_RESOURCE, Path.class); + var language = vars.getString(PROP_LANGUAGE); + var shaderFile = vars.get(PROP_SHADER_RESOURCE, Path.class); - final TreeNode node = getNode(); - final SndShaderSources shaderSources = (SndShaderSources) node.getElement(); - final ShaderNodeDefinition definition = shaderSources.getDefinition(); - final SndShaderSource shaderSource = - new SndShaderSource(definition, language, toAssetPath(shaderFile)); + var node = getNode(); + var shaderSources = (SndShaderSources) node.getElement(); + var definition = shaderSources.getDefinition(); + var shaderSource = new SndShaderSource(definition, language, toAssetPath(shaderFile)); - final ChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); + var changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(new AddSndShaderSourceOperation(shaderSources, shaderSource)); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndAction.java index ba40165..91c29ea 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndAction.java @@ -3,7 +3,7 @@ import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.shader.ShaderNodeDefinition; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.model.shader.node.definition.SndList; import com.ss.editor.shader.nodes.ui.control.tree.operation.DeleteSndOperation; @@ -22,34 +22,34 @@ */ public class DeleteSndAction extends AbstractNodeAction { - public DeleteSndAction(@NotNull final NodeTree nodeTree, @NotNull final TreeNode node) { + public DeleteSndAction(@NotNull NodeTree nodeTree, @NotNull TreeNode node) { super(nodeTree, node); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return Messages.MODEL_NODE_TREE_ACTION_REMOVE; } @Override - @FXThread + @FxThread protected @Nullable Image getIcon() { return Icons.REMOVE_16; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final TreeNode node = getNode(); - final TreeNode parent = notNull(node.getParent()); + var node = getNode(); + var parent = notNull(node.getParent()); - final ShaderNodeDefinition definition = (ShaderNodeDefinition) node.getElement(); - final SndList definitionList = (SndList) parent.getElement(); + var definition = (ShaderNodeDefinition) node.getElement(); + var definitionList = (SndList) parent.getElement(); - final ChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); + var changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(new DeleteSndOperation(definitionList, definition)); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndarameterAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndParameterAction.java similarity index 65% rename from src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndarameterAction.java rename to src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndParameterAction.java index e023408..8927281 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndarameterAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndParameterAction.java @@ -3,7 +3,7 @@ import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.shader.ShaderNodeVariable; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.model.shader.node.definition.SndParameters; import com.ss.editor.shader.nodes.ui.control.tree.operation.DeleteSndParameterOperation; @@ -20,35 +20,35 @@ * * @author JavaSaBr */ -public class DeleteSndarameterAction extends AbstractNodeAction { +public class DeleteSndParameterAction extends AbstractNodeAction { - public DeleteSndarameterAction(@NotNull final NodeTree nodeTree, @NotNull final TreeNode node) { + public DeleteSndParameterAction(@NotNull NodeTree nodeTree, @NotNull TreeNode node) { super(nodeTree, node); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return Messages.MODEL_NODE_TREE_ACTION_REMOVE; } @Override - @FXThread + @FxThread protected @Nullable Image getIcon() { return Icons.REMOVE_16; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final TreeNode node = getNode(); - final TreeNode parent = notNull(node.getParent()); - final ShaderNodeVariable variable = (ShaderNodeVariable) node.getElement(); - final SndParameters parameters = (SndParameters) parent.getElement(); + var node = getNode(); + var parent = notNull(node.getParent()); + var variable = (ShaderNodeVariable) node.getElement(); + var parameters = (SndParameters) parent.getElement(); - final ChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); + var changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(new DeleteSndParameterOperation(parameters, variable)); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndShaderSourceAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndShaderSourceAction.java index 8b76401..0b3cf87 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndShaderSourceAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/DeleteSndShaderSourceAction.java @@ -2,7 +2,7 @@ import static com.ss.rlib.util.ObjectUtils.notNull; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.model.shader.node.definition.SndShaderSource; import com.ss.editor.shader.nodes.model.shader.node.definition.SndShaderSources; @@ -22,33 +22,33 @@ */ public class DeleteSndShaderSourceAction extends AbstractNodeAction { - public DeleteSndShaderSourceAction(@NotNull final NodeTree nodeTree, @NotNull final TreeNode node) { + public DeleteSndShaderSourceAction(@NotNull NodeTree nodeTree, @NotNull TreeNode node) { super(nodeTree, node); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return Messages.MODEL_NODE_TREE_ACTION_REMOVE; } @Override - @FXThread + @FxThread protected @Nullable Image getIcon() { return Icons.REMOVE_16; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final TreeNode node = getNode(); - final TreeNode parent = notNull(node.getParent()); - final SndShaderSource shaderSource = (SndShaderSource) node.getElement(); - final SndShaderSources shaderSources = (SndShaderSources) parent.getElement(); + var node = getNode(); + var parent = notNull(node.getParent()); + var shaderSource = (SndShaderSource) node.getElement(); + var shaderSources = (SndShaderSources) parent.getElement(); - final ChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); + var changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(new DeleteSndShaderSourceOperation(shaderSources, shaderSource)); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/EditSndDocumentationAction.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/EditSndDocumentationAction.java index 7dfddf8..45d4ad8 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/EditSndDocumentationAction.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/action/EditSndDocumentationAction.java @@ -1,11 +1,9 @@ package com.ss.editor.shader.nodes.ui.control.tree.action; import static com.ss.rlib.util.ObjectUtils.notNull; -import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.PluginMessages; -import com.ss.editor.shader.nodes.model.shader.node.definition.SndDocumentation; import com.ss.editor.shader.nodes.ui.control.tree.node.definition.SndDocumentationTreeNode; import com.ss.editor.shader.nodes.ui.dialog.EditSndDocumentationDialog; import com.ss.editor.ui.Icons; @@ -23,35 +21,35 @@ */ public class EditSndDocumentationAction extends AbstractNodeAction { - public EditSndDocumentationAction(@NotNull final NodeTree nodeTree, @NotNull final TreeNode node) { + public EditSndDocumentationAction(@NotNull NodeTree nodeTree, @NotNull TreeNode node) { super(nodeTree, node); } @Override - @FXThread + @FxThread protected @NotNull String getName() { return PluginMessages.ACTION_ADD_EDIT_DOCUMENTATION; } @Override - @FXThread + @FxThread protected @Nullable Image getIcon() { return Icons.EDIT_16; } @Override - @FXThread + @FxThread protected void process() { super.process(); - final SndDocumentationTreeNode node = (SndDocumentationTreeNode) getNode(); - final SndDocumentation documentation = node.getElement(); - final ShaderNodeDefinition definition = documentation.getDefinition(); + var node = (SndDocumentationTreeNode) getNode(); + var documentation = node.getElement(); + var definition = documentation.getDefinition(); - final NodeTree nodeTree = getNodeTree(); - final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer()); + var nodeTree = getNodeTree(); + var changeConsumer = notNull(nodeTree.getChangeConsumer()); - final EditSndDocumentationDialog dialog = new EditSndDocumentationDialog(changeConsumer, definition); + var dialog = new EditSndDocumentationDialog(changeConsumer, definition); dialog.show(); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/factory/ShaderNodesTreeNodeFactory.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/factory/ShaderNodesTreeNodeFactory.java index 8efcb79..3d2caa3 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/factory/ShaderNodesTreeNodeFactory.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/factory/ShaderNodesTreeNodeFactory.java @@ -3,14 +3,14 @@ import static com.ss.rlib.util.ClassUtils.unsafeCast; import com.jme3.shader.ShaderNodeDefinition; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.model.PreviewMaterialSettings; import com.ss.editor.shader.nodes.model.shader.node.definition.*; import com.ss.editor.shader.nodes.ui.control.tree.node.PreviewMaterialSettingsTreeNode; import com.ss.editor.shader.nodes.ui.control.tree.node.definition.*; import com.ss.editor.ui.control.tree.node.TreeNode; -import com.ss.editor.ui.control.tree.node.TreeNodeFactory; +import com.ss.editor.ui.control.tree.node.factory.TreeNodeFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,8 +29,8 @@ public class ShaderNodesTreeNodeFactory implements TreeNodeFactory { } @Override - @FXThread - public > @Nullable V createFor(@Nullable final T element, final long objectId) { + @FxThread + public > @Nullable V createFor(@Nullable T element, long objectId) { if (element instanceof PreviewMaterialSettings) { return unsafeCast(new PreviewMaterialSettingsTreeNode((PreviewMaterialSettings) element, objectId)); @@ -56,8 +56,8 @@ public class ShaderNodesTreeNodeFactory implements TreeNodeFactory { } @Override - @FXThread - public int getOrder() { + @FxThread + public int getPriority() { return 5; } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/PreviewMaterialSettingsTreeNode.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/PreviewMaterialSettingsTreeNode.java index d9d1999..2687b99 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/PreviewMaterialSettingsTreeNode.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/PreviewMaterialSettingsTreeNode.java @@ -2,7 +2,7 @@ import com.ss.editor.model.node.material.RootMaterialSettings; import com.ss.editor.shader.nodes.PluginMessages; -import com.ss.editor.ui.control.material.tree.node.RootMaterialSettingsTreeNode; +import com.ss.editor.ui.control.tree.node.impl.material.settings.RootMaterialSettingsTreeNode; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndDocumentationTreeNode.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndDocumentationTreeNode.java index 49f35a9..82293f8 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndDocumentationTreeNode.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndDocumentationTreeNode.java @@ -1,6 +1,6 @@ package com.ss.editor.shader.nodes.ui.control.tree.node.definition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.model.shader.node.definition.SndDocumentation; @@ -26,14 +26,14 @@ public SndDocumentationTreeNode(@NotNull final SndDocumentation element, final l } @Override - @FXThread + @FxThread public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final ObservableList items) { super.fillContextMenu(nodeTree, items); items.add(new EditSndDocumentationAction(nodeTree, this)); } @Override - @FXThread + @FxThread public @Nullable Image getIcon() { return PluginIcons.DOCUMENT_16; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndListTreeNode.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndListTreeNode.java index 89123a2..0602b4b 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndListTreeNode.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndListTreeNode.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.control.tree.node.definition; import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.model.shader.node.definition.SndList; @@ -31,14 +31,14 @@ public SndListTreeNode(@NotNull final SndList element, final long objectId) { } @Override - @FXThread + @FxThread public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final ObservableList items) { super.fillContextMenu(nodeTree, items); items.add(new AddSndAction(nodeTree, this)); } @Override - @FXThread + @FxThread public @Nullable Image getIcon() { return PluginIcons.LIST_16; } @@ -50,7 +50,7 @@ public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final } @Override - @FXThread + @FxThread public boolean hasChildren(@NotNull final NodeTree nodeTree) { final SndList definitionList = getElement(); final List definitions = definitionList.getDefinitions(); @@ -58,7 +58,7 @@ public boolean hasChildren(@NotNull final NodeTree nodeTree) { } @Override - @FXThread + @FxThread public @NotNull Array> getChildren(@NotNull final NodeTree nodeTree) { final SndList definitionList = getElement(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndParameterTreeNode.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndParameterTreeNode.java index 14436be..2e9df75 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndParameterTreeNode.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndParameterTreeNode.java @@ -2,11 +2,11 @@ import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.model.shader.node.definition.SndParameters; -import com.ss.editor.shader.nodes.ui.control.tree.action.DeleteSndarameterAction; +import com.ss.editor.shader.nodes.ui.control.tree.action.DeleteSndParameterAction; import com.ss.editor.shader.nodes.ui.control.tree.operation.RenameSndParameterOperation; import com.ss.editor.shader.nodes.ui.PluginIcons; import com.ss.editor.ui.control.tree.NodeTree; @@ -30,13 +30,13 @@ public SndParameterTreeNode(@NotNull final ShaderNodeVariable element, final lon } @Override - @FXThread + @FxThread public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final ObservableList items) { super.fillContextMenu(nodeTree, items); - items.add(new DeleteSndarameterAction(nodeTree, this)); + items.add(new DeleteSndParameterAction(nodeTree, this)); } - @FXThread + @FxThread @Override public void changeName(@NotNull final NodeTree nodeTree, @NotNull final String newName) { if (StringUtils.equals(getName(), newName)) return; @@ -52,7 +52,7 @@ public void changeName(@NotNull final NodeTree nodeTree, @NotNull final Strin } @Override - @FXThread + @FxThread public @Nullable Image getIcon() { return PluginIcons.VARIABLE_16; } @@ -64,7 +64,7 @@ public void changeName(@NotNull final NodeTree nodeTree, @NotNull final Strin } @Override - @FXThread + @FxThread public boolean canEditName() { return true; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndParametersTreeNode.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndParametersTreeNode.java index 6ca0a6d..8b4af72 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndParametersTreeNode.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndParametersTreeNode.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.control.tree.node.definition; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.model.shader.node.definition.SndParameters; @@ -41,14 +41,14 @@ public SndParametersTreeNode(@NotNull final SndParameters element, final long ob } @Override - @FXThread + @FxThread public @Nullable Image getIcon() { return getElement() instanceof SndInputParameters ? PluginIcons.ARROW_RIGHT_16 : PluginIcons.ARROW_LEFT_16; } @Override - @FXThread + @FxThread public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final ObservableList items) { super.fillContextMenu(nodeTree, items); @@ -61,7 +61,7 @@ public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final } @Override - @FXThread + @FxThread public boolean hasChildren(@NotNull final NodeTree nodeTree) { final SndParameters element = getElement(); final List parameters = element.getParameters(); @@ -69,7 +69,7 @@ public boolean hasChildren(@NotNull final NodeTree nodeTree) { } @Override - @FXThread + @FxThread public @NotNull Array> getChildren(@NotNull final NodeTree nodeTree) { final SndParameters element = getElement(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndShaderSourceTreeNode.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndShaderSourceTreeNode.java index 42f62df..ce9ee79 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndShaderSourceTreeNode.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndShaderSourceTreeNode.java @@ -1,6 +1,6 @@ package com.ss.editor.shader.nodes.ui.control.tree.node.definition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.shader.nodes.model.shader.node.definition.SndShaderSource; import com.ss.editor.shader.nodes.ui.control.tree.action.DeleteSndShaderSourceAction; @@ -25,14 +25,14 @@ public SndShaderSourceTreeNode(@NotNull final SndShaderSource element, final lon } @Override - @FXThread + @FxThread public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final ObservableList items) { super.fillContextMenu(nodeTree, items); items.add(new DeleteSndShaderSourceAction(nodeTree, this)); } @Override - @FXThread + @FxThread public @Nullable Image getIcon() { return PluginIcons.CODE_16; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndShaderSourcesTreeNode.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndShaderSourcesTreeNode.java index a4d7cf5..a35e455 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndShaderSourcesTreeNode.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndShaderSourcesTreeNode.java @@ -1,12 +1,12 @@ package com.ss.editor.shader.nodes.ui.control.tree.node.definition; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.PluginMessages; import com.ss.editor.shader.nodes.model.shader.node.definition.SndShaderSource; import com.ss.editor.shader.nodes.model.shader.node.definition.SndShaderSources; -import com.ss.editor.shader.nodes.ui.control.tree.action.AddSndShaderSourceAction; import com.ss.editor.shader.nodes.ui.PluginIcons; +import com.ss.editor.shader.nodes.ui.control.tree.action.AddSndShaderSourceAction; import com.ss.editor.ui.control.tree.NodeTree; import com.ss.editor.ui.control.tree.node.TreeNode; import com.ss.rlib.util.array.Array; @@ -37,20 +37,20 @@ public SndShaderSourcesTreeNode(@NotNull final SndShaderSources element, final l } @Override - @FXThread + @FxThread public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final ObservableList items) { super.fillContextMenu(nodeTree, items); items.add(new AddSndShaderSourceAction(nodeTree, this)); } @Override - @FXThread + @FxThread public @Nullable Image getIcon() { return PluginIcons.CODE_16; } @Override - @FXThread + @FxThread public boolean hasChildren(@NotNull final NodeTree nodeTree) { final SndShaderSources element = getElement(); final Map sourceMap = element.getShadeSourceMap(); @@ -58,7 +58,7 @@ public boolean hasChildren(@NotNull final NodeTree nodeTree) { } @Override - @FXThread + @FxThread public @NotNull Array> getChildren(@NotNull final NodeTree nodeTree) { final SndShaderSources element = getElement(); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndTreeNode.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndTreeNode.java index 337345b..af1571d 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndTreeNode.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/node/definition/SndTreeNode.java @@ -2,7 +2,7 @@ import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.model.shader.node.definition.*; @@ -33,7 +33,7 @@ public SndTreeNode(@NotNull final ShaderNodeDefinition element, final long objec } @Override - @FXThread + @FxThread public @Nullable Image getIcon() { final ShaderNodeDefinition element = getElement(); @@ -53,7 +53,7 @@ public SndTreeNode(@NotNull final ShaderNodeDefinition element, final long objec } @Override - @FXThread + @FxThread public void changeName(@NotNull final NodeTree nodeTree, @NotNull final String newName) { if (StringUtils.equals(getName(), newName)) return; @@ -68,19 +68,19 @@ public void changeName(@NotNull final NodeTree nodeTree, @NotNull final Strin } @Override - @FXThread + @FxThread public boolean canEditName() { return true; } @Override - @FXThread + @FxThread public boolean hasChildren(@NotNull final NodeTree nodeTree) { return true; } @Override - @FXThread + @FxThread public @NotNull Array> getChildren(@NotNull final NodeTree nodeTree) { final ShaderNodeDefinition definition = getElement(); @@ -95,7 +95,7 @@ public boolean hasChildren(@NotNull final NodeTree nodeTree) { } @Override - @FXThread + @FxThread public void fillContextMenu(@NotNull final NodeTree nodeTree, @NotNull final ObservableList items) { super.fillContextMenu(nodeTree, items); items.add(new DeleteSndAction(nodeTree, this)); diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndOperation.java index 117b385..36e68b2 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndOperation.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.control.tree.operation; import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.model.shader.node.definition.SndList; @@ -33,16 +33,16 @@ public AddSndOperation(@NotNull final SndList definitionList, } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { definitionList.getDefinitions().add(definition); - editor.notifyFXAddedChild(definitionList, definition, -1, true); + editor.notifyFxAddedChild(definitionList, definition, -1, true); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { definitionList.getDefinitions().remove(definition); - editor.notifyFXRemovedChild(definitionList, definition); + editor.notifyFxRemovedChild(definitionList, definition); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndParameterOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndParameterOperation.java index f944b28..3fea416 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndParameterOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndParameterOperation.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.control.tree.operation; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.model.shader.node.definition.SndParameters; @@ -35,18 +35,18 @@ public AddSndParameterOperation(@NotNull final SndParameters parameters, } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { final List parameterList = parameters.getParameters(); parameterList.add(variable); - editor.notifyFXAddedChild(parameters, variable, -1, true); + editor.notifyFxAddedChild(parameters, variable, -1, true); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { final List parameterList = parameters.getParameters(); parameterList.remove(variable); - editor.notifyFXRemovedChild(parameters, variable); + editor.notifyFxRemovedChild(parameters, variable); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndShaderSourceOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndShaderSourceOperation.java index 910c824..5d5bb89 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndShaderSourceOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/AddSndShaderSourceOperation.java @@ -1,6 +1,6 @@ package com.ss.editor.shader.nodes.ui.control.tree.operation; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.model.shader.node.definition.SndShaderSource; @@ -33,16 +33,16 @@ public AddSndShaderSourceOperation(@NotNull final SndShaderSources shaderSources } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { shaderSources.add(shaderSource); - editor.notifyFXAddedChild(shaderSources, shaderSource, -1, true); + editor.notifyFxAddedChild(shaderSources, shaderSource, -1, true); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { shaderSources.remove(shaderSource); - editor.notifyFXRemovedChild(shaderSources, shaderSources); + editor.notifyFxRemovedChild(shaderSources, shaderSources); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/ChangeSndDocumentationOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/ChangeSndDocumentationOperation.java index 8ab0bef..e3abbed 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/ChangeSndDocumentationOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/ChangeSndDocumentationOperation.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.control.tree.operation; import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import org.jetbrains.annotations.NotNull; @@ -34,16 +34,16 @@ public ChangeSndDocumentationOperation(@NotNull final ShaderNodeDefinition defin } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { definition.setDocumentation(newDocumentation); - editor.notifyFXChangeProperty(definition, "documentation"); + editor.notifyFxChangeProperty(definition, "documentation"); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { definition.setDocumentation(oldDocumentation); - editor.notifyFXChangeProperty(definition, "documentation"); + editor.notifyFxChangeProperty(definition, "documentation"); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndOperation.java index e40ad92..a8d1d9d 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndOperation.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.control.tree.operation; import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.model.shader.node.definition.SndList; @@ -40,18 +40,18 @@ public DeleteSndOperation(@NotNull final SndList definitionList, } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { final List definitions = definitionList.getDefinitions(); index = definitions.indexOf(definition); definitions.remove(definition); - editor.notifyFXRemovedChild(definitionList, definition); + editor.notifyFxRemovedChild(definitionList, definition); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { definitionList.getDefinitions().add(index, definition); - editor.notifyFXAddedChild(definitionList, definition, index, false); + editor.notifyFxAddedChild(definitionList, definition, index, false); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndParameterOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndParameterOperation.java index beea36d..e6c5b61 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndParameterOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndParameterOperation.java @@ -1,7 +1,7 @@ package com.ss.editor.shader.nodes.ui.control.tree.operation; import com.jme3.shader.ShaderNodeVariable; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.model.shader.node.definition.SndParameters; @@ -40,19 +40,19 @@ public DeleteSndParameterOperation(@NotNull final SndParameters parameters, } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { final List parameterList = parameters.getParameters(); index = parameterList.indexOf(variable); parameterList.remove(variable); - editor.notifyFXRemovedChild(parameters, variable); + editor.notifyFxRemovedChild(parameters, variable); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { final List parameterList = parameters.getParameters(); parameterList.add(index, variable); - editor.notifyFXAddedChild(parameters, variable, index, false); + editor.notifyFxAddedChild(parameters, variable, index, false); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndShaderSourceOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndShaderSourceOperation.java index d45d0c8..c18c0b8 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndShaderSourceOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/DeleteSndShaderSourceOperation.java @@ -1,6 +1,6 @@ package com.ss.editor.shader.nodes.ui.control.tree.operation; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.model.shader.node.definition.SndShaderSource; @@ -38,17 +38,17 @@ public DeleteSndShaderSourceOperation(@NotNull final SndShaderSources shaderSour } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { index = shaderSources.indexOf(shaderSource); shaderSources.remove(shaderSource); - editor.notifyFXRemovedChild(shaderSources, shaderSource); + editor.notifyFxRemovedChild(shaderSources, shaderSource); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { shaderSources.add(index, shaderSource); - editor.notifyFXAddedChild(shaderSources, shaderSource, index, false); + editor.notifyFxAddedChild(shaderSources, shaderSource, index, false); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/RenameSndOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/RenameSndOperation.java index 7d5d135..4a16a09 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/RenameSndOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/RenameSndOperation.java @@ -2,7 +2,7 @@ import com.jme3.shader.ShaderNodeDefinition; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.model.shader.node.definition.SndList; @@ -49,16 +49,16 @@ public RenameSndOperation(@NotNull final String oldName, @NotNull final String n } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { definition.setName(newName); - editor.notifyFXChangeProperty(definitionList, definition, Messages.MODEL_PROPERTY_NAME); + editor.notifyFxChangeProperty(definitionList, definition, Messages.MODEL_PROPERTY_NAME); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { definition.setName(oldName); - editor.notifyFXChangeProperty(definitionList, definition, Messages.MODEL_PROPERTY_NAME); + editor.notifyFxChangeProperty(definitionList, definition, Messages.MODEL_PROPERTY_NAME); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/RenameSndParameterOperation.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/RenameSndParameterOperation.java index acf6225..1bed5b2 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/RenameSndParameterOperation.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/operation/RenameSndParameterOperation.java @@ -2,7 +2,7 @@ import com.jme3.shader.ShaderNodeVariable; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.model.undo.impl.AbstractEditorOperation; import com.ss.editor.shader.nodes.model.shader.node.definition.SndParameters; @@ -49,16 +49,16 @@ public RenameSndParameterOperation(@NotNull final String oldName, @NotNull final } @Override - @FXThread + @FxThread protected void redoImpl(@NotNull final ChangeConsumer editor) { variable.setName(newName); - editor.notifyFXChangeProperty(parameters, variable, Messages.MODEL_PROPERTY_NAME); + editor.notifyFxChangeProperty(parameters, variable, Messages.MODEL_PROPERTY_NAME); } @Override - @FXThread + @FxThread protected void undoImpl(@NotNull final ChangeConsumer editor) { variable.setName(oldName); - editor.notifyFXChangeProperty(parameters, variable, Messages.MODEL_PROPERTY_NAME); + editor.notifyFxChangeProperty(parameters, variable, Messages.MODEL_PROPERTY_NAME); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/property/ShaderNodesPropertyBuilder.java b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/property/ShaderNodesPropertyBuilder.java index cf4dba0..5fb2736 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/property/ShaderNodesPropertyBuilder.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/control/tree/property/ShaderNodesPropertyBuilder.java @@ -4,18 +4,19 @@ import com.jme3.shader.ShaderNodeDefinition; import com.jme3.shader.ShaderNodeVariable; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.extension.property.EditableProperty; import com.ss.editor.extension.property.SimpleProperty; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.ui.control.property.builder.PropertyBuilder; import com.ss.editor.ui.control.property.builder.impl.EditableObjectPropertyBuilder; -import com.ss.editor.util.GLSLType; +import com.ss.editor.util.GlslType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; /** @@ -25,6 +26,12 @@ */ public class ShaderNodesPropertyBuilder extends EditableObjectPropertyBuilder { + @NotNull + private static final EnumSet NOT_AVAILABLE_DEFAULT_VALUE = EnumSet.of( + GlslType.SAMPLER_2D, + GlslType.SAMPLER_CUBE + ); + /** * The single instance. */ @@ -46,7 +53,7 @@ protected ShaderNodesPropertyBuilder() { } @Override - @FXThread + @FxThread protected @Nullable List> getProperties(@NotNull final Object object) { if (!(object instanceof ShaderNodeDefinition || object instanceof ShaderNodeVariable)) { @@ -65,13 +72,17 @@ protected ShaderNodesPropertyBuilder() { } else if (object instanceof ShaderNodeVariable) { final ShaderNodeVariable variable = (ShaderNodeVariable) object; + final GlslType glslType = GlslType.ofRawType(variable.getType()); result.add(new SimpleProperty<>(ENUM, Messages.MODEL_PROPERTY_TYPE, variable, - var -> GLSLType.ofRawType(var.getType()), + var -> GlslType.ofRawType(var.getType()), (var, type) -> var.setType(type.getRawType()))); - result.add(new SimpleProperty<>(STRING, Messages.MODEL_PROPERTY_DEFAULT_VALUE, variable, - ShaderNodeVariable::getDefaultValue, - ShaderNodeVariable::setDefaultValue)); + + if (!NOT_AVAILABLE_DEFAULT_VALUE.contains(glslType)) { + result.add(new SimpleProperty<>(STRING, Messages.MODEL_PROPERTY_DEFAULT_VALUE, variable, + ShaderNodeVariable::getDefaultValue, + ShaderNodeVariable::setDefaultValue)); + } } return result; diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/dialog/EditSndDocumentationDialog.java b/src/main/java/com/ss/editor/shader/nodes/ui/dialog/EditSndDocumentationDialog.java index f39a8b2..4976020 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/dialog/EditSndDocumentationDialog.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/dialog/EditSndDocumentationDialog.java @@ -1,16 +1,16 @@ package com.ss.editor.shader.nodes.ui.dialog; -import static com.ss.editor.ui.util.UIUtils.consumeIf; +import static com.ss.editor.ui.util.UiUtils.consumeIf; import static com.ss.rlib.util.ObjectUtils.notNull; import com.jme3.shader.ShaderNodeDefinition; import com.ss.editor.Messages; -import com.ss.editor.annotation.FXThread; import com.ss.editor.annotation.FromAnyThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.model.undo.editor.ChangeConsumer; import com.ss.editor.shader.nodes.PluginMessages; -import com.ss.editor.shader.nodes.ui.control.tree.operation.ChangeSndDocumentationOperation; -import com.ss.editor.shader.nodes.ui.PluginCSSClasses; +import com.ss.editor.shader.nodes.ui.PluginCssClasses; import com.ss.editor.shader.nodes.ui.component.SndDocumentationArea; +import com.ss.editor.shader.nodes.ui.control.tree.operation.ChangeSndDocumentationOperation; import com.ss.editor.ui.dialog.AbstractSimpleEditorDialog; import com.ss.rlib.ui.util.FXUtils; import javafx.scene.input.KeyCode; @@ -48,12 +48,15 @@ public class EditSndDocumentationDialog extends AbstractSimpleEditorDialog { @Nullable private SndDocumentationArea editorArea; - public EditSndDocumentationDialog(@NotNull final ChangeConsumer consumer, - @NotNull final ShaderNodeDefinition definition) { + public EditSndDocumentationDialog( + @NotNull ChangeConsumer consumer, + @NotNull ShaderNodeDefinition definition + ) { this.consumer = consumer; this.definition = definition; - final String documentation = definition.getDocumentation(); - getEditorArea().loadContent(documentation == null ? "" : documentation); + //TODO replace to using util method + var documentation = definition.getDocumentation(); + getEditorArea().loadContent(documentation == null ? "" : documentation.trim()); } /** @@ -61,21 +64,21 @@ public EditSndDocumentationDialog(@NotNull final ChangeConsumer consumer, * * @return the editor area. */ - @FXThread + @FxThread private @NotNull SndDocumentationArea getEditorArea() { return notNull(editorArea); } @Override - @FXThread - protected void createContent(@NotNull final VBox root) { + @FxThread + protected void createContent(@NotNull VBox root) { super.createContent(root); editorArea = new SndDocumentationArea(); editorArea.setOnKeyReleased(event -> consumeIf(event, keyEvent -> keyEvent.getCode() == KeyCode.ENTER)); - FXUtils.addClassTo(editorArea, PluginCSSClasses.SHADER_NODE_DEF_DOCUMENTATION_DIALOG); + FXUtils.addClassTo(editorArea, PluginCssClasses.SHADER_NODE_DEF_DOCUMENTATION_DIALOG); FXUtils.addToPane(editorArea, root); } @@ -92,13 +95,14 @@ protected void createContent(@NotNull final VBox root) { } @Override - @FXThread + @FxThread protected void processOk() { super.processOk(); - final String documentation = definition.getDocumentation(); - final String oldVersion = documentation == null? "" : documentation; - final String newVersion = getEditorArea().getText(); + var documentation = definition.getDocumentation(); + //TODO replace to using util method + var oldVersion = documentation == null? "" : documentation; + var newVersion = getEditorArea().getText(); consumer.execute(new ChangeSndDocumentationOperation(definition, oldVersion, newVersion)); } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/preview/SndFilePreview.java b/src/main/java/com/ss/editor/shader/nodes/ui/preview/SndFilePreview.java index 9148d14..66ab4e5 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/preview/SndFilePreview.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/preview/SndFilePreview.java @@ -1,11 +1,9 @@ package com.ss.editor.shader.nodes.ui.preview; -import com.jme3.asset.AssetManager; import com.jme3.asset.ShaderNodeDefinitionKey; import com.jme3.shader.ShaderNodeDefinition; -import com.ss.editor.Editor; import com.ss.editor.FileExtensions; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.shader.nodes.ui.component.SndDocumentationArea; import com.ss.editor.ui.preview.impl.AbstractFilePreview; import com.ss.editor.util.EditorUtil; @@ -24,48 +22,45 @@ */ public class SndFilePreview extends AbstractFilePreview { - @NotNull - private static final Editor EDITOR = Editor.getInstance(); - @Override - @FXThread + @FxThread protected @NotNull SndDocumentationArea createGraphicsNode() { - final SndDocumentationArea documentationArea = new SndDocumentationArea(); + var documentationArea = new SndDocumentationArea(); documentationArea.setEditable(false); return documentationArea; } @Override - @FXThread - protected void initialize(@NotNull final SndDocumentationArea node, @NotNull final StackPane pane) { + @FxThread + protected void initialize(@NotNull SndDocumentationArea node, @NotNull StackPane pane) { super.initialize(node, pane); node.prefWidthProperty().bind(pane.widthProperty()); node.prefHeightProperty().bind(pane.heightProperty()); } @Override - @FXThread - public void show(@NotNull final Path file) { + @FxThread + public void show(@NotNull Path file) { super.show(file); - final String assetPath = EditorUtil.toAssetPath(file); - final ShaderNodeDefinitionKey key = new ShaderNodeDefinitionKey(assetPath); + var assetPath = EditorUtil.toAssetPath(file); + var key = new ShaderNodeDefinitionKey(assetPath); key.setLoadDocumentation(true); - final AssetManager assetManager = EDITOR.getAssetManager(); - final List definitionList = assetManager.loadAsset(key); + var assetManager = EditorUtil.getAssetManager(); + var definitionList = assetManager.loadAsset(key); show(definitionList); } - @FXThread - private void show(@NotNull final List definitionList) { + @FxThread + private void show(@NotNull List definitionList) { - final SndDocumentationArea documentationArea = getGraphicsNode(); + var documentationArea = getGraphicsNode(); if (definitionList.size() == 1) { - String documentation = definitionList.get(0).getDocumentation(); + var documentation = definitionList.get(0).getDocumentation(); if(StringUtils.isEmpty(documentation)) { documentationArea.reloadContent(" "); return; @@ -79,12 +74,14 @@ private void show(@NotNull final List definitionList) { return; } - final StringBuilder result = new StringBuilder(); + var result = new StringBuilder(); - for (final ShaderNodeDefinition definition : definitionList) { + for (var definition : definitionList) { - final String documentation = definition.getDocumentation(); - if (StringUtils.isEmpty(documentation)) continue; + var documentation = definition.getDocumentation(); + if (StringUtils.isEmpty(documentation)) { + continue; + } result.append("// ----- ") .append(definition.getName()) @@ -97,35 +94,35 @@ private void show(@NotNull final List definitionList) { } @Override - @FXThread - public void show(@NotNull final String resource) { + @FxThread + public void show(@NotNull String resource) { super.show(resource); - final ShaderNodeDefinitionKey key = new ShaderNodeDefinitionKey(resource); + var key = new ShaderNodeDefinitionKey(resource); key.setLoadDocumentation(true); - final AssetManager assetManager = EDITOR.getAssetManager(); - final List definitionList = assetManager.loadAsset(key); + var assetManager = EditorUtil.getAssetManager(); + var definitionList = assetManager.loadAsset(key); show(definitionList); } @Override - @FXThread - public boolean isSupport(@NotNull final Path file) { - final String extension = FileUtils.getExtension(file); + @FxThread + public boolean isSupport(@NotNull Path file) { + var extension = FileUtils.getExtension(file); return FileExtensions.JME_SHADER_NODE.equals(extension); } - @FXThread + @FxThread @Override - public boolean isSupport(@NotNull final String resource) { - final String extension = FileUtils.getExtension(resource); + public boolean isSupport(@NotNull String resource) { + var extension = FileUtils.getExtension(resource); return FileExtensions.JME_SHADER_NODE.equals(extension); } @Override - @FXThread + @FxThread public int getOrder() { return 10; } diff --git a/src/main/java/com/ss/editor/shader/nodes/ui/preview/SndFilePreviewFactory.java b/src/main/java/com/ss/editor/shader/nodes/ui/preview/SndFilePreviewFactory.java index 7cc784c..43696c0 100644 --- a/src/main/java/com/ss/editor/shader/nodes/ui/preview/SndFilePreviewFactory.java +++ b/src/main/java/com/ss/editor/shader/nodes/ui/preview/SndFilePreviewFactory.java @@ -1,6 +1,6 @@ package com.ss.editor.shader.nodes.ui.preview; -import com.ss.editor.annotation.FXThread; +import com.ss.editor.annotation.FxThread; import com.ss.editor.ui.preview.FilePreview; import com.ss.editor.ui.preview.FilePreviewFactory; import com.ss.rlib.util.array.Array; @@ -21,8 +21,8 @@ public class SndFilePreviewFactory implements FilePreviewFactory { } @Override - @FXThread - public void createFilePreviews(@NotNull final Array result) { + @FxThread + public void createFilePreviews(@NotNull Array result) { result.add(new SndFilePreview()); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/util/J3snExporter.java b/src/main/java/com/ss/editor/shader/nodes/util/J3snExporter.java index 8e27f47..1059970 100644 --- a/src/main/java/com/ss/editor/shader/nodes/util/J3snExporter.java +++ b/src/main/java/com/ss/editor/shader/nodes/util/J3snExporter.java @@ -1,6 +1,5 @@ package com.ss.editor.shader.nodes.util; -import com.jme3.shader.Shader; import com.jme3.shader.ShaderNodeDefinition; import com.jme3.shader.ShaderNodeVariable; import com.ss.rlib.util.StringUtils; @@ -30,17 +29,17 @@ public class J3snExporter { * @param definitions the definitions. * @param out the output stream. */ - public void export(@NotNull final List definitions, @NotNull final OutputStream out) { + public void export(@NotNull List definitions, @NotNull OutputStream out) { - final StringBuilder builder = new StringBuilder(); + var builder = new StringBuilder(); builder.append("ShaderNodeDefinitions {\n"); definitions.forEach(definition -> write(definition, builder)); builder.append("}"); - final String result = builder.toString(); + var result = builder.toString(); try { out.write(result.getBytes("UTF-8")); - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException(e); } } @@ -51,22 +50,22 @@ public void export(@NotNull final List definitions, @NotNu * @param definition the definition. * @param builder the builder. */ - private void write(@NotNull final ShaderNodeDefinition definition, @NotNull final StringBuilder builder) { + private void write(@NotNull ShaderNodeDefinition definition, @NotNull StringBuilder builder) { indent(builder, 1); builder.append("ShaderNodeDefinition ") .append(definition.getName()) .append(" {\n"); - final Shader.ShaderType type = definition.getType(); + var type = definition.getType(); - final List shadersPath = definition.getShadersPath(); - final List shadersLanguage = definition.getShadersLanguage(); + var shadersPath = definition.getShadersPath(); + var shadersLanguage = definition.getShadersLanguage(); - final String documentation = definition.getDocumentation(); + var documentation = definition.getDocumentation(); - final List inputs = definition.getInputs(); - final List outputs = definition.getOutputs(); + var inputs = definition.getInputs(); + var outputs = definition.getOutputs(); indent(builder, 2); @@ -74,10 +73,10 @@ private void write(@NotNull final ShaderNodeDefinition definition, @NotNull fina .append(type.name()) .append("\n\n"); - for (int i = 0; i < shadersPath.size(); i++) { + for (var i = 0; i < shadersPath.size(); i++) { - final String path = shadersPath.get(i); - final String language = shadersLanguage.get(i); + var path = shadersPath.get(i); + var language = shadersLanguage.get(i); indent(builder, 2); @@ -119,16 +118,19 @@ private void write(@NotNull final ShaderNodeDefinition definition, @NotNull fina * @param builder the builder. * @param name the name of parameters node. */ - private void write(@NotNull final List variables, @NotNull final StringBuilder builder, - @NotNull final String name) { + private void write( + @NotNull List variables, + @NotNull StringBuilder builder, + @NotNull String name + ) { indent(builder, 2); builder.append(name).append(" {\n"); - for (final ShaderNodeVariable variable : variables) { + for (var variable : variables) { indent(builder, 3); - final String defaultValue = variable.getDefaultValue(); + var defaultValue = variable.getDefaultValue(); builder.append(variable.getType()) .append(' ') @@ -152,13 +154,16 @@ private void write(@NotNull final List variables, @NotNull f * @param builder the builder. * @param name the name of node. */ - private void writeStrings(@NotNull final List values, @NotNull final StringBuilder builder, - @NotNull final String name) { + private void writeStrings( + @NotNull List values, + @NotNull StringBuilder builder, + @NotNull String name + ) { indent(builder, 2); builder.append(name).append(" {\n"); - for (final String value : values) { + for (var value : values) { indent(builder, 3); builder.append(value).append('\n'); } @@ -173,14 +178,17 @@ private void writeStrings(@NotNull final List values, @NotNull final Str * @param builder the builder. * @param level the level. */ - private void indent(@NotNull final StringBuilder builder, final int level) { - if (level < 1) return; + private void indent(@NotNull StringBuilder builder, int level) { - int count = level * 4; + if (level < 1) { + return; + } + + var count = level * 4; builder.ensureCapacity(builder.length() + count); - for (int i = 0; i < count; i++) { + for (var i = 0; i < count; i++) { builder.append(' '); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/util/MaterialDefUtils.java b/src/main/java/com/ss/editor/shader/nodes/util/MaterialDefUtils.java index 5d6cbf4..83eecb7 100644 --- a/src/main/java/com/ss/editor/shader/nodes/util/MaterialDefUtils.java +++ b/src/main/java/com/ss/editor/shader/nodes/util/MaterialDefUtils.java @@ -32,7 +32,7 @@ public class MaterialDefUtils { * @return the mat params. */ @FromAnyThread - public static @NotNull Map getMatParams(@NotNull final MaterialDef def) { + public static @NotNull Map getMatParams(@NotNull MaterialDef def) { return notNull(getFieldValue(def, MAT_PARAMS_FIELD)); } } diff --git a/src/main/java/com/ss/editor/shader/nodes/util/ShaderNodeUtils.java b/src/main/java/com/ss/editor/shader/nodes/util/ShaderNodeUtils.java index 0ff83c8..dad68ca 100644 --- a/src/main/java/com/ss/editor/shader/nodes/util/ShaderNodeUtils.java +++ b/src/main/java/com/ss/editor/shader/nodes/util/ShaderNodeUtils.java @@ -1,5 +1,6 @@ package com.ss.editor.shader.nodes.util; +import static com.ss.rlib.util.dictionary.DictionaryFactory.newObjectDictionary; import static java.util.stream.Collectors.toList; import com.jme3.material.MatParam; import com.jme3.material.MaterialDef; @@ -11,16 +12,27 @@ import com.jme3.shader.VariableMapping; import com.ss.editor.annotation.FromAnyThread; import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodeElement; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.ShaderNodesContainer; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.global.GlobalShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.global.OutputGlobalShaderNodeElement; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.AttributeShaderNodeElement; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.MainShaderNodeElement; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.MaterialShaderNodeElement; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.main.WorldShaderNodeElement; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.InputShaderNodeParameter; import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.OutputShaderNodeParameter; -import com.ss.editor.util.GLSLType; +import com.ss.editor.shader.nodes.ui.component.shader.nodes.parameter.ShaderNodeParameter; +import com.ss.editor.util.GlslType; import com.ss.rlib.util.StringUtils; +import com.ss.rlib.util.dictionary.ObjectDictionary; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.function.BiFunction; /** * The utility class. @@ -29,6 +41,52 @@ */ public class ShaderNodeUtils { + interface NodeElementFactory extends + BiFunction> { + } + + @NotNull + private static final ObjectDictionary NODE_ELEMENT_FACTORIES = newObjectDictionary(); + + static { + NODE_ELEMENT_FACTORIES.put(MaterialShaderNodeElement.NAMESPACE, MaterialShaderNodeElement::new); + NODE_ELEMENT_FACTORIES.put(WorldShaderNodeElement.NAMESPACE, WorldShaderNodeElement::new); + NODE_ELEMENT_FACTORIES.put(AttributeShaderNodeElement.NAMESPACE, AttributeShaderNodeElement::new); + } + + @NotNull + private static final Set SYSTEM_NAMESPACES = Set.of( + MaterialShaderNodeElement.NAMESPACE, + GlobalShaderNodeElement.NAMESPACE, + WorldShaderNodeElement.NAMESPACE, + AttributeShaderNodeElement.NAMESPACE + ); + + /** + * Return true of the node name is user's shader node. + * + * @param shaderNodeName the shader node name. + * @return true of the node name is user's shader node. + */ + public static boolean isUserShaderNode(@NotNull String shaderNodeName) { + return !SYSTEM_NAMESPACES.contains(shaderNodeName); + } + + /** + * Create a shader node element for the shader node variable. + * + * @param container the shader node container. + * @param var the shader node variable. + * @return the option of shader node element. + */ + public static @NotNull Optional> createNodeElement( + @NotNull ShaderNodesContainer container, + @NotNull ShaderNodeVariable var + ) { + return NODE_ELEMENT_FACTORIES.getOptional(var.getNameSpace()) + .map(factory -> factory.apply(container, var)); + } + /** * Find a material parameter with the name. * @@ -37,8 +95,10 @@ public class ShaderNodeUtils { * @return the shader nodes or null. */ @FromAnyThread - public static @Nullable MatParam findMatParameterByName(@NotNull final MaterialDef materialDef, - @NotNull final String name) { + public static @Nullable MatParam findMatParameterByName( + @NotNull MaterialDef materialDef, + @NotNull String name + ) { return materialDef.getMaterialParams().stream() .filter(matParam -> matParam.getName().equals(name)) .findAny().orElse(null); @@ -52,8 +112,10 @@ public class ShaderNodeUtils { * @return the shader nodes or null. */ @FromAnyThread - public static @Nullable UniformBinding findWorldBindingByName(@NotNull final TechniqueDef techniqueDef, - @NotNull final String name) { + public static @Nullable UniformBinding findWorldBindingByName( + @NotNull TechniqueDef techniqueDef, + @NotNull String name + ) { return techniqueDef.getWorldBindings().stream() .filter(binding -> binding.name().equals(name)) .findAny().orElse(null); @@ -67,8 +129,10 @@ public class ShaderNodeUtils { * @return the shader nodes or null. */ @FromAnyThread - public static @Nullable ShaderNodeVariable findAttributeByName(@NotNull final TechniqueDef techniqueDef, - @NotNull final String name) { + public static @Nullable ShaderNodeVariable findAttributeByName( + @NotNull TechniqueDef techniqueDef, + @NotNull String name + ) { return techniqueDef.getShaderGenerationInfo().getAttributes().stream() .filter(variable -> variable.getName().equals(name)) .findAny().orElse(null); @@ -82,8 +146,10 @@ public class ShaderNodeUtils { * @return the shader nodes or null. */ @FromAnyThread - public static @Nullable ShaderNode findByName(@NotNull final TechniqueDef techniqueDef, - @NotNull final String name) { + public static @Nullable ShaderNode findByName( + @NotNull TechniqueDef techniqueDef, + @NotNull String name + ) { return techniqueDef.getShaderNodes().stream() .filter(shaderNode -> shaderNode.getName().equals(name)) .findAny().orElse(null); @@ -97,8 +163,10 @@ public class ShaderNodeUtils { * @return true of the variables are equal. */ @FromAnyThread - public static boolean equalsByNameAndNameSpace(@NotNull final ShaderNodeVariable first, - @NotNull final ShaderNodeVariable second) { + public static boolean equalsByNameAndNameSpace( + @NotNull ShaderNodeVariable first, + @NotNull ShaderNodeVariable second + ) { return StringUtils.equals(first.getName(), second.getName()) && StringUtils.equals(first.getNameSpace(), second.getNameSpace()); } @@ -111,8 +179,10 @@ public static boolean equalsByNameAndNameSpace(@NotNull final ShaderNodeVariable * @return true of the variables are equal. */ @FromAnyThread - public static boolean equalsByName(@NotNull final ShaderNodeVariable first, - @NotNull final ShaderNodeVariable second) { + public static boolean equalsByName( + @NotNull ShaderNodeVariable first, + @NotNull ShaderNodeVariable second + ) { return StringUtils.equals(first.getName(), second.getName()); } @@ -124,8 +194,10 @@ public static boolean equalsByName(@NotNull final ShaderNodeVariable first, * @return the mapping or null. */ @FromAnyThread - public static @Nullable VariableMapping findOutMappingByNNLeftVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable) { + public static @Nullable VariableMapping findOutMappingByNNLeftVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable + ) { return shaderNode.getOutputMapping().stream() .filter(mapping -> equalsByNameAndNameSpace(mapping.getLeftVariable(), variable)) .findAny().orElse(null); @@ -139,13 +211,16 @@ public static boolean equalsByName(@NotNull final ShaderNodeVariable first, * @return the mapping or null. */ @FromAnyThread - public static @Nullable VariableMapping findInMappingByNLeftVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable) { + public static @Nullable VariableMapping findInMappingByNLeftVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable + ) { return shaderNode.getInputMapping().stream() .filter(mapping -> equalsByName(mapping.getLeftVariable(), variable)) .findAny().orElse(null); } + /** * Find an input mapping with the right variable by the name and the namespace. * @@ -154,8 +229,10 @@ public static boolean equalsByName(@NotNull final ShaderNodeVariable first, * @return the mapping or null. */ @FromAnyThread - public static @Nullable VariableMapping findInMappingByNNRightVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable) { + public static @Nullable VariableMapping findInMappingByNNRightVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable + ) { return shaderNode.getInputMapping().stream() .filter(mapping -> equalsByNameAndNameSpace(mapping.getRightVariable(), variable)) .findAny().orElse(null); @@ -169,8 +246,10 @@ public static boolean equalsByName(@NotNull final ShaderNodeVariable first, * @return the mapping or null. */ @FromAnyThread - public static @NotNull List findInMappingsByNNRightVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable) { + public static @NotNull List findInMappingsByNNRightVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable + ) { return shaderNode.getInputMapping().stream() .filter(mapping -> equalsByNameAndNameSpace(mapping.getRightVariable(), variable)) .collect(toList()); @@ -185,9 +264,11 @@ public static boolean equalsByName(@NotNull final ShaderNodeVariable first, * @return the mapping or null. */ @FromAnyThread - public static @NotNull List findInMappingsByNNRightVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable, - @NotNull final String nameSpace) { + public static @NotNull List findInMappingsByNNRightVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable, + @NotNull String nameSpace + ) { return shaderNode.getInputMapping().stream() .filter(mapping -> equalsByName(mapping.getRightVariable(), variable)) .filter(mapping -> mapping.getRightVariable().getNameSpace().equals(nameSpace)) @@ -202,8 +283,10 @@ public static boolean equalsByName(@NotNull final ShaderNodeVariable first, * @return the mapping or null. */ @FromAnyThread - public static @Nullable VariableMapping findInMappingByNNLeftVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable) { + public static @Nullable VariableMapping findInMappingByNNLeftVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable + ) { return shaderNode.getInputMapping().stream() .filter(mapping -> equalsByNameAndNameSpace(mapping.getLeftVariable(), variable)) .findAny().orElse(null); @@ -218,9 +301,11 @@ public static boolean equalsByName(@NotNull final ShaderNodeVariable first, * @return the mapping or null. */ @FromAnyThread - public static @Nullable VariableMapping findInMappingByNNLeftVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable, - @NotNull final String nameSpace) { + public static @Nullable VariableMapping findInMappingByNNLeftVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable, + @NotNull String nameSpace + ) { return shaderNode.getInputMapping().stream() .filter(mapping -> equalsByName(mapping.getLeftVariable(), variable)) .filter(mapping -> mapping.getLeftVariable().getNameSpace().equals(nameSpace)) @@ -235,8 +320,10 @@ public static boolean equalsByName(@NotNull final ShaderNodeVariable first, * @return true if the shader node has the output mapping with the left variable. */ @FromAnyThread - public static boolean hasOutMappingByLeftVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable) { + public static boolean hasOutMappingByLeftVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable + ) { return shaderNode.getOutputMapping() .stream().anyMatch(mapping -> equalsByNameAndNameSpace(mapping.getLeftVariable(), variable)); } @@ -249,12 +336,47 @@ public static boolean hasOutMappingByLeftVar(@NotNull final ShaderNode shaderNod * @return true if the shader nodes has the input mapping with the right variable. */ @FromAnyThread - public static boolean hasInMappingByRightVar(@NotNull final ShaderNode shaderNode, - @NotNull final ShaderNodeVariable variable) { + public static boolean hasInMappingByRightVar( + @NotNull ShaderNode shaderNode, + @NotNull ShaderNodeVariable variable + ) { return shaderNode.getInputMapping() .stream().anyMatch(mapping -> equalsByNameAndNameSpace(mapping.getRightVariable(), variable)); } + /** + * Make a new mapping with the expression. + * + * @param inputParameter the input parameter. + * @param expression the expression. + * @return the new mapping. + */ + @FromAnyThread + public static @NotNull VariableMapping makeExpressionMapping( + @NotNull InputShaderNodeParameter inputParameter, + @NotNull String expression + ) { + + var element = inputParameter.getNodeElement(); + var object = element.getObject(); + var variable = inputParameter.getVariable(); + + final String nameSpace; + + if (object instanceof ShaderNode) { + nameSpace = ((ShaderNode) object).getName(); + } else { + nameSpace = variable.getNameSpace(); + } + + var newMapping = new VariableMapping(); + newMapping.setLeftVariable(new ShaderNodeVariable(variable.getType(), nameSpace, variable.getName(), + null, variable.getPrefix())); + newMapping.setRightExpression(expression); + + return newMapping; + } + /** * Make a new mapping between the parameters. * @@ -263,8 +385,10 @@ public static boolean hasInMappingByRightVar(@NotNull final ShaderNode shaderNod * @return the new mapping. */ @FromAnyThread - public static @NotNull VariableMapping makeMapping(@NotNull final InputShaderNodeParameter inputParameter, - @NotNull final OutputShaderNodeParameter outputParameter) { + public static @NotNull VariableMapping makeMapping( + @NotNull InputShaderNodeParameter inputParameter, + @NotNull OutputShaderNodeParameter outputParameter + ) { final ShaderNodeElement inElement = inputParameter.getNodeElement(); final Object inObject = inElement.getObject(); @@ -311,7 +435,7 @@ public static boolean hasInMappingByRightVar(@NotNull final ShaderNode shaderNod * @return the UI type. */ @FromAnyThread - public static @NotNull String getAttributeUIType(@NotNull final VertexBuffer.Type attribute) { + public static @NotNull String getAttributeUiType(@NotNull final VertexBuffer.Type attribute) { switch (attribute) { case BoneWeight: case BindPoseNormal: @@ -393,10 +517,13 @@ public static boolean hasInMappingByRightVar(@NotNull final ShaderNode shaderNod * @return true of the list contains it. */ @FromAnyThread - public static boolean containsByNN(@NotNull final Collection variables, - @NotNull final String name, @NotNull final String nameSpace) { + public static boolean containsByNN( + @NotNull Collection variables, + @NotNull String name, + @NotNull String nameSpace + ) { - for (final ShaderNodeVariable variable : variables) { + for (var variable : variables) { if (!StringUtils.equals(variable.getNameSpace(), nameSpace)) { continue; @@ -418,17 +545,17 @@ public static boolean containsByNN(@NotNull final Collection * @return true if these types are accessible. */ @FromAnyThread - public static boolean isAccessibleType(@NotNull final String inType, @NotNull final String outType) { + public static boolean isAccessibleType(@NotNull String inType, @NotNull String outType) { if (!inType.contains("|") && !outType.contains("|")) { return inType.equals(outType); } - final String[] inTypes = inType.split("[|]"); - final String[] outTypes = outType.split("[|]"); + var inTypes = inType.split("[|]"); + var outTypes = outType.split("[|]"); - for (final String subInType : inTypes) { - for (final String subOutType : outTypes) { + for (var subInType : inTypes) { + for (var subOutType : outTypes) { if (subInType.equals(subOutType)) { return true; } @@ -445,9 +572,9 @@ public static boolean isAccessibleType(@NotNull final String inType, @NotNull fi * @return true of this variable is required. */ @FromAnyThread - public static boolean isRequired(@NotNull final ShaderNodeVariable variable) { + public static boolean isRequired(@NotNull ShaderNodeVariable variable) { - final GLSLType glslType = GLSLType.ofRawType(variable.getType()); + var glslType = GlslType.ofRawType(variable.getType()); switch (glslType) { case SAMPLER_2D: @@ -459,6 +586,16 @@ public static boolean isRequired(@NotNull final ShaderNodeVariable variable) { return StringUtils.isEmpty(variable.getDefaultValue()); } + /** + * Return true if the parameter is input parameter. + * + * @param parameter the parameter. + * @return true if the parameter is input parameter. + */ + public static boolean isInput(@NotNull ShaderNodeParameter parameter) { + return parameter instanceof InputShaderNodeParameter; + } + /** * Try to calculate a right swizzling for the mapping. * @@ -467,11 +604,13 @@ public static boolean isRequired(@NotNull final ShaderNodeVariable variable) { * @return the right swizzling or null. */ @FromAnyThread - public static @NotNull String calculateRightSwizzling(@NotNull final ShaderNodeVariable leftVar, - @NotNull final ShaderNodeVariable rightVar) { + public static @NotNull String calculateRightSwizzling( + @NotNull ShaderNodeVariable leftVar, + @NotNull ShaderNodeVariable rightVar + ) { - final String leftType = leftVar.getType(); - final String rightType = rightVar.getType(); + var leftType = leftVar.getType(); + var rightType = rightVar.getType(); if (leftType == null || rightType == null) { return ""; @@ -518,8 +657,10 @@ public static boolean isRequired(@NotNull final ShaderNodeVariable variable) { * @return the left swizzling or null. */ @FromAnyThread - public static @NotNull String calculateLeftSwizzling(@NotNull final ShaderNodeVariable leftVar, - @NotNull final ShaderNodeVariable rightVar) { + public static @NotNull String calculateLeftSwizzling( + @NotNull ShaderNodeVariable leftVar, + @NotNull ShaderNodeVariable rightVar + ) { //FIXME if (true) { @@ -559,4 +700,31 @@ public static boolean isRequired(@NotNull final ShaderNodeVariable variable) { return ""; } + + /** + * Return true if we can use expression for the node variable. + * + * @param nodeElement the node element. + * @param variable the shader node variable. + * @return true if we can use expression for the node variable. + */ + public static boolean canUseExpression( + @NotNull ShaderNodeElement nodeElement, + @NotNull ShaderNodeVariable variable + ) { + + if (!(nodeElement instanceof MainShaderNodeElement)) { + return false; + } + + switch (GlslType.ofRawType(variable.getType())) { + case SAMPLER_2D: + case SAMPLER_CUBE: { + return false; + } + default: { + return true; + } + } + } } diff --git a/src/main/resources/com/ss/editor/shader/nodes/messages/messages.properties b/src/main/resources/com/ss/editor/shader/nodes/messages/messages.properties index 828e4e2..945aa14 100644 --- a/src/main/resources/com/ss/editor/shader/nodes/messages/messages.properties +++ b/src/main/resources/com/ss/editor/shader/nodes/messages/messages.properties @@ -25,6 +25,7 @@ NodeElementGlobalOutput=Global outputs NodeElementVertexAttribute=Vertex attribute NodeElementWorldParameter=World parameter NodeElementMaterialParameter=Material parameter +NodeElementUseExpression=expr TreeNodePreviewMaterialSettings=Preview material settings diff --git a/src/main/resources/com/ss/editor/shader/nodes/messages/messages_ru.properties b/src/main/resources/com/ss/editor/shader/nodes/messages/messages_ru.properties index 820821a..d97ea22 100644 --- a/src/main/resources/com/ss/editor/shader/nodes/messages/messages_ru.properties +++ b/src/main/resources/com/ss/editor/shader/nodes/messages/messages_ru.properties @@ -25,6 +25,7 @@ NodeElementGlobalOutput=Результат NodeElementVertexAttribute=Вершинный атрибут NodeElementWorldParameter=Глобальный параметр NodeElementMaterialParameter=Параметр материала +NodeElementUseExpression=выр. TreeNodePreviewMaterialSettings=Настройки материала превью diff --git a/src/main/resources/com/ss/editor/shader/nodes/style.css b/src/main/resources/com/ss/editor/shader/nodes/style.css index ea2de47..873cc25 100644 --- a/src/main/resources/com/ss/editor/shader/nodes/style.css +++ b/src/main/resources/com/ss/editor/shader/nodes/style.css @@ -34,12 +34,28 @@ } .shader-node-parameter { - -fx-spacing: 2px; + -fx-hgap: 2px; } .shader-node-input-parameter { -fx-alignment: center-left; -fx-padding: 0px 0px 0px -4px; + -fx-hgap: 2px; +} + +.shader-node-input-parameter-expr-label { + -fx-min-width: 50px; + -fx-alignment: center-right; +} + +.shader-node-input-parameter-container { + -fx-alignment: center-left; + -fx-spacing: 2px; +} + +.shader-node-input-parameter > .hbox { + -fx-padding: 1px 3px 1px 8px; + -fx-alignment: center; } .shader-node-output-parameter { @@ -78,6 +94,10 @@ -fx-background-color: -fx-focus-color; } +.shader-node-parameter-input-socket:disabled { + -fx-opacity: -var-disabled-opacity; +} + .shader-node-parameter-output-socket:hover { -fx-background-color: -fx-focus-color; } @@ -120,4 +140,9 @@ .shader-node-def-documentation-dialog { -fx-min-height: 400px; -fx-min-width: 500px; +} + +.shader-node-def-documentation-tooltip { + -fx-min-height: 150px; + -fx-min-width: 500px; } \ No newline at end of file