Getting triangulated mesh data in world/object space

Getting triangulated mesh data in world/object space

Anonymous
Not applicable
849 Views
2 Replies
Message 1 of 3

Getting triangulated mesh data in world/object space

Anonymous
Not applicable

Hi,

 

Is there any way to force the API to return mesh vertex data in world or object space? 

I thought it's always in world space but when I load "bike frame" example I got objects in many different places on the scene and it looks like there is some transform added to local vertex data. 

It will be best if I could get data in local space and then get transform matrix for the object.

If this is impossible then at least getting ALL vertex data in world space should be possible.

Now I don't see the way to export "bike frame" scene with all objects in correct places. 

0 Likes
Accepted solutions (1)
850 Views
2 Replies
Replies (2)
Message 2 of 3

liujac
Alumni
Alumni
Accepted solution

Hi,

If you get the mesh data with correct assembly context, the data should be in world space. Could you please try the sctipt below?

 

function run(context) {

    "use strict";
    if (adsk.debug === true) {
        /*jslint debug: true*/
        debugger;
        /*jslint debug: false*/
    }
 
    var ui;
    try {
        var app = adsk.core.Application.get();
        ui = app.userInterface;
        
        var meshStr = '';
        var allOccs = app.activeProduct.rootComponent.allOccurrences;
        for(var i = 0; i < allOccs.count; i++){
            var occ = allOccs.item(i);
            var comp = occ.component;
            var bodies = comp.bRepBodies;
            for(var j = 0; j < bodies.count; j++){
                var body = bodies.item(j);
                body = body.createForAssemblyContext(occ);
                var meshMgr = body.meshManager;
                var meshList = meshMgr.displayMeshes;
                for(var k = 0; k < meshList.count; k++){
                    var triMesh = meshList.item(k);
                    var data = triMesh.nodeCoordinatesAsDouble;
                    var dataStr = data.join(",");
                    meshStr += dataStr;
                    meshStr += '\n';
                }
            }
        }
        //ui.messageBox(meshStr);
    } 
    catch (e) {
        if (ui) {
            ui.messageBox('Failed : ' + (e.description ? e.description : e));
        }
    }

    adsk.terminate(); 
}

 

Thanks,

Jack

0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks, assembly context solved the problem. Now it works fine 🙂
0 Likes