[webGLviewer] - Yet another WebGL viewer


Re: [webGLviewer] - Yet another WebGL viewer
#26
Thanks! It gave me some hints.

Hovewer, still it was hard task to get this working... that is, as far as I understand, Y and Z axis have different orientation in ldd than in ldraw. Plus I had to figure out correct operations sequence...

In case anybody will be interested, please find the conversion algorithm below.

Webgldraw viewer can now render simple .lxf/ .lxfml files (complicated ones with problems). Drag&drop is supported.

Regards,
Jakub

---------------------------------------------------

/* Create: rotation matrix from ldraw.xml definition */
var rotMat = Matrix.Rotation( objdef[6], Vector.create( [objdef[3], objdef[4], objdef[5]] ) ).ensure4x4();

/* Create: shift matrix from ldraw.xml definition */
var shiftMat = Matrix.I(4);
shiftMat.elements[0][3] =-objdef[0]*scale;
shiftMat.elements[1][3] = objdef[1]*scale;
shiftMat.elements[2][3] = objdef[2]*scale;

/* Get parameters from lxmf. */
E.elements[0][0] = parseFloat( t[0] );
E.elements[0][1] =-parseFloat( t[3] );
E.elements[0][2] =-parseFloat( t[6] );
E.elements[1][0] =-parseFloat( t[1] );
E.elements[1][1] = parseFloat( t[4] );
E.elements[1][2] = parseFloat( t[7] );
E.elements[2][0] =-parseFloat( t[2] );
E.elements[2][1] = parseFloat( t[5] );
E.elements[2][2] = parseFloat( t[8] );
E.elements[0][3] = parseFloat( t[9] )*scale;
E.elements[1][3] = parseFloat(-t[10])*scale;
E.elements[2][3] = parseFloat(-t[11])*scale;

/* Calculate final matrix. */
var fin = E.multiply( rotMat.multiply( shiftMat ) );

/* Now: write ldraw format */
l=fin.elements[0][3] + " " + fin.elements[1][3] + " " + fin.elements[2][3] + " " +
fin.elements[0][0] + " " + fin.elements[0][1] + " " + fin.elements[0][2] + " " +
fin.elements[1][0] + " " + fin.elements[1][1] + " " + fin.elements[1][2] + " " +
fin.elements[2][0] + " " + fin.elements[2][1] + " " + fin.elements[2][2];


Reply
« Next Oldest | Next Newest »



Messages In This Thread
just for completeness - by Steffen - 2014-10-16, 19:45
Re: just for completeness - by Steffen - 2015-06-27, 22:32
Re: [webGLviewer] - Yet another WebGL viewer - by Jakub Trznadel - 2014-11-26, 23:51

Forum Jump:


Users browsing this thread: 3 Guest(s)