Jump to content

Draco geometry compression for incremental loading


matdav
 Share

Recommended Posts

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;
    }

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...