David Catuhe 6 jaren geleden
bovenliggende
commit
0fb101edf3

+ 4 - 8
nodeEditor/src/components/preview/previewManager.ts

@@ -73,9 +73,6 @@ export class PreviewManager {
             this._engine.resize();
             this._scene.render();
         });
-
-        let serializationObject = this._nodeMaterial.serialize();
-        this._updatePreview(serializationObject);
     }
 
     private _handleAnimations() {
@@ -97,11 +94,6 @@ export class PreviewManager {
     }
 
     private _prepareMeshes() {
-        // Material
-        for (var mesh of this._meshes) {
-            mesh.material = this._material;
-        }
-
         // Light
         if (!this._scene.lights.length) {
             this._light = new HemisphericLight("light", new Vector3(0, 1, 0), this._scene);
@@ -129,6 +121,10 @@ export class PreviewManager {
 
         // Animations
         this._handleAnimations();
+
+        // Material        
+        let serializationObject = this._nodeMaterial.serialize();
+        this._updatePreview(serializationObject);
     }
 
     private _refreshPreviewMesh() {    

+ 2 - 1
src/Lights/pointLight.ts

@@ -192,7 +192,8 @@ export class PointLight extends ShadowLight {
 
     public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string) {
         if (this.computeTransformedInformation()) {
-            effect.setFloat3(lightDataUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z);        }
+            effect.setFloat3(lightDataUniformName, this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z);        
+        }
         else {
             effect.setFloat3(lightDataUniformName, this.position.x, this.position.y, this.position.z);
         }

+ 8 - 15
src/Materials/Node/Blocks/Vertex/lightInformationBlock.ts

@@ -17,7 +17,6 @@ import { PointLight } from '../../../../Lights/pointLight';
 export class LightInformationBlock extends NodeMaterialBlock {
     private _lightDataUniformName: string;
     private _lightColorUniformName: string;
-    private _lightIntensityUniformName: string;
 
     /**
      * Gets or sets the light associated with this block
@@ -91,15 +90,13 @@ export class LightInformationBlock extends NodeMaterialBlock {
 
         if (!light || !light.isEnabled) {
             effect.setFloat3(this._lightDataUniformName, 0, 0, 0);
-            effect.setFloat3(this._lightColorUniformName, 0, 0, 0);
-            effect.setFloat(this._lightIntensityUniformName, 0);
+            effect.setFloat4(this._lightColorUniformName, 0, 0, 0, 0);
             return;
         }
 
         light.transferToNodeMaterialEffect(effect, this._lightDataUniformName);
 
-        effect.setColor3(this._lightColorUniformName, light.diffuse);
-        effect.setFloat(this._lightIntensityUniformName, light.intensity);
+        effect.setColor4(this._lightColorUniformName, light.diffuse, light.intensity);
     }
 
     protected _buildBlock(state: NodeMaterialBuildState) {
@@ -117,19 +114,15 @@ export class LightInformationBlock extends NodeMaterialBlock {
             light = state.sharedData.scene.lights[0];
         }
 
+        this._lightDataUniformName = state._getFreeVariableName("lightData");
+        this._lightColorUniformName = state._getFreeVariableName("lightColor");
+
         if (!light) {
             state.compilationString += this._declareOutput(direction, state) + ` = vec3(0.);\r\n`;
             state.compilationString += this._declareOutput(color, state) + ` = vec3(0.);\r\n`;
-            state.compilationString += this._declareOutput(intensity, state) + ` = float(0.);\r\n`;
         } else {
-            this._lightDataUniformName = state._getFreeVariableName("lightData");
             state._emitUniformFromString(this._lightDataUniformName, "vec3");
-
-            this._lightColorUniformName = state._getFreeVariableName("lightColor");
-            state._emitUniformFromString(this._lightColorUniformName, "vec3");
-
-            this._lightIntensityUniformName = state._getFreeVariableName("lightIntensity");
-            state._emitUniformFromString(this._lightIntensityUniformName, "float");
+            state._emitUniformFromString(this._lightColorUniformName, "vec4");
 
             if (light instanceof PointLight) {
                 state.compilationString += this._declareOutput(direction, state) + ` = normalize(${this._lightDataUniformName} - ${this.worldPosition.associatedVariableName}.xyz);\r\n`;
@@ -137,8 +130,8 @@ export class LightInformationBlock extends NodeMaterialBlock {
                 state.compilationString += this._declareOutput(direction, state) + ` = ${this._lightDataUniformName};\r\n`;
             }
 
-            state.compilationString += this._declareOutput(color, state) + ` = ${this._lightColorUniformName};\r\n`;
-            state.compilationString += this._declareOutput(intensity, state) + ` = ${this._lightIntensityUniformName};\r\n`;
+            state.compilationString += this._declareOutput(color, state) + ` = ${this._lightColorUniformName}.rgb;\r\n`;
+            state.compilationString += this._declareOutput(intensity, state) + ` = ${this._lightColorUniformName}.a;\r\n`;
         }
 
         return this;