matdav Posted November 14, 2018 Share Posted November 14, 2018 Hi all, in my project I'm using incremental loading in order to split large scene files in small pieces. In the incremental files creation I'm trying to use Draco encoding to reduce the file size and speed up the loading process (certainly then should be implemented decoding when reading the file). I'm using the following code but the resulting encoded data is larger than the original data. I ask you first of all if the reasoning I'm doing makes sense and then if someone can explain to me where I'm wrong. Thanks a lot, Matteo createDelayLoadingFileData: function (meshOrGeometry, isMesh) { var result = { positions: meshOrGeometry.positions, indices: meshOrGeometry.indices, normals: meshOrGeometry.normals, }; if (meshOrGeometry.uvs) { result.uvs = meshOrGeometry.uvs; } if (meshOrGeometry.uvs2) { result.uvs2 = meshOrGeometry.uvs2; } if (meshOrGeometry.colors) { result.colors = meshOrGeometry.colors; } if (meshOrGeometry.matricesIndices) { result.matricesIndices = meshOrGeometry.matricesIndices; } if (meshOrGeometry.matricesWeights) { result.matricesWeights = meshOrGeometry.matricesWeights; } if (isMesh && meshOrGeometry.subMeshes) { result.subMeshes = meshOrGeometry.subMeshes; } // --------------------------------------------------------------------- // Test draco encoding // --------------------------------------------------------------------- const mesh = { indices: new Uint32Array(result.indices), positions: new Float32Array(result.positions), normals: new Float32Array(result.normals), uvs: new Float32Array(result.uvs) }; const encoderModule = DracoEncoderModule(); const encoder = new encoderModule.Encoder(); const meshBuilder = new encoderModule.MeshBuilder(); const dracoMesh = new encoderModule.Mesh(); const numFaces = mesh.indices.length / 3; const numPoints = mesh.positions.length; meshBuilder.AddFacesToMesh(dracoMesh, numFaces, mesh.indices); meshBuilder.AddFloatAttributeToMesh(dracoMesh, encoderModule.POSITION, numPoints, 3, mesh.positions); if (result.hasOwnProperty('normals')) { meshBuilder.AddFloatAttributeToMesh( dracoMesh, encoderModule.NORMAL, numPoints, 3, mesh.normals); } if (result.hasOwnProperty('colors')) { meshBuilder.AddFloatAttributeToMesh( dracoMesh, encoderModule.COLOR, numPoints, 3, mesh.colors); } if (result.hasOwnProperty('uvs')) { meshBuilder.AddFloatAttributeToMesh( dracoMesh, encoderModule.TEX_COORD, numPoints, 3, mesh.uvs); } var method = "edgebreaker"; // test method if (method === "edgebreaker") { encoder.SetEncodingMethod(encoderModule.MESH_EDGEBREAKER_ENCODING); } else if (method === "sequential") { encoder.SetEncodingMethod(encoderModule.MESH_SEQUENTIAL_ENCODING); } const encodedData = new encoderModule.DracoInt8Array(); // Use default encoding setting. const encodedLen = encoder.EncodeMeshToDracoBuffer(dracoMesh, encodedData); // Copy encoded data to buffer. const outputArray = []; for (let i = 0; i < encodedLen; ++i) { outputArray.push(encodedData.GetValue(i)); } encoderModule.destroy(dracoMesh); encoderModule.destroy(encodedData); encoderModule.destroy(encoder); encoderModule.destroy(meshBuilder); result.dracoData = outputArray; result.dracoDataLen = outputArray.length; // --------------------------------------------------------------------- return result; } Quote Link to comment Share on other sites More sharing options...
Guest Posted November 14, 2018 Share Posted November 14, 2018 Pinging @bghgary who did the Draco port for our glTF loader Quote Link to comment Share on other sites More sharing options...
bghgary Posted November 14, 2018 Share Posted November 14, 2018 Babylon currently only has support for Draco decompression. I unfortunately don't have any experience using the encoder. It is probably better to ask this question here: https://github.com/google/draco/issues. Quote Link to comment Share on other sites More sharing options...
matdav Posted November 15, 2018 Author Share Posted November 15, 2018 Ok, thanks for your replies. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.