Created
August 26, 2017 14:21
-
-
Save cecilemuller/60bb93bc43fe0bf3a4b889eaded62fe2 to your computer and use it in GitHub Desktop.
VRMLScript: Transform a Coordinate node
This file contains 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
# There is a bug that prevents making a proto wrapping a Coordinate + Script | |
# (initialize isn't even called), hence this proto instead (which works but is more verbose). | |
PROTO CoordinateTransformer [ | |
field SFNode coord Coordinate {} | |
exposedField SFVec3f translation 0 0 0 | |
exposedField SFRotation rotation 0 0 1 0 | |
]{ | |
Script { | |
field MFVec3f point [] | |
field SFNode coord IS coord | |
exposedField SFVec3f translation IS translation | |
exposedField SFRotation rotation IS rotation | |
directOutput TRUE | |
url "javascript: | |
function refresh(){ | |
var inner = new VrmlMatrix(); | |
var outer = new VrmlMatrix(); | |
outer.setTransform(translation, rotation); | |
var l = point.length; | |
var transformed = new MFVec3f(); | |
transformed.length = l; | |
var defaultRotation = new SFRotation(); | |
for (var i = 0; i < l; i++){ | |
inner.setTransform(point[i], defaultRotation); | |
var result = new SFVec3f(); | |
outer.multLeft(inner).getTransform(result, null, null); | |
transformed[i] = result; | |
} | |
coord.point = transformed; | |
} | |
function initialize(){ | |
point = coord.point; | |
refresh(); | |
} | |
function eventsProcessed(){ | |
refresh(); | |
} | |
function translation(){} | |
function rotation(){} | |
" | |
} | |
} | |
############################################################################## | |
# Usage example | |
############################################################################## | |
#Shape { | |
# appearance Appearance { | |
# material Material { | |
# diffuseColor 0 0 0 | |
# emissiveColor 1 0 0 | |
# } | |
# } | |
# geometry IndexedFaceSet { | |
# solid FALSE | |
# coordIndex [0 3 2 1 0 -1] | |
# coord Coordinate { | |
# point [-1 1 0, 1 1 0, 1 -1 0, -1 -1 0] | |
# } | |
# } | |
#} | |
# | |
#Shape { | |
# appearance Appearance { | |
# material Material { | |
# diffuseColor 0 0 0 | |
# emissiveColor 0 1 0 | |
# } | |
# } | |
# geometry IndexedFaceSet { | |
# solid FALSE | |
# coordIndex [0 3 2 1 0 -1] | |
# coord DEF coord Coordinate { | |
# point [-1 1 0, 1 1 0, 1 -1 0, -1 -1 0] | |
# } | |
# } | |
#} | |
# | |
#CoordinateTransformer { | |
# coord USE coord | |
# translation 0 0 1 | |
#} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment