#VRML V2.0 utf8 Texture Modeller, Evgeny Demidov, 18 April 2001 PROTO TextureModeller[ field SFInt32 n 0 field SFInt32 m 0 field MFString urlImg "" field MFVec2f texCoord [] field MFVec3f points [] ]{ Transform{ scale 3 3 3 children[ # --- model Transform{ scale .7 .7 .7 translation .5 -.2 0 children[ Shape{ appearance Appearance{ material Material{ diffuseColor 1 1 1} texture ImageTexture { url IS urlImg}} geometry DEF spIFS IndexedFaceSet{ coord DEF spCoord Coordinate{} texCoord DEF TC TextureCoordinate{} creaseAngle 1 solid FALSE} } ]} # --- Transform{ translation -1 -.5 0 children[ Shape{ appearance Appearance{ material Material{ diffuseColor 1 1 1} texture ImageTexture { url IS urlImg}} geometry IndexedFaceSet{ coord Coordinate{ point[0 0 0, 1 0 0, 1 1 0, 0 1 0]} coordIndex[0 1 2 3] solid FALSE} } DEF PS PlaneSensor{} ]} Transform{ translation -1 -.5 0 children[ Shape{ appearance Appearance{ material Material{ emissiveColor 1 1 1 } } geometry DEF Net IndexedLineSet{ coord DEF NetCoord Coordinate{} } } ]} Transform{ translation -1.3 .2 0 children[ Shape{ appearance Appearance{ material Material{ diffuseColor 1 0 0} } geometry Sphere{ radius .1}} DEF tsPrint TouchSensor{}] } Transform{ translation -1.3 -.2 0 children[ Shape{ appearance Appearance{ material Material{ diffuseColor 0 1 0} } geometry Sphere{ radius .1}} DEF tsOut TouchSensor{}] } ]} DEF SCR Script{ eventIn SFVec3f setXY eventIn SFBool Print eventIn SFBool Out field SFNode Net USE Net field SFNode NetCoord USE NetCoord field SFNode spIFS USE spIFS field SFNode spCoord USE spCoord field SFNode TC USE TC field SFInt32 n IS n field SFInt32 m IS m field MFVec2f texCoord IS texCoord field MFVec3f points IS points directOutput TRUE url ["javascript: function initialize() { // Modeller eps = .001; nm = n*m; c = new MFInt32(); c.length = 2*nm+n+m+1; pm = new MFVec3f(); pm.length = nm; if (texCoord.length == 0){ stX=1./(n-1); stY=1./(m-1); y=0; t=0; for (j=0; j < m; j++){ x=0; for (i=0; i< n; i++){ texCoord[t] = new SFVec2f(x,y); pm[t++] = new SFVec3f(x,y,eps); x += stX;} y += stY;}} else for (t=0; t< nm; t++) pm[t] = new SFVec3f(texCoord[t].x,texCoord[t].y,eps); NetCoord.set_point = pm; t=0; for (j=0; j < m; j++){ for (i=0; i< n; i++) c[t++] = n*j + i; c[t++] = -1;} c[t++] = -1; for (i=0; i< n; i++){ for (j=0; j < m; j++) c[t++] = n*j + i; c[t++] = -1;} Net.set_coordIndex = c; // Splinse Grid num = 7; n2=n+2; m2=m+2; n3=3*n; n1=n-1; m1=m-1; num1=num-1; ns=n1*num1+1; ms=m1*num1+1; p = new MFVec3f(); p.length = m2*n2; cp = new MFVec3f(); cp.length = 9*m*n; sp = new MFVec3f(); sp.length = ns*(m1*num1+1); tc = new MFVec2f(); tc.length = m2*n2; ct = new MFVec2f(); ct.length = 9*m*n; st = new MFVec2f(); st.length = ns*(m1*num1+1); b0 = new MFFloat(); b0.length = num; b1 = new MFFloat(); b1.length = num; b2 = new MFFloat(); b2.length = num; b3 = new MFFloat(); b3.length = num; step=1.0/(num-1); for (i= 0; i< num; i++){ u = i*step; u1 = 1-u; u12 = u1*u1; u2 = u*u; b0[i] = u1*u12; b1[i] = 3*u*u12; b2[i] = 3*u2*u1; b3[i] = u*u2;} tp=0; t=n2; for (j=0; j < m; j++){ p[t++] = points[tp].add( points[tp].subtract(points[tp+1]) ); for (i=0; i< n; i++) p[t++] = points[tp++]; p[t++] = points[tp-1].add( points[tp-1].subtract(points[tp-2]) ); } n2m1=n2*(m+1)+1; nm1=n*(m-1); nm2=n*(m-2); for (i=0; i < n; i++){ p[i+1] = points[i].add( points[i].subtract(points[i+n]) ); p[i+n2m1] = points[i+nm1].add( points[i+nm1].subtract(points[i+nm2]) ); } ip=n2+1; ic=n3+1; for (j=0; j < m; j++){ for (i=0; i< n; i++){ du = p[ip+1].subtract(p[ip-1]).divide(6); dv = p[ip+n2].subtract(p[ip-n2]).divide(6); cp[ic] = p0 = p[ip++]; cp[ic+1] = p0.add(du); cp[ic-1] = p0.subtract(du); cp[ic+n3] = p0.add(dv); cp[ic-n3] = p0.subtract(dv); cp[ic+1+n3] = p0.add(du).add(dv); cp[ic-1+n3] = p0.subtract(du).add(dv); cp[ic+1-n3] = p0.add(du).subtract(dv); cp[ic-1-n3] = p0.subtract(du).subtract(dv); ic +=3;} ip +=2; ic += 2*n3; } for (j=0; j < m1; j++){ for (i=0; i < n1; i++){ ic=3*(j*n3+i)+n3+1; p0 = cp[ic++]; p1 = cp[ic++]; p2 = cp[ic++]; p3 = cp[ic]; ic += n3-3; p4 = cp[ic++]; p5 = cp[ic++]; p6 = cp[ic++]; p7 = cp[ic]; ic += n3-3; p8 = cp[ic++]; p9 = cp[ic++]; p10 = cp[ic++]; p11 = cp[ic]; ic += n3-3; p12 = cp[ic++]; p13 = cp[ic++]; p14 = cp[ic++]; p15 = cp[ic]; is=(j*ns+i)*num1; for (l= 0; l< num; l++) for (k= 0; k< num; k++){ d = p0.multiply(b0[k]).add(p1.multiply(b1[k])) .add(p2.multiply(b2[k])).add(p3.multiply(b3[k])).multiply(b0[l]); d = d.add(p4.multiply(b0[k]).add(p5.multiply(b1[k])) .add(p6.multiply(b2[k])).add(p7.multiply(b3[k])).multiply(b1[l])); d = d.add(p8.multiply(b0[k]).add(p9.multiply(b1[k])) .add(p10.multiply(b2[k])).add(p11.multiply(b3[k])).multiply(b2[l])); sp[is+l*ns+k] = d.add(p12.multiply(b0[k]).add(p13.multiply(b1[k])) .add(p14.multiply(b2[k])).add(p15.multiply(b3[k])).multiply(b3[l])); } } } spCoord.set_point = sp; setTex(); s = new MFInt32(); s.length = 8*(ns-1)*(ms-1); k=0; for (j= 0; j< ms-1; j++) for (i= 0; i< ns-1; i++) { s[k++] = i+ns*j+1; s[k++] = i+ns*j; s[k++] = i+ns*(j+1); s[k++] = -1; s[k++] = i+ns*(j+1); s[k++] = i+ns*(j+1)+1; s[k++]=i+ns*j+1; s[k++]=-1;} spIFS.set_coordIndex = s; } function setTex() { tp=0; t=n2; for (j=0; j < m; j++){ tc[t++] = texCoord[tp].add( texCoord[tp].subtract(texCoord[tp+1]) ); for (i=0; i< n; i++) tc[t++] = texCoord[tp++]; tc[t++] = texCoord[tp-1].add( texCoord[tp-1].subtract(texCoord[tp-2]) ); } n2m1=n2*(m+1)+1; nm1=n*(m-1); nm2=n*(m-2); for (i=0; i < n; i++){ tc[i+1] = texCoord[i].add( texCoord[i].subtract(texCoord[i+n]) ); tc[i+n2m1] = texCoord[i+nm1].add( texCoord[i+nm1].subtract(texCoord[i+nm2]) ); } ip=n2+1; ic=n3+1; for (j=0; j < m; j++){ for (i=0; i< n; i++){ tu = tc[ip+1].subtract(tc[ip-1]).divide(6); tv = tc[ip+n2].subtract(tc[ip-n2]).divide(6); ct[ic] = t0 = tc[ip++]; ct[ic+1] = t0.add(tu); ct[ic-1] = t0.subtract(tu); ct[ic+n3] = t0.add(tv); ct[ic-n3] = t0.subtract(tv); ct[ic+1+n3] = t0.add(tu).add(tv); ct[ic-1+n3] = t0.subtract(tu).add(tv); ct[ic+1-n3] = t0.add(tu).subtract(tv); ct[ic-1-n3] = t0.subtract(tu).subtract(tv); ic +=3;} ip +=2; ic += 2*n3; } for (j=0; j < m1; j++){ for (i=0; i < n1; i++){ ic=3*(j*n3+i)+n3+1; t0 = ct[ic++]; t1 = ct[ic++]; t2 = ct[ic++]; t3 = ct[ic]; ic += n3-3; t4 = ct[ic++]; t5 = ct[ic++]; t6 = ct[ic++]; t7 = ct[ic]; ic += n3-3; t8 = ct[ic++]; t9 = ct[ic++]; t10 = ct[ic++]; t11 = ct[ic]; ic += n3-3; t12 = ct[ic++]; t13 = ct[ic++]; t14 = ct[ic++]; t15 = ct[ic]; is=(j*ns+i)*num1; for (l= 0; l< num; l++) for (k= 0; k< num; k++){ d = t0.multiply(b0[k]).add(t1.multiply(b1[k])) .add(t2.multiply(b2[k])).add(t3.multiply(b3[k])).multiply(b0[l]); d = d.add(t4.multiply(b0[k]).add(t5.multiply(b1[k])) .add(t6.multiply(b2[k])).add(t7.multiply(b3[k])).multiply(b1[l])); d = d.add(t8.multiply(b0[k]).add(t9.multiply(b1[k])) .add(t10.multiply(b2[k])).add(t11.multiply(b3[k])).multiply(b2[l])); st[is+l*ns+k] = d.add(t12.multiply(b0[k]).add(t13.multiply(b1[k])) .add(t14.multiply(b2[k])).add(t15.multiply(b3[k])).multiply(b3[l])); } } } TC.set_point = st; } function setXY(val){ val.z = eps; t=0; mLen=1.; for (t=0; t< nm; t++){ len = pm[t].subtract(val).length(); if (len < mLen ){ mt = t; mLen = len;} } pm[mt] = val; NetCoord.set_point = pm; } function Print(val){ if(val) for (t=0; t< nm; t++) print(pm[t].x +' '+ pm[t].y); } function Out(val){ if(val){ for (t=0; t< nm; t++) texCoord[t] = new SFVec2f(pm[t].x, pm[t].y); setTex(); } } "]} ROUTE PS.trackPoint_changed TO SCR.setXY ROUTE tsPrint.isActive TO SCR.Print ROUTE tsOut.isActive TO SCR.Out } NavigationInfo{ type "EXAMINE" } Background{ skyColor .5 .5 1} Viewpoint{ position 0 0 8} TextureModeller{ n 5 m 7 urlImg "local/chaos/25.jpg" points[ -0.514562 -1.058253 0 -0.368931 -1.058253 0.242718 0.031416 -1.058253 0.208538 0.466020 -1.058253 0.271845 0.621360 -1.058253 0 -0.613834 0.000000 0 -0.417274 0.000000 0.251426 0.001080 0.000000 0.230549 0.485236 0.000000 0.284181 0.663587 0.000000 0 -0.433567 0.495145 0 -0.298888 0.495145 0.189008 0.002066 0.495145 0.273078 0.318306 0.495145 0.211936 0.460628 0.495145 0 -0.499656 0.834952 0 -0.388349 0.834952 0.242718 -0.009709 0.836939 0.331630 0.398058 0.834952 0.271845 0.527494 0.834952 0 -0.563106 1.140699 0.166905 -0.427184 1.135922 0.398058 -0.009708 1.135922 0.349515 0.407767 1.135922 0.427185 0.572816 1.141057 0.171276 -0.526243 1.407767 0 -0.322436 1.374663 0.236938 -0.015606 1.392720 0.244965 0.313696 1.383692 0.263655 0.515733 1.407767 0 -0.218060 1.572816 0 -0.213906 1.539712 0.113569 -0.022843 1.506608 0.217449 0.172062 1.539712 0.123843 0.182650 1.572816 0 ] # texCoord[ 0 0, 1 0, 0 1, 1 1] }