0

I need to export scene as single STL file. Whereas its easy to export each single <asset>/<mesh>/<model> exporting whole scene with transformations its another story. That requires applying world matrix transform to every vertex of each asset data on-the-fly before export. Does XML3D has some mechanisms that would help me with that?

Where should I start?

Xyz
  • 1,522
  • 17
  • 23

1 Answers1

1

Actually, XML3D is an presentation format and was never designed to extract something useful other than interactive renderings. However, since it is JavaScript, you can access everything somehow and obviously you can also get the data you need to apply all transformations and create a single huge STL mesh from the scene.

The easiest way I can imagine is using the internal scene:

var scene = document.querySelector("xml3d")._configured.adapters["webgl_1"].getScene();

// Iterate render objects
scene.ready.forEach(function(renderObject) {
  // Get word matrix
  var worldMatrix = new Float32Array(16);
  renderObject.getWorldMatrix(worldMatrix);

  // Get local position data
  var dataRequest = new Xflow.ComputeRequest(renderObject.drawable.dataNode, ["position"]);
  var positions = dataRequest.getResult().getOutputData("position").getValue();

  console.log(worldMatrix, positions.length);
  // apply worldmatrix to all positions
  ...
});
ksons
  • 183
  • 9
  • I guess matrix multiplication is something to be done by hand, right? – Xyz Jun 12 '15 at 11:57
  • 2
    You can find a math function that will transform a vector with a matrix under ```XML3D.math.vec3.transformMat4(outVec, inVec, inMat)```. All the functions under XML3D.math operate with the glmatrix math types (basically just plain arrays). – csvurt Jun 12 '15 at 13:31
  • How can I get index data for particular drawable? (By index data i mean indicies of triples of verticies that define triangles). – Xyz Jun 22 '15 at 21:02