#X3D V3.2 utf8 PROFILE Interactive # Simple RenderedTexture test. # # Teapot is inside EditableTransform, so you can interactively # move it/rotate etc., see ../dynamic_world.x3dv. # ---------------------------------------------------------------------------- # Content of "children" can be moved/scaled/rotated by the user # by clicking (making TouchSensor active) and then holding various keys. PROTO EditableTransform [ inputOutput MFNode children [] inputOutput SFVec3f translation 0 0 0 inputOutput SFVec3f scale 1 1 1 inputOutput SFString description "" ] { Transform { children [ DEF Trans Transform { translation IS translation scale IS scale children IS children } DEF Touch TouchSensor { description IS description } DEF Key KeySensor { } DEF Time TimeSensor { loop TRUE cycleInterval 10000000 } DEF Scr Script { # Input to script from touch and key sensors. # isActive is inputOutput, as it's value must be saved (for use # in time function). inputOutput SFBool isActive FALSE inputOnly SFString keyPress inputOnly SFString keyRelease # Output from script to translation. # Initialized to the same values as Trans, so they match at the start. # (rotation is just initialized directly, it cannot be changed # by PROTO caller, as we assume here that rotation dir = 0, 1, 0) inputOutput SFVec3f translation IS translation inputOutput SFVec3f scale IS scale inputOutput SFRotation rotation 0 1 0 0 # Variables storing keys state, needed by time, # modified by keyPress/Release. initializeOnly SFBool f_pressed FALSE initializeOnly SFBool s_pressed FALSE initializeOnly SFBool e_pressed FALSE initializeOnly SFBool d_pressed FALSE initializeOnly SFBool w_pressed FALSE initializeOnly SFBool r_pressed FALSE initializeOnly SFBool i_pressed FALSE initializeOnly SFBool j_pressed FALSE initializeOnly SFBool k_pressed FALSE initializeOnly SFBool l_pressed FALSE initializeOnly SFBool u_pressed FALSE initializeOnly SFBool o_pressed FALSE initializeOnly SFBool m_pressed FALSE initializeOnly SFBool n_pressed FALSE # Variables storing time difference, for time-based animation. initializeOnly SFTime previousTime -1 initializeOnly SFTime timeDiff 0 inputOnly SFTime time # This is a constant, feel free to change to suit your taste. initializeOnly SFTime editSpeed 2 url "kambiscript: function keyPress(value, time) when (isActive, if (value = 'f', f_pressed := true, if (value = 's', s_pressed := true, if (value = 'e', e_pressed := true, if (value = 'd', d_pressed := true, if (value = 'w', w_pressed := true, if (value = 'r', r_pressed := true, if (value = 'i', i_pressed := true, if (value = 'j', j_pressed := true, if (value = 'k', k_pressed := true, if (value = 'l', l_pressed := true, if (value = 'u', u_pressed := true, if (value = 'o', o_pressed := true, if (value = 'm', m_pressed := true, when (value = 'n', n_pressed := true ))))))))))))))) function keyRelease(value, time) { respect key releases even when not isActive, otherwise (if isActive would get false before user released the key) we would keep *_pressed = true in infinity. } if (value = 'f', f_pressed := false, if (value = 's', s_pressed := false, if (value = 'e', e_pressed := false, if (value = 'd', d_pressed := false, if (value = 'w', w_pressed := false, if (value = 'r', r_pressed := false, if (value = 'i', i_pressed := false, if (value = 'j', j_pressed := false, if (value = 'k', k_pressed := false, if (value = 'l', l_pressed := false, if (value = 'u', u_pressed := false, if (value = 'o', o_pressed := false, if (value = 'm', m_pressed := false, when (value = 'n', n_pressed := false )))))))))))))) function time(value, timestamp) { calculate timeDiff, to scale animations (so that it runs with the same speed on every system) } timeDiff := if (previousTime >= 0, value - previousTime, 0); { update previousTime } previousTime := value; when (f_pressed, vector_set(translation, 0, vector_get(translation, 0) - editSpeed * timeDiff)); when (s_pressed, vector_set(translation, 0, vector_get(translation, 0) + editSpeed * timeDiff)); when (e_pressed, vector_set(translation, 2, vector_get(translation, 2) + editSpeed * timeDiff)); when (d_pressed, vector_set(translation, 2, vector_get(translation, 2) - editSpeed * timeDiff)); when (w_pressed, vector_set(translation, 1, vector_get(translation, 1) - editSpeed * timeDiff)); when (r_pressed, vector_set(translation, 1, vector_get(translation, 1) + editSpeed * timeDiff)); when (l_pressed, vector_set(scale, 0, max(vector_get(scale, 0) - editSpeed * timeDiff, 0.01))); when (j_pressed, vector_set(scale, 0, vector_get(scale, 0) + editSpeed * timeDiff)); when (i_pressed, vector_set(scale, 2, vector_get(scale, 2) + editSpeed * timeDiff)); when (k_pressed, vector_set(scale, 2, max(vector_get(scale, 2) - editSpeed * timeDiff, 0.01))); when (u_pressed, vector_set(scale, 1, max(vector_get(scale, 1) - editSpeed * timeDiff, 0.01))); when (o_pressed, vector_set(scale, 1, vector_get(scale, 1) + editSpeed * timeDiff)); when (m_pressed, vector_set(rotation, 3, vector_get(rotation, 3) - editSpeed * timeDiff)); when (n_pressed, vector_set(rotation, 3, vector_get(rotation, 3) + editSpeed * timeDiff)) " } ] } ROUTE Touch.isActive TO Scr.isActive ROUTE Key.keyPress TO Scr.keyPress ROUTE Key.keyRelease TO Scr.keyRelease ROUTE Time.elapsedTime TO Scr.time ROUTE Scr.translation TO Trans.translation ROUTE Scr.scale TO Trans.scale ROUTE Scr.rotation TO Trans.rotation } # testing teapot ------------------------------------------------------------- # Camera settings "encoded" in the VRML declaration below : # direction 0.0162931103259325 -0.0087941382080316 0.0075629726052284 # up 0.398832231760025 0.8981400728225708 0.1851321160793304 # gravityUp 0 1 0 Viewpoint { position -10.518335342407227 6.0124320983886719 -2.6900680065155029 orientation -0.1425759643316268 -0.9642499685287475 -0.223369762301445 2.0381448268890381 } NavigationInfo { type "FLY" speed 10 } EditableTransform { children DEF DynamicTrans Transform { translation 0 0 -3 children Shape { appearance Appearance { material Material { diffuseColor 1 1 0 } } geometry Teapot { } } } } DEF Time TimeSensor { loop TRUE cycleInterval 10 } DEF Orient OrientationInterpolator { key [ 0 1 ] keyValue [ 0 0 1 0, 0 0 1 6.2831853072 # 2*pi ] } ROUTE Time.fraction_changed TO Orient.set_fraction ROUTE Orient.value_changed TO DynamicTrans.rotation # Testing box prototype ------------------------------------------------------ PROTO TestingBox [ inputOutput SFNode appearance NULL inputOutput MFString string "" ] { Group { children [ Shape { appearance IS appearance geometry Box { } } Transform { translation 0 2 0 rotation 0 1 0 -1.7 children Shape { geometry Text { string IS string fontStyle FontStyle { size 0.3 justify "MIDDLE" } } } } ] } } # box with RenderedTexture --------------------------------------------------- TestingBox { string "Explicit viewpoint" appearance Appearance { material Material { } texture RenderedTexture { update "ALWAYS" dimensions [ 512 512 ] repeatS FALSE repeatT FALSE viewpoint # Camera settings "encoded" in the VRML declaration below : # direction 0.0179050657898187 -0.008794137276709 -0.0014395721955224 # up 0.4382922053337097 0.898141324520111 -0.0352372489869594 # gravityUp 0 1 0 Viewpoint { position -4.4447846412658691 2.2520251274108887 -1.0610120296478271 orientation -0.2375470995903015 -0.9463170766830444 -0.2192159593105316 1.5456631183624268 } # Test this will cause appropriate warning and size will change to 32 x 32 # dimensions [ 32 32 ] } shaders DEF MyShader ComposedShader { language "GLSL" parts [ ShaderPart { type "FRAGMENT" url "uniform sampler2D tex; void main(void) { gl_FragColor = texture2D(tex, gl_TexCoord[0].st) * gl_Color; // add some ambient gl_FragColor.rgb += vec3(0.1, 0.1, 0.1); } " } ] } } } # box with RenderedTexture --------------------------------------------------- Transform { translation 0 0 3 children TestingBox { string "Repeat 2x" appearance Appearance { material Material { } texture RenderedTexture { update "ALWAYS" dimensions [ 512 512 ] repeatS TRUE repeatT TRUE } # Test TextureTransform (and repeatS/T) work Ok textureTransform TextureTransform { scale 2 2 } shaders USE MyShader } } } # box with RenderedTexture --------------------------------------------------- Transform { translation 0 0 6 children TestingBox { string [ "depthMap" "(and explicit viewpoint)" ] appearance Appearance { material Material { } texture RenderedTexture { update "ALWAYS" dimensions [ 512 512 ] repeatS FALSE repeatT FALSE # Test depthMap depthMap TRUE viewpoint # Camera settings "encoded" in the VRML declaration below : # direction 0.0199739690870046 -0.0006295652128756 0.0008271657861769 # up 0.0314487889409065 0.9994763731956481 0.001302644261159 # gravityUp 0 1 0 Viewpoint { position -2.3980166912078857 -0.4101448059082031 -3.1834867000579834 orientation -0.0151009261608123 -0.9997622370719909 -0.0157377813011407 1.6124224662780762 } } shaders USE MyShader } } } # box with RenderedTexture --------------------------------------------------- Transform { translation 0 0 9 children TestingBox { string "Pixelated" appearance Appearance { material Material { } texture RenderedTexture { update "ALWAYS" repeatS FALSE repeatT FALSE # Test this will cause texture to look with blocky pixels dimensions [ 32 32 ] textureProperties TextureProperties { minificationFilter "NEAREST_PIXEL" magnificationFilter "NEAREST_PIXEL" } } shaders USE MyShader } } }