Created
June 22, 2016 13:32
-
-
Save cecilemuller/ad5e961ad20be3aadbbf30c2dc97c7a2 to your computer and use it in GitHub Desktop.
VRML: Merge transforms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#VRML V2.0 utf8 | |
Viewpoint{ | |
description "Default" | |
} | |
DEF tr1 Transform { | |
rotation 0.5 0.4 0.1 2 | |
children Transform { | |
rotation 0.1 0.6 0.3 -0.8 | |
children Shape { | |
appearance Appearance { | |
material Material { | |
diffuseColor 0 0 1 | |
emissiveColor 0.3 0 0 | |
} | |
} | |
geometry Box{size 4 1 2} | |
} | |
} | |
} | |
DEF tr2 Transform { | |
children Shape { | |
appearance Appearance { | |
material Material { | |
diffuseColor 0 0 1 | |
emissiveColor 0.3 0 0 | |
transparency 0.5 | |
} | |
} | |
geometry Box { | |
size 5 2 3 | |
} | |
} | |
} | |
Script { | |
field SFNode tr1 USE tr1 | |
field SFNode tr2 USE tr2 | |
directOutput TRUE | |
url "javascript: | |
function collapse(outer_transform, inner_transform){ | |
var translation = new SFVec3f(); | |
var rotation = new SFRotation(); | |
var scale = new SFVec3f(); | |
var scaleOrientation = new SFRotation(); | |
var center = new SFVec3f(); | |
var matrix1 = new VrmlMatrix(); | |
var matrix2 = new VrmlMatrix(); | |
matrix1.setTransform( | |
outer_transform.translation, | |
outer_transform.rotation, | |
outer_transform.scale, | |
outer_transform.scaleOrientation, | |
outer_transform.center | |
); | |
matrix2.setTransform( | |
inner_transform.translation, | |
inner_transform.rotation, | |
inner_transform.scale, | |
inner_transform.scaleOrientation, | |
inner_transform.center | |
); | |
matrix1.multLeft(matrix2).getTransform(translation, rotation, scale, scaleOrientation, center); | |
return Browser.createVrmlFromString('Transform{translation ' + translation + ' rotation ' + rotation + ' scale ' + scale + ' scaleOrientation ' + scaleOrientation + ' center ' + center + '}')[0]; | |
} | |
function initialize(){ | |
var transform = collapse(tr1, tr1.children[0]); | |
tr2.translation = transform.translation; | |
tr2.rotation = transform.rotation; | |
tr2.scale = transform.scale; | |
tr2.scaleOrientation = transform.scaleOrientation; | |
tr2.center = transform.center; | |
} | |
" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment