Jump to content

Multiple instances of base mesh


ozRocker
 Share

Recommended Posts

It probably would be easier since I know where everything fits.  Maybe I can streamline it more with the extra knowledge of Babylon.js that I've gained since then.  I'll try and get it done within the next 2 weeks.  I'm a bit tied up right now writing pitch-decks and business plans and all that crap that investors care about.

Link to comment
Share on other sites

Hi, I'm trying to get the prefab instances to export correctly, and when they export, the .babylon file seems correct though if I have a material on the prefab at all (even the default material) I get an error when loading the scene. 

This is the error:  "Uncaught TypeError: Cannot read property 'index' of undefined                babylon.max.nightly.js:6297"

Which leads to this section of code: 

Engine.prototype.updateAndBindInstancesBuffer = function (instancesBuffer, data, offsetLocations) {
    this._gl.bindBuffer(this._gl.ARRAY_BUFFER, instancesBuffer);
    if (data) {
        this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
    }
    if (offsetLocations[0].index !== undefined) { // this is the line in question
        var stride = 0;
        for (var i = 0; i < offsetLocations.length; i++) {
            var ai = offsetLocations[i];
            stride += ai.attributeSize * 4;
        }
        for (var i = 0; i < offsetLocations.length; i++) {
            var ai = offsetLocations[i];
            this._gl.enableVertexAttribArray(ai.index);
            this._gl.vertexAttribPointer(ai.index, ai.attributeSize, ai.attribyteType || this._gl.FLOAT, ai.normalized || false, stride, ai.offset);
            this._caps.instancedArrays.vertexAttribDivisorANGLE(ai.index, 1);
        }
    }
    else {
        for (var index = 0; index < 4; index++) {
            var offsetLocation = offsetLocations[index];
            this._gl.enableVertexAttribArray(offsetLocation);
            this._gl.vertexAttribPointer(offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);
            this._caps.instancedArrays.vertexAttribDivisorANGLE(offsetLocation, 1);
        }
    }
};

This is not the current nightly build, but it is fairly recent, probably a week or two old. 

Any ideas? I can post more info/code if needed.

Link to comment
Share on other sites

I've figured it out. I had this code in the scene.executeWhenReady function and for some reason that was causing problems: 

scene.materials.forEach( function( mat ) {
    mat.freeze();
});

I moved it to a render loop that stops itself and it now works fine.

Inside scene.executeWhenReady() :

engine.runRenderLoop( freezeMaterials );

The 'freezeMaterials' function: 

function freezeMaterials() {
    scene.materials.forEach( function( mat ) {
        mat.freeze();
    });
    scene.getEngine().stopRenderLoop(freezeMaterials);
}
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...