#VRML V2.0 utf8 ## ##@ proto PROTO asphere [ field SFInt32 nlatitude 16 field SFInt32 nlongitude 16 field SFFloat creaseAngle 3.14 ] ##@ body { DEF IFS IndexedFaceSet { coord DEF C Coordinate { } texCoord DEF TC TextureCoordinate { } creaseAngle IS creaseAngle } ##@ script DEF S Script { field SFInt32 nlat IS nlatitude field SFInt32 nl IS nlongitude ##eventOut MFVec3f c eventOut MFVec3f c eventOut MFVec2f tc eventOut MFInt32 ci url [ "javascript: function initialize() { var r, phi, x, y, z; var i, j, idx; //@ coordinates // Compute coordinates, texture coordinates: for (i = 0; i < nlat; i++) { y = 2 * ( i / (nlat-1) ) - 1; r = Math.sqrt( 1 - y*y ); for (j = 0; j < nl; j++) { phi = 2 * Math.PI * j / nl; x = -Math.sin(phi)*r; z = -Math.cos(phi)*r; c[i*nl+j] = new SFVec3f(x,y,z); tc[i*nl+j] = new SFVec2f( j/nl, i/(nlat-1) ); } } ##@ indices // And compute indices: dfac = 3; for (i = 0; i < (nlat-1)/dfac; i++) { for (j = 0; j < nl; j++) { idx = 5*(i*nl+j); ci[idx+0] = dfac*i*nl+(j)%nl; ci[idx+1] = dfac*i*nl+(j+1)%nl; ci[idx+2] = (dfac*i+1)*nl+(j+1)%nl; ci[idx+3] = (dfac*i+1)*nl+(j)%nl; ci[idx+4] = -1; // end-of-polygon } } }" ] } ##@ route(s) ROUTE S.c TO C.set_point ROUTE S.tc TO TC.set_point ROUTE S.ci TO IFS.set_coordIndex } ##@ world Background { skyColor [0.9 .1 .1] } NavigationInfo { type ["EXAMINE", "ANY"] } Viewpoint { position 0 0 10 orientation 0 0 1 0 } ##@ object Transform { translation 0 0 0 scale 2 2 2 children [ Shape { appearance DEF A Appearance { material Material {} ##texture ImageTexture { url ["local/images/check.gif"] } texture ImageTexture { url ["logo.jpg"] } } ##geometry asphere { nlatitude 32 nlongitude 20 } geometry asphere { nlatitude 100 nlongitude 100 } } ] } ##