user3970726
user3970726

Reputation:

XML3D: Exporting scene

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?

Upvotes: 0

Views: 66

Answers (1)

ksons
ksons

Reputation: 123

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

Upvotes: 0

Related Questions