Jelajahi Sumber

New particleSystem.forceDepthWrite
New custom parameter for activating FlatShading for blender exporter

David Catuhe 11 tahun lalu
induk
melakukan
c8bde335b5

+ 5 - 3
Babylon/Mesh/babylon.mesh.js

@@ -176,10 +176,12 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.Mesh.prototype.isVerticesDataPresent = function (kind) {
-        if (!this._vertexBuffers && this._delayInfo) {
-            return this._delayInfo.indexOf(kind) !== -1;
+        if (!this._vertexBuffers) {
+            if (this._delayInfo) {
+                return this._delayInfo.indexOf(kind) !== -1;
+            }
+            return false;
         }
-
         return this._vertexBuffers[kind] !== undefined;
     };
 

+ 7 - 0
Babylon/Particles/babylon.particleSystem.js

@@ -93,6 +93,8 @@ var BABYLON = BABYLON || {};
 
     BABYLON.ParticleSystem.prototype.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE;
 
+    BABYLON.ParticleSystem.prototype.forceDepthWrite = false;
+
     // Methods   
     BABYLON.ParticleSystem.prototype.isAlive = function () {
         return this._alive;
@@ -329,6 +331,11 @@ var BABYLON = BABYLON || {};
         } else {
             engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);
         }
+
+        if (this.forceDepthWrite) {
+            this.setDepthWrite(true);
+        }
+
         engine.draw(true, 0, this.particles.length * 6);
         engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
 

+ 7 - 0
Babylon/Tools/babylon.sceneLoader.js

@@ -367,6 +367,7 @@ var BABYLON = BABYLON || {};
         }
 
         mesh.checkCollisions = parsedMesh.checkCollisions;
+        mesh._shouldGenerateFlatShading = parsedMesh.useFlatShading;
 
         // Parent
         if (parsedMesh.parentId) {
@@ -520,6 +521,12 @@ var BABYLON = BABYLON || {};
             // Update
             mesh.computeWorldMatrix(true);
 
+            // Flat shading
+            if (mesh._shouldGenerateFlatShading) {
+                mesh.convertToFlatShadedMesh();
+                delete mesh._shouldGenerateFlatShading;
+            }
+
             var scene = mesh.getScene();
             if (scene._selectionOctree) {
                 scene._selectionOctree.addMesh(mesh);

+ 16 - 4
Babylon/babylon.scene.js

@@ -249,6 +249,7 @@ var BABYLON = BABYLON || {};
         if (speedRatio === undefined) {
             speedRatio = 1.0;
         }
+
         // Local animations
         if (target.animations) {
             this.stopAnimation(target);
@@ -269,10 +270,21 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.Scene.prototype.stopAnimation = function (target) {
-        for (var index = 0; index < this._activeAnimatables.length; index++) {
-            if (this._activeAnimatables[index].target === target) {
-                this._activeAnimatables.splice(index, 1);
-                return;
+        // Local animations
+        if (target.animations) {
+            for (var index = 0; index < this._activeAnimatables.length; index++) {
+                if (this._activeAnimatables[index].target === target) {
+                    this._activeAnimatables.splice(index, 1);
+                    return;
+                }
+            }
+        }
+
+        // Children animations
+        if (target.getAnimatables) {
+            var animatables = target.getAnimatables();
+            for (var index = 0; index < animatables.length; index++) {
+                this.stopAnimation(animatables[index]);
             }
         }
     };

+ 8 - 2
Exporters/Blender/io_export_babylon.py

@@ -598,6 +598,7 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
         Export_babylon.write_vector(file_handler, "scaling", scale)
         Export_babylon.write_bool(file_handler, "isVisible", object.is_visible(scene))
         Export_babylon.write_bool(file_handler, "isEnabled", True)
+        Export_babylon.write_bool(file_handler, "useFlatShading", object.data.useFlatShading)
         Export_babylon.write_bool(file_handler, "checkCollisions", object.data.checkCollisions)
         Export_babylon.write_int(file_handler, "billboardMode", billboardMode)
         Export_babylon.write_bool(file_handler, "receiveShadows", object.data.receiveShadows)
@@ -974,6 +975,10 @@ class Export_babylon(bpy.types.Operator, ExportHelper):
         return {'FINISHED'}
 
 # UI
+bpy.types.Mesh.useFlatShading = BoolProperty(
+    name="Use Flat Shading", 
+    default = False)
+
 bpy.types.Mesh.checkCollisions = BoolProperty(
     name="Check Collisions", 
     default = False)
@@ -1023,10 +1028,11 @@ class ObjectPanel(bpy.types.Panel):
         isCamera = isinstance(ob.data, bpy.types.Camera)
         isLight = isinstance(ob.data, bpy.types.Lamp)
         
-        if isMesh:
+        if isMesh:   
+            layout.prop(ob.data, 'useFlatShading') 
             layout.prop(ob.data, 'checkCollisions')     
             layout.prop(ob.data, 'castShadows')     
-            layout.prop(ob.data, 'receiveShadows')      
+            layout.prop(ob.data, 'receiveShadows')   
         elif isCamera:
             layout.prop(ob.data, 'checkCollisions')
             layout.prop(ob.data, 'applyGravity')