瀏覽代碼

Complete integration of binary format

David Catuhe 11 年之前
父節點
當前提交
3b883ea25a

+ 63 - 0
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -608,6 +608,10 @@
                 mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;
                 mesh._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMinimum), BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMaximum));
 
+                if (parsedMesh._binaryInfo) {
+                    mesh._binaryInfo = parsedMesh._binaryInfo;
+                }
+
                 mesh._delayInfo = [];
                 if (parsedMesh.hasUVs) {
                     mesh._delayInfo.push(BABYLON.VertexBuffer.UVKind);
@@ -793,6 +797,65 @@
                 if (geometry) {
                     geometry.applyToMesh(mesh);
                 }
+            } else if (parsedGeometry instanceof ArrayBuffer) {
+                var binaryInfo = mesh._binaryInfo;
+
+                if (binaryInfo.positionsAttrDesc && binaryInfo.positionsAttrDesc.count > 0) {
+                    var positionsData = new Float32Array(parsedGeometry, binaryInfo.positionsAttrDesc.offset, binaryInfo.positionsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positionsData, false);
+                }
+
+                if (binaryInfo.normalsAttrDesc && binaryInfo.normalsAttrDesc.count > 0) {
+                    var normalsData = new Float32Array(parsedGeometry, binaryInfo.normalsAttrDesc.offset, binaryInfo.normalsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normalsData, false);
+                }
+
+                if (binaryInfo.uvsAttrDesc && binaryInfo.uvsAttrDesc.count > 0) {
+                    var uvsData = new Float32Array(parsedGeometry, binaryInfo.uvsAttrDesc.offset, binaryInfo.uvsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvsData, false);
+                }
+
+                if (binaryInfo.uvs2AttrDesc && binaryInfo.uvs2AttrDesc.count > 0) {
+                    var uvs2Data = new Float32Array(parsedGeometry, binaryInfo.uvs2AttrDesc.offset, binaryInfo.uvs2AttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.UV2Kind, uvs2Data, false);
+                }
+
+                if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {
+                    var colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false);
+                }
+
+                if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {
+                    var matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesAttrDesc.offset, binaryInfo.matricesIndicesAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndicesData, false);
+                }
+
+                if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {
+                    var matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);
+                }
+
+                if (binaryInfo.indicesAttrDesc && binaryInfo.indicesAttrDesc.count > 0) {
+                    var indicesData = new Int32Array(parsedGeometry, binaryInfo.indicesAttrDesc.offset, binaryInfo.indicesAttrDesc.count);
+                    mesh.setIndices(indicesData);
+                }
+
+                if (binaryInfo.subMeshesAttrDesc && binaryInfo.subMeshesAttrDesc.count > 0) {
+                    var subMeshesData = new Int32Array(parsedGeometry, binaryInfo.subMeshesAttrDesc.offset, binaryInfo.subMeshesAttrDesc.count * 5);
+
+                    mesh.subMeshes = [];
+                    for (var i = 0; i < binaryInfo.subMeshesAttrDesc.count; i++) {
+                        var materialIndex = subMeshesData[(i * 5) + 0];
+                        var verticesStart = subMeshesData[(i * 5) + 1];
+                        var verticesCount = subMeshesData[(i * 5) + 2];
+                        var indexStart = subMeshesData[(i * 5) + 3];
+                        var indexCount = subMeshesData[(i * 5) + 4];
+
+                        var subMesh = new BABYLON.SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh);
+                    }
+                }
+
+                return;
             } else if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {
                 mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, parsedGeometry.positions, false);
                 mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, parsedGeometry.normals, false);

+ 28 - 29
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -269,19 +269,19 @@
             var data;
 
             switch (dataType) {
-            case BABYLON.Animation.ANIMATIONTYPE_FLOAT:
-                data = key.values[0];
-                break;
-            case BABYLON.Animation.ANIMATIONTYPE_QUATERNION:
-                data = BABYLON.Quaternion.FromArray(key.values);
-                break;
-            case BABYLON.Animation.ANIMATIONTYPE_MATRIX:
-                data = BABYLON.Matrix.FromArray(key.values);
-                break;
-            case BABYLON.Animation.ANIMATIONTYPE_VECTOR3:
-            default:
-                data = BABYLON.Vector3.FromArray(key.values);
-                break;
+                case BABYLON.Animation.ANIMATIONTYPE_FLOAT:
+                    data = key.values[0];
+                    break;
+                case BABYLON.Animation.ANIMATIONTYPE_QUATERNION:
+                    data = BABYLON.Quaternion.FromArray(key.values);
+                    break;
+                case BABYLON.Animation.ANIMATIONTYPE_MATRIX:
+                    data = BABYLON.Matrix.FromArray(key.values);
+                    break;
+                case BABYLON.Animation.ANIMATIONTYPE_VECTOR3:
+                default:
+                    data = BABYLON.Vector3.FromArray(key.values);
+                    break;
             }
 
             keys.push({
@@ -299,20 +299,20 @@
         var light;
 
         switch (parsedLight.type) {
-        case 0:
-            light = new BABYLON.PointLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.position), scene);
-            break;
-        case 1:
-            light = new BABYLON.DirectionalLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
-            light.position = BABYLON.Vector3.FromArray(parsedLight.position);
-            break;
-        case 2:
-            light = new BABYLON.SpotLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.position), BABYLON.Vector3.FromArray(parsedLight.direction), parsedLight.angle, parsedLight.exponent, scene);
-            break;
-        case 3:
-            light = new BABYLON.HemisphericLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
-            light.groundColor = BABYLON.Color3.FromArray(parsedLight.groundColor);
-            break;
+            case 0:
+                light = new BABYLON.PointLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.position), scene);
+                break;
+            case 1:
+                light = new BABYLON.DirectionalLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
+                light.position = BABYLON.Vector3.FromArray(parsedLight.position);
+                break;
+            case 2:
+                light = new BABYLON.SpotLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.position), BABYLON.Vector3.FromArray(parsedLight.direction), parsedLight.angle, parsedLight.exponent, scene);
+                break;
+            case 3:
+                light = new BABYLON.HemisphericLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
+                light.groundColor = BABYLON.Color3.FromArray(parsedLight.groundColor);
+                break;
         }
 
         light.id = parsedLight.id;
@@ -1156,8 +1156,7 @@
 
                 if (camera instanceof BABYLON.FreeCamera) {
                     var freecamera = <FreeCamera>camera;
-                    if (freecamera._waitingLockedTargetId)
-                    {
+                    if (freecamera._waitingLockedTargetId) {
                         freecamera.lockedTarget = scene.getLastEntryByID(freecamera._waitingLockedTargetId);
                         delete freecamera._waitingLockedTargetId;
                     }

+ 9 - 2
Babylon/Mesh/babylon.mesh.js

@@ -514,12 +514,19 @@ var BABYLON;
 
                 scene._addPendingData(that);
 
+                var getBinaryData = (this.delayLoadingFile.indexOf(".babylonbinarymeshdata") !== -1) ? true : false;
+
                 BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
-                    _this._delayLoadingFunction(JSON.parse(data), _this);
+                    if (data instanceof ArrayBuffer) {
+                        _this._delayLoadingFunction(data, _this);
+                    } else {
+                        _this._delayLoadingFunction(JSON.parse(data), _this);
+                    }
+
                     _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
                     scene._removePendingData(_this);
                 }, function () {
-                }, scene.database);
+                }, scene.database, getBinaryData);
             }
         };
 

+ 1 - 1
Babylon/Mesh/babylon.mesh.ts

@@ -10,7 +10,7 @@
         public delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
         public instances = new Array<InstancedMesh>();
         public delayLoadingFile: string;
-        public _binaryInfo : BinaryAttrData;
+        public _binaryInfo: any;
 
         // Private
         public _geometry: Geometry;

+ 0 - 528
Exporters/BinaryConverter/BabylonLodMesh.cs

@@ -1,528 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Runtime.Serialization;
-using System.Net;
-
-using Vertice.Core;
-using BabylonExport.Core;
-using Newtonsoft.Json;
-
-
-namespace BabylonBinaryConverter
-{
-    public enum VertexAttributes
-    {
-        Undefined = 0,
-        Position = 2,
-        Color = 4,
-        Normal = 8,
-        Uv1 = 16,
-        Uv2 = 32,
-        HPos = 64
-    }
-
-    public enum DataType
-    {
-        Byte,
-        UByte,
-        Int16,
-        UInt16,
-        Int32,
-        UInt32,
-        Int64,
-        UInt64,
-        Float,
-        Double
-    }
-
-
-    [DataContract]
-    public class IncrMeshData
-    {
-        [DataMember]
-        public float[] positions { get; set; }
-
-        [DataMember]
-        public float[] colors { get; set; }
-
-        [DataMember]
-        public float[] normals { get; set; }
-
-        [DataMember]
-        public float[] uvs { get; set; }
-
-        [DataMember]
-        public float[] uvs2 { get; set; }
-
-        [DataMember]
-        public int[] indices { get; set; }
-
-        [DataMember]
-        public int[] matricesIndices { get; set; }
-
-        [DataMember]
-        public float[] matricesWeights { get; set; }
-
-        [DataMember]
-        public BabylonSubMesh[] subMeshes { get; set; }
-    }
-
-
-    [DataContract]
-    public class AttrDesc
-    {
-        [DataMember]
-        public int count;
-
-        [DataMember]
-        public int stride;
-
-        [DataMember]
-        public long offset;
-
-        [DataMember]
-        public DataType dataType;
-
-        
-        public AttrDesc()
-        {
-            count = 0;
-            stride = 0;
-            offset = 0;
-            dataType = DataType.Float;
-        }
-
-
-        public AttrDesc(int _count, int _stride, long _offset, DataType _dataType)
-        {
-            count = _count;
-            stride = _stride;
-            offset = _offset;
-            dataType = _dataType;
-        }
-    }
-
-
-    [DataContract]
-    public class BabylonLodMesh : BabylonMesh
-    {
-        [DataMember]
-        public int lod { get; set; }
-
-        [DataMember]
-        public float distance { get; set; }
-
-        [DataMember]
-        public string delayLoadingFile { get; set; }
-
-        [DataMember]
-        public float[] boundingBoxMinimum { get; set; }
-
-        [DataMember]
-        public float[] boundingBoxMaximum { get; set; }
-
-        [DataMember]
-        public bool hasUVs { get; set; }
-
-        [DataMember]
-        public bool hasUVs2 { get; set; }
-
-        [DataMember]
-        public bool hasColors { get; set; }
-
-        [DataMember]
-        public bool hasMatricesIndices { get; set; }
-
-        [DataMember]
-        public bool hasMatricesWeights { get; set; }
-
-        [DataMember]
-        public AttrDesc positionsAttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc colorsAttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc normalsAttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc uvsAttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc uvs2AttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc indicesAttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc matricesIndicesAttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc matricesWeightsAttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc subMeshesAttrDesc { get; set; }
-
-        [DataMember]
-        public AttrDesc combinedAttrDesc { get; set; }
-
-        [DataMember]
-        public VertexAttributes vertexAttributes { get; set; }
-        
-        const string fileEXT = ".binarymesh.babylon";
-
-        
-        public BabylonLodMesh() : base()
-        {
-            lod = 0;
-            distance = 0.0f;
-            delayLoadingFile = "";
-
-            positionsAttrDesc = new AttrDesc();
-            colorsAttrDesc = new AttrDesc();
-            normalsAttrDesc = new AttrDesc();
-            uvsAttrDesc = new AttrDesc();
-            uvs2AttrDesc = new AttrDesc();
-
-            indicesAttrDesc = new AttrDesc();
-
-            matricesIndicesAttrDesc = new AttrDesc();
-            matricesWeightsAttrDesc = new AttrDesc();
-
-            subMeshesAttrDesc = new AttrDesc();
-
-            combinedAttrDesc = new AttrDesc();
-            vertexAttributes = VertexAttributes.Undefined;
-        }
-
-
-        public void Convert(string srcPath, string dstPath, bool _combined = false, int _lod = 0, float _distance = 0.0f)
-        {
-            lod = _lod;
-            distance = _distance;
-
-            if (Path.GetExtension(delayLoadingFile).CompareTo(".babylonmeshdata") == 0)
-                LoadMeshData(Path.Combine(srcPath, delayLoadingFile));
-
-            if (string.IsNullOrEmpty(delayLoadingFile))
-                //delayLoadingFile = name + fileEXT;
-                delayLoadingFile = id + fileEXT;
-            else
-                delayLoadingFile = Path.GetFileNameWithoutExtension(delayLoadingFile) + fileEXT;
-
-            
-            string fullPath = Path.Combine(dstPath, delayLoadingFile);
-
-            if (localMatrix == null)
-                localMatrix = Matrix.Identity.ToArray();
-
-            CalculateBoundingBox();
-
-            if (!_combined)
-                WriteMultipleBuffers(fullPath);
-
-            else
-                VertexBuffer(fullPath);
-        }
-
-
-        private void LoadMeshData(string srcFilename)
-        {
-            try
-            {
-                string filename = WebUtility.UrlDecode(srcFilename);
-
-                IncrMeshData incrMeshData = JsonConvert.DeserializeObject<IncrMeshData>(File.ReadAllText(filename));
-
-                positions = incrMeshData.positions;
-                colors = incrMeshData.colors;
-                normals = incrMeshData.normals;
-                uvs = incrMeshData.uvs;
-                uvs2 = incrMeshData.uvs2;
-                indices = incrMeshData.indices;
-
-                matricesIndices = incrMeshData.matricesIndices;
-                matricesWeights = incrMeshData.matricesWeights;
-
-                subMeshes = incrMeshData.subMeshes;
-            }
-            catch (Exception ex)
-            {
-                Console.ForegroundColor = ConsoleColor.Red;
-                Console.WriteLine();
-                Console.WriteLine(ex.Message);
-                Console.ForegroundColor = ConsoleColor.DarkCyan;
-                Console.WriteLine(ex);
-                Console.ResetColor();
-            }
-        }
-        
-        
-        private void WriteMultipleBuffers(string fullPath)
-        {
-            try
-            {
-                using (var stream = File.Open(WebUtility.UrlDecode(fullPath), FileMode.Create))
-                {
-                    BinaryWriter writer = new BinaryWriter(stream);
-
-                    if (positions != null && positions.Length > 0)
-                    {
-                        positionsAttrDesc.count = positions.Length;
-                        positionsAttrDesc.stride = 3;
-                        positionsAttrDesc.offset = stream.Length;
-                        positionsAttrDesc.dataType = DataType.Float;
-
-                        for (int x = 0; x < positions.Length; x++)
-                            writer.Write(positions[x]);
-
-                        positions = null;
-                    }
-
-                    if (colors != null && colors.Length > 0)
-                    {
-                        colorsAttrDesc.count = colors.Length;
-                        colorsAttrDesc.stride = 3;
-                        colorsAttrDesc.offset = stream.Length;
-                        colorsAttrDesc.dataType = DataType.Float;
-
-                        for (int x = 0; x < colors.Length; x++)
-                            writer.Write(colors[x]);
-
-                        hasColors = true;
-
-                        colors = null;
-                    }
-
-                    if (normals != null && normals.Length > 0)
-                    {
-                        normalsAttrDesc.count = normals.Length;
-                        normalsAttrDesc.stride = 3;
-                        normalsAttrDesc.offset = stream.Length;
-                        normalsAttrDesc.dataType = DataType.Float;
-
-                        for (int x = 0; x < normals.Length; x++)
-                            writer.Write(normals[x]);
-
-                        normals = null;
-                    }
-
-                    if (uvs != null && uvs.Length > 0)
-                    {
-                        uvsAttrDesc.count = uvs.Length;
-                        uvsAttrDesc.stride = 2;
-                        uvsAttrDesc.offset = stream.Length;
-                        uvsAttrDesc.dataType = DataType.Float;
-
-                        for (int x = 0; x < uvs.Length; x++)
-                            writer.Write(uvs[x]);
-
-                        hasUVs = true;
-
-                        writer.Flush();
-
-                        uvs = null;
-                    }
-
-                    if (uvs2 != null && uvs2.Length > 0)
-                    {
-                        uvs2AttrDesc.count = uvs2.Length;
-                        uvs2AttrDesc.stride = 2;
-                        uvs2AttrDesc.offset = stream.Length;
-                        uvs2AttrDesc.dataType = DataType.Float;
-
-                        for (int x = 0; x < uvs2.Length; x++)
-                            writer.Write(uvs2[x]);
-
-                        hasUVs2 = true;
-
-                        writer.Flush();
-
-                        uvs2 = null;
-                    }
-
-                    if (indices != null && indices.Length > 0)
-                    {
-                        indicesAttrDesc.count = indices.Length;
-                        indicesAttrDesc.stride = 1;
-                        indicesAttrDesc.offset = stream.Length;
-                        indicesAttrDesc.dataType = DataType.Int32;
-
-                        for (int x = 0; x < indices.Length; x++)
-                            writer.Write(indices[x]);
-
-                        indices = null;
-                    }
-
-                    if (matricesIndices != null && matricesIndices.Length > 0)
-                    {
-                        matricesIndicesAttrDesc.count = matricesIndices.Length;
-                        matricesIndicesAttrDesc.stride = 1;
-                        matricesIndicesAttrDesc.offset = stream.Length;
-                        matricesIndicesAttrDesc.dataType = DataType.Int32;
-
-                        for (int x = 0; x < matricesIndices.Length; x++)
-                            writer.Write(matricesIndices[x]);
-
-                        hasMatricesIndices = true;
-
-                        matricesIndices = null;
-                    }
-
-                    if (matricesWeights != null && matricesWeights.Length > 0)
-                    {
-                        matricesWeightsAttrDesc.count = matricesWeights.Length;
-                        matricesWeightsAttrDesc.stride = 2;
-                        matricesWeightsAttrDesc.offset = stream.Length;
-                        matricesWeightsAttrDesc.dataType = DataType.Float;
-
-                        for (int x = 0; x < matricesWeights.Length; x++)
-                            writer.Write(matricesWeights[x]);
-
-                        hasMatricesWeights = true;
-
-                        matricesWeights = null;
-                    }
-
-                    if(subMeshes != null && subMeshes.Length > 0)
-                    {
-                        subMeshesAttrDesc.count = subMeshes.Length;
-                        subMeshesAttrDesc.stride = 5;
-                        subMeshesAttrDesc.offset = stream.Length;
-                        subMeshesAttrDesc.dataType = DataType.Int32;
-
-                        int[] smData = new int[5];
-
-                        for (int x = 0; x < subMeshes.Length; x++)
-                        {
-                            smData[0] = subMeshes[x].materialIndex;
-                            smData[1] = subMeshes[x].verticesStart;
-                            smData[2] = subMeshes[x].verticesCount;
-                            smData[3] = subMeshes[x].indexStart;
-                            smData[4] = subMeshes[x].indexCount;
-
-                            for (int y = 0; y < smData.Length; y++)
-                                writer.Write(smData[y]);
-                        }
-
-                        subMeshes = null;
-                    }
-                }
-            }
-            catch (Exception ex)
-            {
-                Console.ForegroundColor = ConsoleColor.Red;
-                Console.WriteLine();
-                Console.WriteLine(ex.Message);
-                Console.ForegroundColor = ConsoleColor.DarkCyan;
-                Console.WriteLine(ex);
-                Console.ResetColor();
-            }
-        }
-
-        
-        private void VertexBuffer(string fullPath)
-        {
-            combinedAttrDesc.count = positions.Length;
-            combinedAttrDesc.stride = 0;
-            combinedAttrDesc.offset = 0;
-
-            vertexAttributes = VertexAttributes.Undefined;
-
-
-            if (positions != null && positions.Length > 0)
-            {
-                vertexAttributes |= VertexAttributes.Position;
-                combinedAttrDesc.stride += 3;
-            }
-
-            if (colors != null && colors.Length > 0)
-            {
-                vertexAttributes |= VertexAttributes.Color;
-                combinedAttrDesc.stride += 4;
-            }
-
-            if (normals != null && normals.Length > 0)
-            {
-                vertexAttributes |= VertexAttributes.Normal;
-                combinedAttrDesc.stride += 3;
-            }
-
-            if (uvs != null && uvs.Length > 0)
-            {
-                vertexAttributes |= VertexAttributes.Uv1;
-                combinedAttrDesc.stride += 2;
-            }
-
-            if (uvs2 != null && uvs2.Length > 0)
-            {
-                vertexAttributes |= VertexAttributes.Uv2;
-                combinedAttrDesc.stride += 2;
-            }
-
-            
-            List<float> data = new List<float>();
-
-            using (var stream = File.Open(WebUtility.UrlDecode(fullPath), FileMode.Create))
-            {
-            }
-        }
-
-
-        private void CalculateBoundingBox()
-        {
-            Vector3 min = new Vector3(0.0f, 0.0f, 0.0f);
-            Vector3 max = new Vector3(0.0f, 0.0f, 0.0f);
-
-            if (positions != null && positions.Length > 0)
-            {
-                Vector3 src = new Vector3(positions[0], positions[1], positions[2]);
-                min = src;
-                max = src;
-
-                for (int x = 3; x < positions.Length; x += 3)
-                {
-                    if (x + 2 < positions.Length)
-                    {
-                        src.X = positions[x + 0];
-                        src.Y = positions[x + 1];
-                        src.Z = positions[x + 2];
-
-                        VecMin(src, ref min);
-                        VecMax(src, ref max);
-                    }
-                }
-            }
-
-            boundingBoxMinimum = min.ToArray();
-            boundingBoxMaximum = max.ToArray();
-        }
-
-
-        private void VecMin(Vector3 src, ref Vector3 dst)
-        {
-            if (src.X < dst.X)
-                dst.X = src.X;
-
-            if (src.Y < dst.Y)
-                dst.Y = src.Y;
-
-            if (src.Z < dst.Z)
-                dst.Z = src.Z;
-        }
-
-
-        private void VecMax(Vector3 src, ref Vector3 dst)
-        {
-            if (src.X > dst.X)
-                dst.X = src.X;
-
-            if (src.Y > dst.Y)
-                dst.Y = src.Y;
-
-            if (src.Z > dst.Z)
-                dst.Z = src.Z;
-        }
-    }
-}

+ 0 - 32
Exporters/BinaryConverter/BabylonLodScene.cs

@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.Serialization;
-
-using BabylonExport.Core;
-
-namespace BabylonBinaryConverter
-{
-    [DataContract]
-    public class BabylonLodScene : BabylonScene
-    {
-        [DataMember]
-        public new BabylonLodMesh[] meshes { get; set; }
-
-        [DataMember]
-        public bool useDelayedTextureLoading { get; set; }
-
-
-        public BabylonLodScene(string outputPath) : base(outputPath)
-        {
-        }
-
-
-        public void Convert(string srcPath, string dstPath)
-        {
-            for (int x = 0; x < meshes.Length; x++)
-            {
-                meshes[x].Convert(srcPath, dstPath);
-            }
-        }
-    }
-}

+ 0 - 126
Exporters/BinaryConverter/BinaryConverter.csproj

@@ -1,126 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{78DEBAD0-4265-4237-9FB3-2AEB63EED7EF}</ProjectGuid>
-    <OutputType>Exe</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>BabylonBinaryConverter</RootNamespace>
-    <AssemblyName>BabylonBinaryConverter</AssemblyName>
-    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <IsWebBootstrapper>false</IsWebBootstrapper>
-    <PublishUrl>C:\Temp\Converter\</PublishUrl>
-    <Install>true</Install>
-    <InstallFrom>Disk</InstallFrom>
-    <UpdateEnabled>false</UpdateEnabled>
-    <UpdateMode>Foreground</UpdateMode>
-    <UpdateInterval>7</UpdateInterval>
-    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
-    <UpdatePeriodically>false</UpdatePeriodically>
-    <UpdateRequired>false</UpdateRequired>
-    <MapFileExtensions>true</MapFileExtensions>
-    <ApplicationRevision>1</ApplicationRevision>
-    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
-    <UseApplicationTrust>false</UseApplicationTrust>
-    <PublishWizardCompleted>true</PublishWizardCompleted>
-    <BootstrapperEnabled>true</BootstrapperEnabled>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <PropertyGroup>
-    <ManifestCertificateThumbprint>7346144549A904B3EB11D4D318746B02AF5F1A25</ManifestCertificateThumbprint>
-  </PropertyGroup>
-  <PropertyGroup>
-    <ManifestKeyFile>BinaryConverter_TemporaryKey.pfx</ManifestKeyFile>
-  </PropertyGroup>
-  <PropertyGroup>
-    <GenerateManifests>false</GenerateManifests>
-  </PropertyGroup>
-  <PropertyGroup>
-    <SignManifests>true</SignManifests>
-  </PropertyGroup>
-  <PropertyGroup>
-    <TargetZone>LocalIntranet</TargetZone>
-  </PropertyGroup>
-  <PropertyGroup>
-    <ApplicationManifest>Properties\app.manifest</ApplicationManifest>
-  </PropertyGroup>
-  <ItemGroup>
-    <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
-      <HintPath>..\packages\Newtonsoft.Json.5.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
-    </Reference>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
-    <Reference Include="System.Runtime.Serialization" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Xml" />
-    <Reference Include="Vertice.Core">
-      <HintPath>..\XNA - OBJ\BabylonExport.Core\Refs\Vertice.Core.dll</HintPath>
-    </Reference>
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="BabylonLodMesh.cs" />
-    <Compile Include="BabylonLodScene.cs" />
-    <Compile Include="Program.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="App.config" />
-    <None Include="packages.config" />
-    <None Include="Properties\app.manifest" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\XNA - OBJ\BabylonExport.Core\BabylonExport.Core.csproj">
-      <Project>{ce70b051-fb63-420d-80c0-51cc03a214ba}</Project>
-      <Name>BabylonExport.Core</Name>
-    </ProjectReference>
-  </ItemGroup>
-  <ItemGroup>
-    <BootstrapperPackage Include=".NETFramework,Version=v4.5">
-      <Visible>False</Visible>
-      <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
-      <Install>true</Install>
-    </BootstrapperPackage>
-    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
-      <Visible>False</Visible>
-      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
-      <Install>false</Install>
-    </BootstrapperPackage>
-    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
-      <Visible>False</Visible>
-      <ProductName>.NET Framework 3.5 SP1</ProductName>
-      <Install>false</Install>
-    </BootstrapperPackage>
-  </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>

+ 0 - 124
Exporters/BinaryConverter/Program.cs

@@ -1,124 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Net;
-using System.IO;
-
-using Newtonsoft.Json;
-using BabylonExport.Core;
-
-
-namespace BabylonBinaryConverter
-{
-    class Program
-    {
-        static void Main(string[] args)
-        {
-            string srcFilename = "";
-            string dstPath = "";
-            bool formatted = false;
-
-            try
-            {
-                if (args.Length < 2)
-                {
-                    DisplayUsage();
-                    return;
-                }
-
-                foreach (var arg in args)
-                {
-                    if(arg.ToLower() == "/formatted")
-                    {
-                        formatted = true;
-                    }
-                    else if (arg.Substring(0, 3).ToLower() == "/i:")
-                    {
-                        srcFilename = arg.Substring(3);
-                    }
-                    else if (arg.Substring(0, 3).ToLower() == "/o:")
-                    {
-                        dstPath = arg.Substring(3);
-                    }
-                    else
-                    {
-                        DisplayUsage();
-                    }
-                }
-
-                if (string.IsNullOrEmpty(srcFilename) || string.IsNullOrEmpty(dstPath))
-                {
-                    DisplayUsage();
-                    return;
-                }
-
-                string srcPath = Path.GetDirectoryName(srcFilename);
-                string dstFilename = "";
-                
-                if (!srcFilename.Contains(".incremental.babylon"))
-                    dstFilename = Path.Combine(dstPath, Path.GetFileNameWithoutExtension(srcFilename) + ".incremental.babylon");
-                else
-                    dstFilename = Path.Combine(dstPath, Path.GetFileName(srcFilename));
-
-                if (!Directory.Exists(dstPath))
-                {
-                    Directory.CreateDirectory(dstPath);
-                }
-
-                Console.WriteLine("Converting file " + WebUtility.UrlDecode(srcFilename) + " to binary in folder " + dstPath);
-
-                ParseBabylonSceneFileAsJson(srcPath, srcFilename, dstPath, dstFilename, formatted);
-
-                using (var debugFile = new StreamWriter(dstPath + @"\debug.txt", true))
-                {
-                    debugFile.Write("Generation of " + dstFilename + " successfull");
-                }
-            }
-            catch (Exception ex)
-            {
-                Console.ForegroundColor = ConsoleColor.Red;
-                Console.WriteLine();
-                Console.WriteLine(ex.Message);
-                Console.ResetColor();
-
-                using (var debugFile = new StreamWriter(dstPath + @"\debug.txt", true))
-                {
-                    debugFile.Write(ex);
-                }
-            }
-        }
-
-
-        static void ParseBabylonSceneFileAsJson(string srcPath, string srcFilename, string dstPath, string dstFilename, bool formatted)
-        {
-            try
-            {
-                BabylonLodScene scene = JsonConvert.DeserializeObject<BabylonLodScene>(File.ReadAllText(WebUtility.UrlDecode(srcFilename)));
-                scene.autoClear = true;
-                scene.useDelayedTextureLoading = true;
-
-                scene.Convert(srcPath, dstPath);
-
-                File.WriteAllText(WebUtility.UrlDecode(dstFilename), JsonConvert.SerializeObject(scene, (formatted ? Formatting.Indented : Formatting.None)));
-            }
-            catch (Exception ex)
-            {
-                Console.ForegroundColor = ConsoleColor.Red;
-                Console.WriteLine();
-                Console.WriteLine(ex.Message);
-                Console.ForegroundColor = ConsoleColor.DarkCyan;
-                Console.WriteLine(ex);
-                Console.ResetColor();
-            }
-        }
-        
-        
-        static void DisplayUsage()
-        {
-            Console.WriteLine("Babylon binary converter usage: BabylonBinaryConverter.exe /i:\"source file\" /o:\"output folder\" /formatted");
-            Console.WriteLine("   /formatted to write formatted Json. The default is compressed.");
-        }
-    }
-}

+ 0 - 54
Exporters/BinaryConverter/Properties/app.manifest

@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
-  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
-    <security>
-      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
-        <!-- UAC Manifest Options
-            If you want to change the Windows User Account Control level replace the 
-            requestedExecutionLevel node with one of the following.
-
-        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
-        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
-        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
-
-            Specifying requestedExecutionLevel node will disable file and registry virtualization.
-            If you want to utilize File and Registry Virtualization for backward 
-            compatibility then delete the requestedExecutionLevel node.
-        -->
-        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
-      </requestedPrivileges>
-      <applicationRequestMinimum>
-        <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
-        <defaultAssemblyRequest permissionSetReference="Custom" />
-      </applicationRequestMinimum>
-    </security>
-  </trustInfo>
-  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
-    <application>
-      <!-- A list of all Windows versions that this application is designed to work with. 
-      Windows will automatically select the most compatible environment.-->
-      <!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
-      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
-      <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
-      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
-      <!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
-      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
-      <!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
-      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
-    </application>
-  </compatibility>
-  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
-  <!-- <dependency>
-    <dependentAssembly>
-      <assemblyIdentity
-          type="win32"
-          name="Microsoft.Windows.Common-Controls"
-          version="6.0.0.0"
-          processorArchitecture="*"
-          publicKeyToken="6595b64144ccf1df"
-          language="*"
-        />
-    </dependentAssembly>
-  </dependency>-->
-</asmv1:assembly>

+ 0 - 4
Exporters/BinaryConverter/packages.config

@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="Newtonsoft.Json" version="5.0.4" targetFramework="net45" />
-</packages>

Exporters/BinaryConverter/App.config → Tools/ConvertToBinary/App.config


+ 67 - 0
Tools/ConvertToBinary/ConvertToBinary.csproj

@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{6A8A02E3-324F-4807-8AF9-AAD3CAF86376}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ConvertToBinary</RootNamespace>
+    <AssemblyName>ConvertToBinary</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <SccProjectName>SAK</SccProjectName>
+    <SccLocalPath>SAK</SccLocalPath>
+    <SccAuxPath>SAK</SccAuxPath>
+    <SccProvider>SAK</SccProvider>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Newtonsoft.Json.5.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Web" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 447 - 0
Tools/ConvertToBinary/Program.cs

@@ -0,0 +1,447 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Web;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System.Collections.Generic;
+using System.Net;
+
+namespace ConvertToBinary
+{
+    public enum DataType { Int32, Float };
+
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 1)
+            {
+                DisplayUsage();
+                return;
+            }
+
+            // Parsing arguments
+            string srcFilename = "";
+            string dstPath = "";
+
+            foreach (var arg in args)
+            {
+                var order = arg.Substring(0, 3);
+
+                switch (order)
+                {
+                    case "/i:":
+                        srcFilename = arg.Substring(3);
+                        break;
+                    case "/o:":
+                        dstPath = arg.Substring(3);
+                        break;
+                    default:
+                        DisplayUsage();
+                        return;
+                }
+            }
+
+            if (string.IsNullOrEmpty(srcFilename) || string.IsNullOrEmpty(dstPath))
+            {
+                DisplayUsage();
+                return;
+            }
+
+            ProcessSourceFile(srcFilename, dstPath);
+        }
+
+        static void ProcessSourceFile(string srcFilename, string dstPath)
+        {
+            try
+            {
+                if (!Directory.Exists(dstPath))
+                    Directory.CreateDirectory(dstPath);
+
+                string srcPath = Path.GetDirectoryName(srcFilename);
+                string dstFilename = Path.Combine(dstPath, Path.GetFileNameWithoutExtension(srcFilename) + ".binary.babylon");
+
+                dynamic scene;
+
+                // Loading
+                Console.ForegroundColor = ConsoleColor.Green;
+                Console.WriteLine("Loading " + srcFilename);
+                Console.WriteLine();
+                Console.ResetColor();
+
+                using (var streamReader = new StreamReader(srcFilename))
+                {
+                    using (var reader = new JsonTextReader(streamReader))
+                    {
+                        scene = JObject.Load(reader);
+                    }
+                }
+
+                // Marking scene
+                string objName = scene.name;
+
+                if(string.IsNullOrEmpty(objName))
+                    objName = Path.GetFileNameWithoutExtension(srcFilename);
+
+                int atDot = objName.IndexOf(".incremental");
+                if(atDot > 0)
+                    objName = objName.Substring(0, atDot);
+
+                scene["autoClear"] = true;
+                scene["useDelayedTextureLoading"] = true;
+
+                var doNotDelayLoadingForGeometries = new List<string>();
+
+                // Parsing meshes
+                bool isMesh = true;
+                var meshes = (JArray)scene.meshes;
+                foreach (dynamic mesh in meshes)
+                {
+                    if (mesh.checkCollisions.Value) // Do not delay load collisions object
+                    {
+                        if (mesh.geometryId != null)
+                            doNotDelayLoadingForGeometries.Add(mesh.geometryId.Value);
+                        continue;
+                    }
+
+                    isMesh = true;
+
+                    Extract(srcPath, dstPath, objName, mesh, isMesh);
+                }
+
+
+                // Parsing vertexData
+                var geometries = scene.geometries;
+                if (geometries != null)
+                {
+                    var vertexData = (JArray)geometries.vertexData;
+                    foreach (dynamic geometry in vertexData)
+                    {
+                        var id = geometry.id.Value;
+
+                        if (doNotDelayLoadingForGeometries.Any(g => g == id))
+                            continue;
+
+                        isMesh = false;
+
+                        Extract(srcPath, dstPath, objName, geometry, isMesh);
+                    }
+                }
+
+                // Saving
+                Console.ForegroundColor = ConsoleColor.Green;
+                Console.WriteLine("Saving " + dstFilename);
+                string json = scene.ToString(Formatting.Indented);
+
+                using (var writer = new StreamWriter(WebUtility.UrlDecode(dstFilename)))
+                {
+                    writer.Write(json);
+                }
+
+                Console.WriteLine();
+                Console.ResetColor();
+            }
+            catch (Exception ex)
+            {
+                Console.ForegroundColor = ConsoleColor.Red;
+                Console.WriteLine("Fatal error encountered:");
+                Console.WriteLine(ex.Message);
+                Console.ResetColor();
+            }
+        }
+
+        
+        static void Extract(string srcPath, string dstPath, string objName, dynamic meshObj, bool isMesh)
+        {
+            try
+            {
+                string dstFilename = meshObj.delayLoadingFile;
+                string dstExt = (isMesh ? ".babylonbinarymeshdata" : ".babylonbinarygeometrydata");
+                
+                if(!string.IsNullOrEmpty(dstFilename))
+                {
+                    string filename = WebUtility.UrlDecode(Path.Combine(srcPath, (string)meshObj.delayLoadingFile));
+
+                    using (var streamReader = new StreamReader(filename))
+                    {
+                        using (var reader = new JsonTextReader(streamReader))
+                        {
+                            var meshData = JObject.Load(reader);
+                            meshObj.positions = meshData["positions"];
+                            meshObj.normals = meshData["normals"];
+                            meshObj.indices = meshData["indices"];
+                            meshObj.uvs = meshData["uvs"];
+                            meshObj.uvs2 = meshData["uvs2"];
+                            meshObj.colors = meshData["colors"];
+                            meshObj.matricesIndices = meshData["matricesIndices"];
+                            meshObj.matricesWeights = meshData["matricesWeights"];
+                            meshObj.subMeshes = meshData["subMeshes"];
+                        }
+                    }
+                }
+
+                if (meshObj.positions == null || meshObj.normals == null || meshObj.indices == null)
+                    return;
+
+                Console.WriteLine("Extracting " + (isMesh ? meshObj.name : meshObj.id));
+
+                ComputeBoundingBox(meshObj);
+
+                string meshName = meshObj.name.ToString();
+                meshName = meshName.Trim();
+                if (meshName.Length > 40)
+                    meshName = meshName.Substring(0, 40);
+
+                if (isMesh && !string.IsNullOrEmpty(meshName))
+                    dstFilename = objName + "." + meshName + "." + meshObj.id.ToString() + dstExt;
+                else
+                    dstFilename = objName + meshObj.id.ToString() + dstExt;
+
+                dstFilename = dstFilename.Replace("+", "_").Replace(" ", "_").Replace("/", "_").Replace("\\", "_");
+
+                meshObj.delayLoadingFile = WebUtility.UrlEncode(dstFilename);
+                Console.WriteLine("Creating delayLoadingFile: " + meshObj.delayLoadingFile);
+
+
+                var binaryInfo = new JObject();
+
+                using (var stream = File.Open(WebUtility.UrlDecode(Path.Combine(dstPath, dstFilename)), FileMode.Create))
+                {
+                    BinaryWriter writer = new BinaryWriter(stream);
+
+                    if (meshObj.positions != null && meshObj.positions.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.positions.Count;
+                        attrData["stride"] = 3;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Float;
+
+                        binaryInfo["positionsAttrDesc"] = attrData;
+
+                        for (int x = 0; x < meshObj.positions.Count; x++)
+                            writer.Write((float)meshObj.positions[x]);
+
+                        meshObj.positions = null;
+                    }
+
+
+                    if (meshObj.colors != null && meshObj.colors.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.colors.Count;
+                        attrData["stride"] = 3;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Float;
+
+                        binaryInfo["colorsAttrDesc"] = attrData;
+
+                        for (int x = 0; x < meshObj.colors.Count; x++)
+                            writer.Write((float)meshObj.colors[x]);
+
+                        meshObj["hasColors"] = true;
+                        meshObj.colors = null;
+                    }
+
+
+                    if (meshObj.normals != null && meshObj.normals.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.normals.Count;
+                        attrData["stride"] = 3;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Float;
+
+                        binaryInfo["normalsAttrDesc"] = attrData;
+
+                        for (int x = 0; x < meshObj.normals.Count; x++)
+                            writer.Write((float)meshObj.normals[x]);
+
+                        meshObj.normals = null;
+                    }
+
+
+                    if (meshObj.uvs != null && meshObj.uvs.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.uvs.Count;
+                        attrData["stride"] = 2;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Float;
+
+                        binaryInfo["uvsAttrDesc"] = attrData;
+
+                        for (int x = 0; x < meshObj.uvs.Count; x++)
+                            writer.Write((float)meshObj.uvs[x]);
+
+                        meshObj["hasUVs"] = true;
+                        meshObj.uvs = null;
+                    }
+
+
+                    if (meshObj.uvs2 != null && meshObj.uvs2.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.uvs2.Count;
+                        attrData["stride"] = 2;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Float;
+
+                        binaryInfo["uvs2AttrDesc"] = attrData;
+
+                        for (int x = 0; x < meshObj.uvs2.Count; x++)
+                            writer.Write((float)meshObj.uvs2[x]);
+
+                        meshObj["hasUVs2"] = true;
+                        meshObj.uvs2 = null;
+                    }
+
+
+                    if (meshObj.indices != null && meshObj.indices.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.indices.Count;
+                        attrData["stride"] = 1;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Int32;
+
+                        binaryInfo["indicesAttrDesc"] = attrData;
+
+                        for (int x = 0; x < meshObj.indices.Count; x++)
+                            writer.Write((int)meshObj.indices[x]);
+
+                        meshObj.indices = null;
+                    }
+
+
+                    if (meshObj.matricesIndices != null && meshObj.matricesIndices.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.matricesIndices.Count;
+                        attrData["stride"] = 1;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Int32;
+
+                        binaryInfo["matricesIndicesAttrDesc"] = attrData;
+
+                        for (int x = 0; x < meshObj.matricesIndices.Count; x++)
+                            writer.Write((int)meshObj.matricesIndices[x]);
+
+                        meshObj["hasMatricesIndices"] = true;
+                        meshObj.matricesIndices = null;
+                    }
+
+
+                    if (meshObj.matricesWeights != null && meshObj.matricesWeights.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.matricesWeights.Count;
+                        attrData["stride"] = 2;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Float;
+
+                        binaryInfo["matricesWeightsAttrDesc"] = attrData;
+
+                        for (int x = 0; x < meshObj.matricesWeights.Count; x++)
+                            writer.Write((float)meshObj.matricesWeights[x]);
+
+                        meshObj["hasMatricesWeights"] = true;
+                        meshObj.matricesWeights = null;
+                    }
+
+
+                    if (isMesh && meshObj.subMeshes != null && meshObj.subMeshes.Count > 0)
+                    {
+                        var attrData = new JObject();
+                        attrData["count"] = meshObj.subMeshes.Count;
+                        attrData["stride"] = 5;
+                        attrData["offset"] = stream.Length;
+                        attrData["dataType"] = (int)DataType.Int32;
+
+                        binaryInfo["subMeshesAttrDesc"] = attrData;
+
+                        int[] smData = new int[5];
+
+                        for (int x = 0; x < meshObj.subMeshes.Count; x++)
+                        {
+                            smData[0] = meshObj.subMeshes[x].materialIndex;
+                            smData[1] = meshObj.subMeshes[x].verticesStart;
+                            smData[2] = meshObj.subMeshes[x].verticesCount;
+                            smData[3] = meshObj.subMeshes[x].indexStart;
+                            smData[4] = meshObj.subMeshes[x].indexCount;
+
+                            for (int y = 0; y < smData.Length; y++)
+                                writer.Write((int)smData[y]);
+                        }
+
+                        meshObj.subMeshes = null;
+                    }
+                }
+
+                meshObj["_binaryInfo"] = binaryInfo;
+            }
+            catch (Exception ex)
+            {
+                Console.ForegroundColor = ConsoleColor.Red;
+                Console.WriteLine();
+                Console.WriteLine(ex.Message);
+                Console.ForegroundColor = ConsoleColor.DarkCyan;
+                Console.WriteLine(ex);
+                Console.ResetColor();
+            }
+        }
+        
+        
+        static void ComputeBoundingBox(dynamic meshOrGeometry)
+        {
+            // Compute bounding boxes
+            var positions = ((JArray)meshOrGeometry.positions).Select(v => v.Value<float>()).ToArray();
+            var minimum = new[] { float.MaxValue, float.MaxValue, float.MaxValue };
+            var maximum = new[] { float.MinValue, float.MinValue, float.MinValue };
+
+            for (var index = 0; index < positions.Length; index += 3)
+            {
+                var x = positions[index];
+                var y = positions[index + 1];
+                var z = positions[index + 2];
+
+                if (x < minimum[0])
+                {
+                    minimum[0] = x;
+                }
+                if (x > maximum[0])
+                {
+                    maximum[0] = x;
+                }
+
+                if (y < minimum[1])
+                {
+                    minimum[1] = y;
+                }
+                if (y > maximum[1])
+                {
+                    maximum[1] = y;
+                }
+
+                if (z < minimum[2])
+                {
+                    minimum[2] = z;
+                }
+                if (z > maximum[2])
+                {
+                    maximum[2] = z;
+                }
+            }
+
+            meshOrGeometry["boundingBoxMinimum"] = new JArray(minimum);
+            meshOrGeometry["boundingBoxMaximum"] = new JArray(maximum);
+        }
+
+
+        static void DisplayUsage()
+        {
+            Console.WriteLine("ConvertToBinary usage: ConvertToBinary.exe /i:\"sourceFilename\" /o:\"dstinationFolder\"");
+        }
+    }
+}

+ 3 - 3
Exporters/BinaryConverter/Properties/AssemblyInfo.cs

@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
 // General Information about an assembly is controlled through the following 
 // set of attributes. Change these attribute values to modify the information
 // associated with an assembly.
-[assembly: AssemblyTitle("BabylonBinaryConverter")]
+[assembly: AssemblyTitle("ConvertToBinary")]
 [assembly: AssemblyDescription("")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("BabylonBinaryConverter")]
+[assembly: AssemblyProduct("ConvertToBinary")]
 [assembly: AssemblyCopyright("Copyright ©  2014")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
 [assembly: ComVisible(false)]
 
 // The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("155c78d1-0e27-4e85-863a-d96a418007cc")]
+[assembly: Guid("4e8c456c-1bd6-43fb-b67b-0dfbee0c468d")]
 
 // Version information for an assembly consists of the following four values:
 //

+ 72 - 2
babylon.1.14-beta-debug.js

@@ -10360,12 +10360,19 @@ var BABYLON;
 
                 scene._addPendingData(that);
 
+                var getBinaryData = (this.delayLoadingFile.indexOf(".babylonbinarymeshdata") !== -1) ? true : false;
+
                 BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
-                    _this._delayLoadingFunction(JSON.parse(data), _this);
+                    if (data instanceof ArrayBuffer) {
+                        _this._delayLoadingFunction(data, _this);
+                    } else {
+                        _this._delayLoadingFunction(JSON.parse(data), _this);
+                    }
+
                     _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
                     scene._removePendingData(_this);
                 }, function () {
-                }, scene.database);
+                }, scene.database, getBinaryData);
             }
         };
 
@@ -18366,6 +18373,10 @@ var BABYLON;
                 mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;
                 mesh._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMinimum), BABYLON.Vector3.FromArray(parsedMesh.boundingBoxMaximum));
 
+                if (parsedMesh._binaryInfo) {
+                    mesh._binaryInfo = parsedMesh._binaryInfo;
+                }
+
                 mesh._delayInfo = [];
                 if (parsedMesh.hasUVs) {
                     mesh._delayInfo.push(BABYLON.VertexBuffer.UVKind);
@@ -18551,6 +18562,65 @@ var BABYLON;
                 if (geometry) {
                     geometry.applyToMesh(mesh);
                 }
+            } else if (parsedGeometry instanceof ArrayBuffer) {
+                var binaryInfo = mesh._binaryInfo;
+
+                if (binaryInfo.positionsAttrDesc && binaryInfo.positionsAttrDesc.count > 0) {
+                    var positionsData = new Float32Array(parsedGeometry, binaryInfo.positionsAttrDesc.offset, binaryInfo.positionsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positionsData, false);
+                }
+
+                if (binaryInfo.normalsAttrDesc && binaryInfo.normalsAttrDesc.count > 0) {
+                    var normalsData = new Float32Array(parsedGeometry, binaryInfo.normalsAttrDesc.offset, binaryInfo.normalsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normalsData, false);
+                }
+
+                if (binaryInfo.uvsAttrDesc && binaryInfo.uvsAttrDesc.count > 0) {
+                    var uvsData = new Float32Array(parsedGeometry, binaryInfo.uvsAttrDesc.offset, binaryInfo.uvsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvsData, false);
+                }
+
+                if (binaryInfo.uvs2AttrDesc && binaryInfo.uvs2AttrDesc.count > 0) {
+                    var uvs2Data = new Float32Array(parsedGeometry, binaryInfo.uvs2AttrDesc.offset, binaryInfo.uvs2AttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.UV2Kind, uvs2Data, false);
+                }
+
+                if (binaryInfo.colorsAttrDesc && binaryInfo.colorsAttrDesc.count > 0) {
+                    var colorsData = new Float32Array(parsedGeometry, binaryInfo.colorsAttrDesc.offset, binaryInfo.colorsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, colorsData, false);
+                }
+
+                if (binaryInfo.matricesIndicesAttrDesc && binaryInfo.matricesIndicesAttrDesc.count > 0) {
+                    var matricesIndicesData = new Int32Array(parsedGeometry, binaryInfo.matricesIndicesAttrDesc.offset, binaryInfo.matricesIndicesAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, matricesIndicesData, false);
+                }
+
+                if (binaryInfo.matricesWeightsAttrDesc && binaryInfo.matricesWeightsAttrDesc.count > 0) {
+                    var matricesWeightsData = new Float32Array(parsedGeometry, binaryInfo.matricesWeightsAttrDesc.offset, binaryInfo.matricesWeightsAttrDesc.count);
+                    mesh.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeightsData, false);
+                }
+
+                if (binaryInfo.indicesAttrDesc && binaryInfo.indicesAttrDesc.count > 0) {
+                    var indicesData = new Int32Array(parsedGeometry, binaryInfo.indicesAttrDesc.offset, binaryInfo.indicesAttrDesc.count);
+                    mesh.setIndices(indicesData);
+                }
+
+                if (binaryInfo.subMeshesAttrDesc && binaryInfo.subMeshesAttrDesc.count > 0) {
+                    var subMeshesData = new Int32Array(parsedGeometry, binaryInfo.subMeshesAttrDesc.offset, binaryInfo.subMeshesAttrDesc.count * 5);
+
+                    mesh.subMeshes = [];
+                    for (var i = 0; i < binaryInfo.subMeshesAttrDesc.count; i++) {
+                        var materialIndex = subMeshesData[(i * 5) + 0];
+                        var verticesStart = subMeshesData[(i * 5) + 1];
+                        var verticesCount = subMeshesData[(i * 5) + 2];
+                        var indexStart = subMeshesData[(i * 5) + 3];
+                        var indexCount = subMeshesData[(i * 5) + 4];
+
+                        var subMesh = new BABYLON.SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh);
+                    }
+                }
+
+                return;
             } else if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {
                 mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, parsedGeometry.positions, false);
                 mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, parsedGeometry.normals, false);

文件差異過大導致無法顯示
+ 7 - 7
babylon.1.14-beta.js