Looking for examples of programmatic generation of geometries in xml3d

86 Views Asked by At

There are various examples here in the specification but I could not find an end-to-end example on how to start e.g. with a numerical dataset representing an object surface, construct the meshes on the fly and display in a browser.

1

There are 1 best solutions below

0
On

We have some examples of this in our xml3d-examples repository, particularly the wave example which generates and deforms a grid on the fly. The face morphing example also shows mesh deformation, the principle for generating the mesh would be basically the same.

What you'll want to do is write an Xflow operator that takes the numerical dataset as input and outputs vertex positions (and normals and face indices if necessary). The end result would look something like this:

<data id="mydata" compute="index, position, normal = xflow.yourOperator(input1, input2 ...)">
    <float3 id="myinput1" name="input1">...</float3>
    ...
</data>

<mesh src="#mydata" type="triangles"></mesh>

Here is the operator from the wave example above, that would be a good starting point. Xflow will automatically re-compute the mesh whenever the input data changes and you could use the setScriptValue function on value elements (int, float, float3 etc) to set the input data without having to dump it into the DOM as text:

document.getElementById("myinput1").setScriptValue(numericalData.input1);