[x3d-public] quaterntion lib., was: errors in convertJsonToStl.js

Andreas Plesch andreasplesch at gmail.com
Mon Jun 4 07:23:59 PDT 2018


Ok.

Yes, I would then stay away from quaternions and just use the
transform matrix for each transform, just multiplying while walking
the transform hierarchy.

Look at

https://github.com/x3dom/x3dom/blob/master/src/nodes/Grouping/Transform.js#L85

to see how to get the transform matrix for each transform node.

Then normals and points need different treatment:

points: https://github.com/x3dom/x3dom/blob/master/src/fields.js#L510
vectors: https://github.com/x3dom/x3dom/blob/master/src/fields.js#L523

In x3dom, you can usually get the world transform of a node by .getTransform() .

-Andreas


On Mon, Jun 4, 2018 at 10:05 AM, Leonard Daly <Leonard.Daly at realism.com> wrote:
> John & Andreas,
>
> I think what John is stating is that STL needs world coordinates for
> everything. That means transforming every coordinate to world space prior to
> conversion. Since X3D supports skewing (non-uniform and non-axial scaling),
> you will need to use 4x4 matrices. I have seen math libraries in X3DOM as
> Andreas has pointed out. THREE.js also deals with quaternions (see
> https://threejs.org/docs/index.html#api/math/Quaternion -- link at bottom to
> code). It also has methods to return the world transform (see
> https://threejs.org/docs/index.html#api/core/Object3D for .matrixWorld and
> related methods).
>
> Leonard Daly
>
>
> What I need for STL is to unwind all the transforms into actual coordinates.
> STL has no concept of transforms.
>
> John
>
> On Mon, Jun 4, 2018, 8:47 AM Andreas Plesch <andreasplesch at gmail.com> wrote:
>>
>> x3dom has a pretty complete matrix et al. math library which includes
>> quaternions:
>>
>> https://github.com/x3dom/x3dom/blob/master/src/fields.js#L1754
>>
>> Its invert methods looks the same as yours.
>>
>> I am not sure if inverting a quaternions is identical to inverting the
>> 4x4 rotation matrix derived from a quaternion, or if that is what you
>> need for stl.
>>
>> -Andreas
>>
>> > Date: Mon, 4 Jun 2018 03:18:40 -0400
>> > From: John Carlson <yottzumm at gmail.com>
>> > To: X3D Graphics public mailing list <x3d-public at web3d.org>
>> > Subject: Re: [x3d-public] errors in convertJsonToStl.js
>> > Message-ID: <5b14e7cf.1c69fb81.b0537.d319 at mx.google.com>
>> > Content-Type: text/plain; charset="utf-8"
>> >
>> > I looked at my quaternion code today, and at quaternions and rotations
>> > on the web.  I am not quite sure how I came up with the code I did (I saw
>> > some video). I think I watched the wrong video, or I was smoking anxiety
>> > that day.  Currently, my converter converts lots of stuff to a plane, it
>> > looks like (see SuperCobra).
>> >
>> > Can anyone point me to a reasonable open source implementation of
>> > quaternion rotations in JavaScript, Java, C or C++?  X_ITE or X3DOM?
>> > Ideally, the quaternions would fit into a 4x4 matrix stack, which is how I
>> > learned how to do transforms (I am not doing a perspective transform that I
>> > know of, so perhaps 3x3 is good enough).  Yes, I know that other
>> > implementations are probably more efficient. I?d like to try to get 4x4
>> > transforms working first before optimizing.  4x4 transforms are NOT a
>> > requirement, however, just a nice to have.
>> >
>> > John
>> >
>> >
>> > Sent from Mail for Windows 10
>> >
>> > From: John Carlson
>> > Sent: Saturday, May 20, 2017 2:20 AM
>> > To: Don Brutzman; X3D Graphics public mailing list
>> > Subject: RE: errors in convertJsonToStl.js
>> >
>> > New versions of X3D JSON, STL and PLY interoperability are here:
>> >
>> >
>> > https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertJsonToStl.js
>> >
>> > https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertPlyToJson.js
>> >
>> > https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertStlToJson.js
>> >
>> > This mostly works with Indexed geometry.? I don?t handle PLY texture
>> > coordinates yet.
>> >
>> > Contributions are welcome, particularly JSON to PLY?
>> >
>> > John
>> >
>> >
>> > -------------- next part --------------
>> > An HTML attachment was scrubbed...
>> > URL:
>> > <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180604/ce73dc01/attachment-0001.html>
>> >
>> > ------------------------------
>> >
>> > Message: 3
>> > Date: Mon, 4 Jun 2018 06:48:24 -0400
>> > From: John Carlson <yottzumm at gmail.com>
>> > To: X3D Graphics public mailing list <x3d-public at web3d.org>
>> > Subject: Re: [x3d-public] errors in convertJsonToStl.js
>> > Message-ID: <5b1518f7.1c69fb81.ed8cb.38a4 at mx.google.com>
>> > Content-Type: text/plain; charset="utf-8"
>> >
>> > Well, I ?fixed? my code, but would appreciate a second pair of eyes
>> > looking at it.  Essentially, I added an inverse quaternion to the transform
>> > ?stack? (now not quite a stack).
>> >
>> >
>> > https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/matrix.js
>> >
>> > https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertJsonToStl.js
>> >
>> > search for quaternion.
>> >
>> > If you hook up the X3DJSONLD web server, you can search for ?LightsOn?
>> > in X3DJSONLD and look at the JSON file  at
>> > /c/x3d-code/www.web3d.org/x3d/content/examples/Savage/? (set up
>> > Cygwin/MingW, node.js etc, create symbolic link).
>> >
>> > It should convert to STL automatically I think. To convert back to JSON
>> > (and display as a green surface), press the here above the STL output pane.
>> >
>> > But really, just a review of the quaternion code should be sufficient.
>> > There?s probably an issue with the viewpoint in the example (STL doesn?t
>> > have viewpoints, and I don?t think I?ve taken the time to introduce the
>> > necessary transforms).
>> >
>> > Thanks,
>> >
>> > John
>> >
>> >
>> > Sent from Mail for Windows 10
>> >
>> > From: John Carlson
>> > Sent: Monday, June 4, 2018 3:18 AM
>> > To: X3D Graphics public mailing list
>> > Subject: RE: errors in convertJsonToStl.js
>> >
>> > I looked at my quaternion code today, and at quaternions and rotations
>> > on the web.? I am not quite sure how I came up with the code I did (I saw
>> > some video). I think I watched the wrong video, or I was smoking anxiety
>> > that day. ?Currently, my converter converts lots of stuff to a plane, it
>> > looks like (see SuperCobra).
>> >
>> > Can anyone point me to a reasonable open source implementation of
>> > quaternion rotations in JavaScript, Java, C or C++?? X_ITE or X3DOM?
>> > Ideally, the quaternions would fit into a 4x4 matrix stack, which is how I
>> > learned how to do transforms (I am not doing a perspective transform that I
>> > know of, so perhaps 3x3 is good enough).? Yes, I know that other
>> > implementations are probably more efficient. I?d like to try to get 4x4
>> > transforms working first before optimizing.? 4x4 transforms are NOT a
>> > requirement, however, just a nice to have.
>> >
>> > John
>> >
>> >
>> > Sent from Mail for Windows 10
>> >
>> > From: John Carlson
>> > Sent: Saturday, May 20, 2017 2:20 AM
>> > To: Don Brutzman; X3D Graphics public mailing list
>> > Subject: RE: errors in convertJsonToStl.js
>> >
>> > New versions of X3D JSON, STL and PLY interoperability are here:
>> >
>> >
>> > https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertJsonToStl.js
>> >
>> > https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertPlyToJson.js
>> >
>> > https://github.com/coderextreme/X3DJSONLD/blob/master/src/main/node/convertStlToJson.js
>> >
>> > This mostly works with Indexed geometry.? I don?t handle PLY texture
>> > coordinates yet.
>> >
>> > Contributions are welcome, particularly JSON to PLY?
>> >
>> > John
>> >
>> >
>> >
>> > -------------- next part --------------
>> > An HTML attachment was scrubbed...
>> > URL:
>> > <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180604/606f3c80/attachment.html>
>> >
>> > ------------------------------
>> >
>> > Subject: Digest Footer
>> >
>> > _______________________________________________
>> > x3d-public mailing list
>> > x3d-public at web3d.org
>> > http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>> >
>> >
>> > ------------------------------
>> >
>> > End of x3d-public Digest, Vol 111, Issue 6
>> > ******************************************
>>
>>
>>
>> --
>> Andreas Plesch
>> Waltham, MA 02453
>
>
>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>
>
> --
> Leonard Daly
> 3D Systems & Cloud Consultant
> LA ACM SIGGRAPH Past Chair
> President, Daly Realism - Creating the Future



-- 
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list