// new three broke it? // http://www.clicktorelease.com/code/perlin/explosion.html // http://www.webgl.com/2013/01/webgl-tutorial-vertex-displacement-with-a-noise-function-aka-fiery-explosion/ /// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IDefault page = null) { // http://inear.se/fireshader/ // http://stackoverflow.com/questions/16765120/ashima-perlin-noise-shader-not-working-with-recent-versions-of-three-js //var container, renderer, camera, mesh; var start = IDate.Now; var fov = 30; #region container Native.document.body.style.overflow = IStyle.OverflowEnum.hidden; var container = new IHTMLDiv(); container.AttachToDocument(); container.style.backgroundColor = "#000000"; container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height); #endregion var scene = new THREE.Scene(); var bkgScene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(fov, Native.window.aspect, 1, 10000); camera.position.z = 100; //camera.target = new THREE.Vector3(0, 0, 0); scene.add(camera); var bkgCamera = new THREE.OrthographicCamera( Native.window.Width / -2, Native.window.Width / 2, Native.window.Height / 2, Native.window.Height / -2, -10000, 10000 ); bkgScene.add(bkgCamera); var bkgShader = new THREE.ShaderMaterial( new { uniforms = new { tDiffuse = new { type = "t", value = THREE.ImageUtils.loadTexture( new HTML.Images.FromAssets.bkg().src ) }, resolution = new { type = "v2", value = new THREE.Vector2(Native.window.Width, Native.window.Height) } }, vertexShader = new Shaders.ExplosionVertexShader().ToString(), // fragmentShader: document.getElementById( 'fs_Gradient' ).textContent, //fragmentShader = new Shaders.GradientFragmentShader().ToString(), fragmentShader = new Shaders.ExplosionFragmentShader().ToString(), depthWrite = false, depthTest = false, transparent = true } ); var quad = new THREE.Mesh(new THREE.PlaneGeometry(Native.window.Width, Native.window.Height), bkgShader); quad.position.z = -100; quad.rotation.x = (float)Math.PI / 2; bkgScene.add(quad); var material = new THREE.ShaderMaterial( new { uniforms = new // material_uniforms { tExplosion = new //uniforms_item { type = "t", value = THREE.ImageUtils.loadTexture( new HTML.Images.FromAssets.explosion().src ) }, time = new { type = "f", value = 0.0 }, weight = new { type = "f", value = 8.0 }, }, vertexShader = new Shaders.ExplosionVertexShader().ToString(), fragmentShader = new Shaders.ExplosionFragmentShader().ToString(), depthWrite = false, depthTest = false, transparent = true } ); var mesh = new THREE.Mesh(new THREE.SphereGeometry(20, 200, 200), material); scene.add(mesh); var renderer = new THREE.WebGLRenderer(); renderer.setSize(Native.window.Width, Native.window.Height); renderer.autoClear = false; container.appendChild(renderer.domElement); var lon = 0.0; var phi = 0.0; var theta = 0.0; var lat = 15.0; var isUserInteracting = false; var scale = 0.0; #region render Native.window.onframe += delegate { ((material_uniforms)material.uniforms).time.value = .00025 * (IDate.Now - start); scale += .005; scale %= 2; lat = Math.Max(-85, Math.Min(85, lat)); phi = (90 - lat) * Math.PI / 180; theta = lon * Math.PI / 180; camera.position.x = (float)(100 * Math.Sin(phi) * Math.Cos(theta)); camera.position.y = (float)(100 * Math.Cos(phi)); camera.position.z = (float)(100 * Math.Sin(phi) * Math.Sin(theta)); //mesh.rotation.x += .012; //mesh.rotation.y += .01; camera.lookAt(scene.position); // //renderer.render( bkgScene, bkgCamera ); renderer.render(scene, camera); // stats.update(); }; #endregion #region IsDisposed Dispose = delegate { if (IsDisposed) return; IsDisposed = true; container.Orphanize(); }; #endregion #region AtResize Action AtResize = delegate { container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height); renderer.setSize(Native.window.Width, Native.window.Height); camera.projectionMatrix.makePerspective(fov, Native.window.aspect, 1, 1100); //camera.aspect = Native.Window.Width / Native.Window.Height; //camera.updateProjectionMatrix(); }; Native.window.onresize += delegate { AtResize(); }; AtResize(); #endregion var ze = new ZeProperties(); ze.Show(); ze.treeView1.Nodes.Clear(); ze.Add(() => renderer); //ze.Add(() => controls); ze.Add(() => scene); ze.Left = 0; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // https://chrome.google.com/webstore/detail/dglmddjmdpdbijfkoaiadbpmjampfdjh/publish-delayed #region ChromeTCPServer dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_socket = self_chrome.socket; if (self_chrome_socket != null) { #region AtFormCreated FormStyler.AtFormCreated = ss => { ss.Context.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; // this is working? var x = new ChromeTCPServerWithFrameNone.HTML.Pages.AppWindowDrag().AttachTo(ss.Context.GetHTMLTarget()); }; #endregion chrome.Notification.DefaultTitle = "Heat Zeeker"; chrome.Notification.DefaultIconUrl = new HTML.Images.FromAssets.Promotion3D_iso1_tiltshift_128().src; ChromeTCPServer.TheServerWithStyledForm.Invoke( AppSource.Text, AtFormCreated: FormStyler.AtFormCreated ); return; } #endregion Native.body.style.margin = "0px"; Native.body.style.overflow = IStyle.OverflowEnum.hidden; // jsc, add THREE // ... ok. // X:\jsc.svn\examples\javascript\WebGL\WebGLOrthographicCamera\WebGLOrthographicCamera\Application.cs // this is not isometric. // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151112 var camera = new THREE.OrthographicCamera( Native.window.Width / -2, Native.window.Width / 2, Native.window.Height / 2, Native.window.Height / -2 , // if we change these values what will change? -1000, 1000 ); camera.position.x = 200; camera.position.y = 100; camera.position.z = 200; var scene = new THREE.Scene(); // Grid var size = 600; var step = 50; Func<double> random = new Random().NextDouble; // how do I add a new ground box? { var geometry = new THREE.BoxGeometry(size * 2, 2, size * 2); var material = new THREE.MeshLambertMaterial(new { color = 0xB27D51 // , shading = THREE.FlatShading, overdraw = 0.5 }); { var cube = new THREE.Mesh(geometry, material); // why cant we get the shadows?? cube.receiveShadow = true; cube.scale.y = Math.Floor(random() * 2 + 1); cube.position.x = 0; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.y = -2; cube.position.z = 0; scene.add(cube); } } { var geometry = new THREE.Geometry(); for (var i = -size; i <= size; i += step) { ((IArray<THREE.Vector3>)(object)geometry.vertices).push(new THREE.Vector3(-size, 0, i)); ((IArray<THREE.Vector3>)(object)geometry.vertices).push(new THREE.Vector3(size, 0, i)); ((IArray<THREE.Vector3>)(object)geometry.vertices).push(new THREE.Vector3(i, 0, -size)); ((IArray<THREE.Vector3>)(object)geometry.vertices).push(new THREE.Vector3(i, 0, size)); } var material = new THREE.LineBasicMaterial(new { color = 0, opacity = 0.2 }); var line = new THREE.Line(geometry, material, mode: THREE.LinePieces); scene.add(line); } var interactiveObjects = new List<THREE.Object3D>(); #region Cubes { for (var i = 0; i < 8; i++) { new HZBunker().Source.Task.ContinueWithResult( cube => { // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 2.0; cube.scale.y = 2.0; cube.scale.z = 2.0; //cube.castShadow = true; //dae.receiveShadow = true; cube.position.x = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; scene.add(cube); interactiveObjects.Add(cube); } ); new HZWaterTower().Source.Task.ContinueWithResult( cube => { // https://github.com/mrdoob/three.js/issues/1285 // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); // http://stackoverflow.com/questions/15906248/three-js-objloader-obj-model-not-casting-shadows // http://stackoverflow.com/questions/22895120/imported-3d-objects-are-not-casting-shadows-with-three-js //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 2.0; cube.scale.y = 2.0; cube.scale.z = 2.0; //cube.castShadow = true; //dae.receiveShadow = true; cube.position.x = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; scene.add(cube); interactiveObjects.Add(cube); } ); new HZCannon().Source.Task.ContinueWithResult( cube => { // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 2.0; cube.scale.y = 2.0; cube.scale.z = 2.0; //cube.castShadow = true; //dae.receiveShadow = true; cube.position.x = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; // if i want to rotate, how do I do it? //cube.rotation.z = random() + Math.PI; //cube.rotation.x = random() + Math.PI; cube.rotation.y = random() * Math.PI * 2; scene.add(cube); interactiveObjects.Add(cube); } ); } } #endregion // we need expression evaluator with intellisense for live debugging sessions #region Lights var ambientLight = new THREE.AmbientLight((int)(random() * 0x10)); scene.add(ambientLight); // can we get our shadows? { var directionalLight = new THREE.DirectionalLight((int)(random() * 0xffffff), 0.5); directionalLight.position.x = random() - 0.5; directionalLight.position.y = 400; directionalLight.position.z = random() - 0.5; directionalLight.position.normalize(); scene.add(directionalLight); } { var directionalLight = new THREE.DirectionalLight((int)(random() * 0xffffff), 0.5); directionalLight.position.x = random() - 0.5; directionalLight.position.y = 400; directionalLight.position.z = random() - 0.5; directionalLight.position.normalize(); scene.add(directionalLight); } #endregion //var renderer = new THREE.CanvasRenderer(); var renderer = new THREE.WebGLRenderer(); renderer.shadowMapEnabled = true; // background-color: #B27D51; renderer.setClearColor(0xB27D51); //renderer.setSize( // Native.window.Width , // Native.window.Height * 10 // ); renderer.setSize(); renderer.domElement.AttachToDocument(); Native.window.onresize += delegate { camera.left = Native.window.Width / -2; camera.right = Native.window.Width / 2; camera.top = Native.window.Height / 2; camera.bottom = Native.window.Height / -2; camera.updateProjectionMatrix(); renderer.setSize(); }; //window.addEventListener( 'resize', onWindowResize, false ); //#region Comanche //new Comanche().Source.Task.ContinueWithResult( // Comanche => // { // Comanche.position.y = 200; // //dae.position.z = 280; // Comanche.AttachTo(scene); // //scene.add(dae); // //oo.Add(Comanche); // // wont do it // //dae.castShadow = true; // // http://stackoverflow.com/questions/15492857/any-way-to-get-a-bounding-box-from-a-three-js-object3d // //var helper = new THREE.BoundingBoxHelper(dae, 0xff0000); // //helper.update(); // //// If you want a visible bounding box // //scene.add(helper); // Comanche.children[0].children[0].children.WithEach(x => x.castShadow = true); // // the rotors? // Comanche.children[0].children[0].children.Last().children.WithEach(x => x.castShadow = true); // Comanche.scale.set(0.5, 0.5, 0.5); // //helper.scale.set(0.5, 0.5, 0.5); // var sw = Stopwatch.StartNew(); // Native.window.onframe += delegate // { // //dae.children[0].children[0].children.Last().al // //dae.children[0].children[0].children.Last().rotation.z = sw.ElapsedMilliseconds * 0.01; // //dae.children[0].children[0].children.Last().rotation.x = sw.ElapsedMilliseconds * 0.01; // //rotation.y = sw.ElapsedMilliseconds * 0.01; // Comanche.children[0].children[0].children.Last().rotation.y = sw.ElapsedMilliseconds * 0.001; // //dae.children[0].children[0].children.Last().app // }; // } //); //#endregion //#region ee //// X:\jsc.svn\examples\javascript\forms\NumericTextBox\NumericTextBox\ApplicationControl.cs //// can we restile the window as the pin window in IDE? //var ee = new Form { Left = 0, StartPosition = FormStartPosition.Manual }; //var ee_camera_y = new TextBox { Dock = DockStyle.Fill, Text = camera.position.y + "" }.AttachTo(ee); ////ee.AutoSize = AutoSizeMode. ////ee.ClientSize = new System.Drawing.Size(ee_camera_y.Width, ee_camera_y.Height); //ee.ClientSize = new System.Drawing.Size(200, 24); //ee.Show(); ////ee_camera_y. //ee_camera_y.TextChanged += delegate //{ // camera.position.y = double.Parse(ee_camera_y.Text); //}; //#endregion var s = Stopwatch.StartNew(); var controls = new THREE.OrbitControls(camera, renderer.domElement); // http://stackoverflow.com/questions/26497903/nested-webglrendertargets-in-three-js // var effect = new THREE.OculusRiftEffect( //renderer, new //{ // worldScale = 100, // //HMD // } //); // effect.setSize(1920, 1080); Native.window.onframe += e => { // jsc, when can we have the edit and continue already? //var timer = s.ElapsedMilliseconds * 0.1; //var timer = s.ElapsedMilliseconds * 0.0001; //camera.position.x = Math.Cos(timer) * 200; //camera.position.z = Math.Sin(timer) * 200; // camera.position.z = 200; //camera.position.y = 100; //camera.position.y = Math.Sin(timer * 0.1) * 200; controls.update(); camera.position = controls.center.clone(); renderer.render(scene, camera); //effect.render(scene, camera); }; //var ze = new ZeProperties(); //ze.Show(); //ze.treeView1.Nodes.Clear(); //ze.Add(() => renderer); ////ze.Add(() => controls); //ze.Add(() => scene); //ze.Left = 0; // view-source:http://mrdoob.github.io/three.js/examples/webgl_interactive_voxelpainter.html //var mouse2D = new THREE.Vector3(0, 10000, 0.5); //renderer.domElement.onclick += // e => // { // e.preventDefault(); // mouse2D.x = (e.CursorX / (double)Native.window.Width) * 2 - 1; // mouse2D.y = -(e.CursorY / (double)Native.window.Height) * 2 + 1; // var vector = new THREE.Vector3( // (e.CursorX / (double)Native.window.Width) * 2 - 1, // -(e.CursorY / (double)Native.window.Height) * 2 + 1, // 0.5); // // X:\jsc.svn\examples\javascript\WebGL\WebGLInteractiveCubes\WebGLInteractiveCubes\Application.cs // var projector = new THREE.Projector(); // projector.unprojectVector(vector, camera); // // http://stackoverflow.com/questions/18553209/orthographic-camera-and-selecting-objects-with-raycast // // http://stackoverflow.com/questions/20361776/orthographic-camera-and-pickingray // // view-source:http://stemkoski.github.io/Three.js/Mouse-Click.html // // http://stackoverflow.com/questions/11921033/projector-and-ray-with-orthographiccamera // // use picking ray since it's an orthographic camera // // doesnt fkin work ??? // //var raycaster = projector.pickingRay(vector, camera); // var raycaster = projector.pickingRay(mouse2D.clone(), camera); // //var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize()); // var intersects = raycaster.intersectObjects(interactiveObjects.ToArray()); // // https://github.com/mrdoob/three.js/issues/599 // Native.document.title = new { intersects.Length }.ToString(); // }; }
// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150809/chrome360hz // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150809/chromeequirectangularcameraexperiment // "x:\util\android-sdk-windows\platform-tools\adb.exe" install -r "r:\jsc.svn\examples\javascript\WebGL\WebGLVRHZTeaser\WebGLVRHZTeaser\bin\Debug\staging\WebGLVRHZTeaser.ApplicationWebService\staging.apk\staging\apk\bin\WebGLVRHZTeaser.Activities-release.apk" //I/Web Console(25108): 0ms NewInstanceConstructor restore fields.. at http://10.144.157.179:23222/view-source:50800 //I/Web Console(25108): THREE.WebGLRenderer at http://10.144.157.179:23222/view-source:90370 //E/Web Console(25108): Error creating WebGL context. at http://10.144.157.179:23222/view-source:90581 //E/Web Console(25108): Uncaught TypeError: Cannot read property 'getShaderPrecisionFormat' of null at http://10.144.157.179:23222/view-source:90585 /// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { #if false #region += Launched chrome.app.window // X:\jsc.svn\examples\javascript\chrome\apps\ChromeTCPServerAppWindow\ChromeTCPServerAppWindow\Application.cs dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_socket = self_chrome.socket; if (self_chrome_socket != null) { chrome.Notification.DefaultTitle = "HZ"; chrome.Notification.DefaultIconUrl = new HTML.Images.FromAssets.Preview().src; ChromeTCPServer.TheServerWithAppWindow.Invoke(AppSource.Text); return; } #endregion #endif // https://code.google.com/p/chromium/issues/detail?id=483890 Native.document.body.style.margin = "0px"; Native.document.body.style.overflow = IStyle.OverflowEnum.hidden; Native.body.style.backgroundColor = "black"; Native.document.body.Clear(); // what dto do if webgl not supported? double SCREEN_WIDTH = Native.window.Width; double SCREEN_HEIGHT = Native.window.Height; #region scene var scene = new THREE.Scene(); var clock = new THREE.Clock(); var sceneRenderTarget = new THREE.Scene(); var cameraOrtho = new THREE.OrthographicCamera( (int)SCREEN_WIDTH / -2, (int)SCREEN_WIDTH / 2, (int)SCREEN_HEIGHT / 2, (int)SCREEN_HEIGHT / -2, -100000, 100000 ); cameraOrtho.position.z = 100; sceneRenderTarget.add(cameraOrtho); var camera = new THREE.PerspectiveCamera( //40, 20, //10, Native.window.aspect, 2, // how far out do we want to zoom? 200000 //9000 ); camera.position.set(-1200, 800, 1200); var target = new THREE.Vector3(0, 0, 0); scene.add(camera); //scene.add(new THREE.AmbientLight(0x212121)); //var spotLight = new THREE.SpotLight(0xffffff, 1.15); //spotLight.position.set(500, 2000, 0); //spotLight.castShadow = true; //scene.add(spotLight); //var pointLight = new THREE.PointLight(0xff4400, 1.5); //pointLight.position.set(0, 0, 0); //scene.add(pointLight); //scene.add(new THREE.AmbientLight(0xaaaaaa)); scene.add(new THREE.AmbientLight(0x101030)); #endregion #region light //var light = new THREE.DirectionalLight(0xffffff, 1.0); var light = new THREE.DirectionalLight(0xffffff, 2.5); //var light = new THREE.DirectionalLight(0xffffff, 2.5); //var light = new THREE.DirectionalLight(0xffffff, 1.5); //var lightOffset = new THREE.Vector3(0, 1000, 2500.0); var lightOffset = new THREE.Vector3( 2000, 700, // lower makes longer shadows 700.0 ); light.position.copy(lightOffset); light.castShadow = true; var xlight = light as dynamic; xlight.shadowMapWidth = 4096; xlight.shadowMapHeight = 2048; xlight.shadowDarkness = 0.1; //xlight.shadowDarkness = 0.5; xlight.shadowCameraNear = 10; xlight.shadowCameraFar = 10000; xlight.shadowBias = 0.00001; xlight.shadowCameraRight = 4000; xlight.shadowCameraLeft = -4000; xlight.shadowCameraTop = 4000; xlight.shadowCameraBottom = -4000; xlight.shadowCameraVisible = true; scene.add(light); #endregion var renderer = new THREE.WebGLRenderer( new { // http://stackoverflow.com/questions/20495302/transparent-background-with-three-js alpha = true, preserveDrawingBuffer = true, antialias = true } ); renderer.setSize(1920, 1080); //renderer.setSize(2560, 1440); renderer.domElement.AttachToDocument(); renderer.shadowMapEnabled = true; renderer.shadowMapType = THREE.PCFSoftShadowMap; var renderTarget = new THREE.WebGLRenderTarget( Native.window.Width, Native.window.Height, new { minFilter = THREE.LinearFilter, magFilter = THREE.LinearFilter, format = THREE.RGBAFormat, stencilBufer = false } ); //var composer = new THREE.EffectComposer(renderer, renderTarget); //var renderModel = new THREE.RenderPass(scene, camera); //composer.addPass(renderModel); //#region vblur //var hblur = new THREE.ShaderPass(THREE.HorizontalTiltShiftShader); //var vblur = new THREE.ShaderPass(THREE.VerticalTiltShiftShader); ////var bluriness = 6.0; //var bluriness = 4.0; //// Show Details Severity Code Description Project File Line ////Error CS0656 Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' WebGLTiltShift Application.cs 183 //(hblur.uniforms as dynamic).h.value = bluriness / Native.window.Width; //(vblur.uniforms as dynamic).v.value = bluriness / Native.window.Height; //(hblur.uniforms as dynamic).r.value = 0.5; //(vblur.uniforms as dynamic).r.value = 0.5; ////vblur.renderToScreen = true; //composer.addPass(hblur); //composer.addPass(vblur); //#endregion // Uncaught TypeError: renderer.setSize is not a function // Uncaught TypeError: renderer.getClearColor is not a function var effect = new THREE.OculusRiftEffect( renderer, // how to get the vblur into oculus effect? //renderModel, //composer, //renderTarget, new { worldScale = 100, //HMD } ); effect.setSize(1920, 1080); //effect.setSize(2560, 1440); #region WebGLRah66Comanche // why isnt it being found? // "Z:\jsc.svn\examples\javascript\WebGL\collada\WebGLRah66Comanche\WebGLRah66Comanche\WebGLRah66Comanche.csproj" new global::WebGLRah66Comanche.Comanche( ).Source.Task.ContinueWithResult( dae => { //dae.position.y = -40; //dae.position.z = 280; scene.add(dae); //oo.Add(dae); // wont do it //dae.castShadow = true; dae.children[0].children[0].children.WithEach(x => x.castShadow = true); // the rotors? dae.children[0].children[0].children.Last().children.WithEach(x => x.castShadow = true); dae.scale.set(0.5, 0.5, 0.5); dae.position.x = -900; dae.position.z = +900; // raise it up dae.position.y = 400; //var sw = Stopwatch.StartNew(); //Native.window.onframe += delegate //{ // //dae.children[0].children[0].children.Last().al // //dae.children[0].children[0].children.Last().rotation.z = sw.ElapsedMilliseconds * 0.01; // //dae.children[0].children[0].children.Last().rotation.x = sw.ElapsedMilliseconds * 0.01; // dae.children[0].children[0].children.Last().rotation.y = sw.ElapsedMilliseconds * 0.01; //}; } ); #endregion #region tree // X:\jsc.svn\examples\javascript\WebGL\WebGLGodRay\WebGLGodRay\Application.cs var materialScene = new THREE.MeshBasicMaterial(new { color = 0x000000, shading = THREE.FlatShading }); var tloader = new THREE.JSONLoader(); // http://stackoverflow.com/questions/16539736/do-not-use-system-runtime-compilerservices-dynamicattribute-use-the-dynamic // https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.dynamicattribute%28v=vs.110%29.aspx //System.Runtime.CompilerServices.DynamicAttribute tloader.load( new WebGLGodRay.Models.tree().Content.src, new Action<THREE.Geometry>( xgeometry => { var treeMesh = new THREE.Mesh(xgeometry, materialScene); treeMesh.position.set(0, -150, -150); treeMesh.position.x = -900; treeMesh.position.z = -900; treeMesh.position.y = 25; var tsc = 400; treeMesh.scale.set(tsc, tsc, tsc); treeMesh.matrixAutoUpdate = false; treeMesh.updateMatrix(); treeMesh.AttachTo(scene); } ) ); #endregion #region create field // THREE.PlaneGeometry: Consider using THREE.PlaneBufferGeometry for lower memory footprint. // could we get some film grain? var planeGeometry = new THREE.CubeGeometry(512, 512, 1); var plane = new THREE.Mesh(planeGeometry, new THREE.MeshPhongMaterial(new { ambient = 0x101010, color = 0xA26D41, specular = 0xA26D41, shininess = 1 }) ); //plane.castShadow = false; plane.receiveShadow = true; { var parent = new THREE.Object3D(); parent.add(plane); parent.rotation.x = -Math.PI / 2; parent.scale.set(10, 10, 10); scene.add(parent); } var random = new Random(); var meshArray = new List<THREE.Mesh>(); var geometry = new THREE.CubeGeometry(1, 1, 1); var sw = Stopwatch.StartNew(); for (var i = 3; i < 9; i++) { //THREE.MeshPhongMaterial var ii = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial(new { ambient = 0x000000, color = 0xA06040, specular = 0xA26D41, shininess = 1 }) //new THREE.MeshLambertMaterial( //new //{ // color = (Convert.ToInt32(0xffffff * random.NextDouble())), // specular = 0xffaaaa, // ambient= 0x050505, //}) ); ii.position.x = i % 7 * 200 - 2.5f; // raise it up ii.position.y = .5f * 100; ii.position.z = -1 * i * 100; ii.castShadow = true; ii.receiveShadow = true; //ii.scale.set(100, 100, 100 * i); ii.scale.set(100, 100 * i, 100); meshArray.Add(ii); scene.add(ii); if (i % 2 == 0) { #if FWebGLHZBlendCharacter #region SpeedBlendCharacter var _i = i; { WebGLHZBlendCharacter.HTML.Pages.TexturesImages ref0; } var blendMesh = new THREE.SpeedBlendCharacter(); blendMesh.load( new WebGLHZBlendCharacter.Models.marine_anims().Content.src, new Action( delegate { // buildScene //blendMesh.rotation.y = Math.PI * -135 / 180; blendMesh.castShadow = true; // we cannot scale down we want our shadows //blendMesh.scale.set(0.1, 0.1, 0.1); blendMesh.position.x = (_i + 2) % 7 * 200 - 2.5f; // raise it up //blendMesh.position.y = .5f * 100; blendMesh.position.z = -1 * _i * 100; var xtrue = true; // run blendMesh.setSpeed(1.0); // will in turn call THREE.AnimationHandler.play( this ); //blendMesh.run.play(); // this wont help. bokah does not see the animation it seems. //blendMesh.run.update(1); blendMesh.showSkeleton(!xtrue); scene.add(blendMesh); Native.window.onframe += delegate { blendMesh.rotation.y = Math.PI * 0.0002 * sw.ElapsedMilliseconds; ii.rotation.y = Math.PI * 0.0002 * sw.ElapsedMilliseconds; }; } ) ); #endregion #endif } } #endregion #region HZCannon new HeatZeekerRTSOrto.HZCannon().Source.Task.ContinueWithResult( async cube => { // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // //child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 10.0; cube.scale.y = 10.0; cube.scale.z = 10.0; //cube.castShadow = true; //dae.receiveShadow = true; //cube.position.x = -100; ////cube.position.y = (cube.scale.y * 50) / 2; //cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; // if i want to rotate, how do I do it? //cube.rotation.z = random() + Math.PI; //cube.rotation.x = random() + Math.PI; var sw2 = Stopwatch.StartNew(); scene.add(cube); //interactiveObjects.Add(cube); // offset is wrong //while (true) //{ // await Native.window.async.onframe; // cube.rotation.y = Math.PI * 0.0002 * sw2.ElapsedMilliseconds; //} } ); #endregion #region HZCannon new HeatZeekerRTSOrto.HZCannon().Source.Task.ContinueWithResult( async cube => { // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // //child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 10.0; cube.scale.y = 10.0; cube.scale.z = 10.0; //cube.castShadow = true; //dae.receiveShadow = true; // jsc shat about out of band code patching? cube.position.z = 600; cube.position.x = -900; //cube.position.y = -400; //cube.position.x = -100; //cube.position.y = -400; ////cube.position.y = (cube.scale.y * 50) / 2; //cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; // if i want to rotate, how do I do it? //cube.rotation.z = random() + Math.PI; //cube.rotation.x = random() + Math.PI; var sw2 = Stopwatch.StartNew(); scene.add(cube); //interactiveObjects.Add(cube); // offset is wrong //while (true) //{ // await Native.window.async.onframe; // cube.rotation.y = Math.PI * 0.0002 * sw2.ElapsedMilliseconds; //} } ); #endregion #region HZBunker new HeatZeekerRTSOrto.HZBunker().Source.Task.ContinueWithResult( cube => { // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); cube.castShadow = true; //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // //child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 10.0; cube.scale.y = 10.0; cube.scale.z = 10.0; //cube.castShadow = true; //dae.receiveShadow = true; cube.position.x = -1000; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = 0; scene.add(cube); } ); #endregion var lon0 = -45.0; var lon1 = 0.0; var lon = new sum( () => lon0, () => lon1 ); var lat0 = 0.0; var lat1 = 0.0; // or could we do it with byref or pointers? var lat = new sum( () => lat0, () => lat1 ); var phi = 0.0; var theta = 0.0; //var controls = new THREE.OrbitControls(camera); var camera_rotation_z = 0.0; Native.window.onframe += delegate { ////var delta = clock.getDelta(); //controls.update(); var scale = 1.0; var delta = clock.getDelta(); var stepSize = delta * scale; if (stepSize > 0) { //characterController.update(stepSize, scale); //gui.setSpeed(blendMesh.speed); THREE.AnimationHandler.update(stepSize); } //camera.position = controls.center.clone(); //if (Native.document.pointerLockElement == Native.document.body) // lon += 0.00; //else // lon += 0.01; //var lat2 = Math.Max(-85, Math.Min(85, lat)); //Native.document.title = new { lon, lat }.ToString(); //Native.document.title = new { lon0 }.ToString(); phi = THREE.Math.degToRad(90 - lat); theta = THREE.Math.degToRad(lon); target.x = camera.position.x + (500 * Math.Sin(phi) * Math.Cos(theta)); target.y = camera.position.y + (500 * Math.Cos(phi)); target.z = camera.position.z + (500 * Math.Sin(phi) * Math.Sin(theta)); //controls.update(); //camera.position = controls.center.clone(); // camera beta tilt? camera.lookAt(target); camera.rotation.z += camera_rotation_z; //composer.render(0.1); //renderer.render(scene, camera); effect.render(scene, camera); }; new { }.With( async delegate { retry: //var s = (double)Native.window.Width / 1920.0; //var s = (double)Native.window.Height / Native.screen.height; //var s = (double)Native.window.Height / 1440; var s = (double)Native.window.Height / 1080; Native.document.body.style.transform = "scale(" + s + ")"; Native.document.body.style.transformOrigin = "0% 0%"; await Native.window.async.onresize; goto retry; } ); // gamma -0 .. -90 var compassHeadingOffset = 0.0; var compassHeadingInitialized = 0; #region compassHeading // X:\jsc.svn\examples\javascript\android\Test\TestCompassHeading\TestCompassHeading\Application.cs Native.window.ondeviceorientation += dataValues => { // Convert degrees to radians var alphaRad = dataValues.alpha * (Math.PI / 180); var betaRad = dataValues.beta * (Math.PI / 180); var gammaRad = dataValues.gamma * (Math.PI / 180); // Calculate equation components var cA = Math.Cos(alphaRad); var sA = Math.Sin(alphaRad); var cB = Math.Cos(betaRad); var sB = Math.Sin(betaRad); var cG = Math.Cos(gammaRad); var sG = Math.Sin(gammaRad); // Calculate A, B, C rotation components var rA = -cA * sG - sA * sB * cG; var rB = -sA * sG + cA * sB * cG; var rC = -cB * cG; // Calculate compass heading var compassHeading = Math.Atan(rA / rB); // Convert from half unit circle to whole unit circle if (rB < 0) { compassHeading += Math.PI; } else if (rA < 0) { compassHeading += 2 * Math.PI; } /* Alternative calculation (replacing lines 99-107 above): var compassHeading = Math.atan2(rA, rB); if(rA < 0) { compassHeading += 2 * Math.PI; } */ // Convert radians to degrees compassHeading *= 180 / Math.PI; // Compass heading can only be derived if returned values are 'absolute' // X:\jsc.svn\examples\javascript\android\Test\TestCompassHeadingWithReset\TestCompassHeadingWithReset\Application.cs //Native.document.body.innerText = new { compassHeading }.ToString(); if (compassHeadingInitialized > 0) { lon1 = compassHeading - compassHeadingOffset; } else { compassHeadingOffset = compassHeading; compassHeadingInitialized++; } }; #endregion #region gamma Native.window.ondeviceorientation += //e => Native.body.innerText = new { e.alpha, e.beta, e.gamma }.ToString(); //e => lon = e.gamma; e => { lat1 = e.gamma; // after servicing a running instance would be nice // either by patching or just re running the whole iteration in the backgrou camera_rotation_z = e.beta * 0.02; }; #endregion #region camera rotation var old = new { clientX = 0, clientY = 0 }; Native.document.body.ontouchstart += e => { var n = new { e.touches[0].clientX, e.touches[0].clientY }; old = n; }; Native.document.body.ontouchmove += e => { var n = new { e.touches[0].clientX, e.touches[0].clientY }; e.preventDefault(); lon0 += (n.clientX - old.clientX) * 0.2; lat0 -= (n.clientY - old.clientY) * 0.2; old = n; }; Native.document.body.onmousemove += e => { e.preventDefault(); if (Native.document.pointerLockElement == Native.document.body) { lon0 += e.movementX * 0.1; lat0 -= e.movementY * 0.1; //Console.WriteLine(new { lon, lat, e.movementX, e.movementY }); } }; Native.document.body.onmouseup += e => { //drag = false; e.preventDefault(); }; Native.document.body.onmousedown += e => { //e.CaptureMouse(); //drag = true; e.preventDefault(); Native.document.body.requestPointerLock(); }; Native.document.body.ondblclick += e => { e.preventDefault(); Console.WriteLine("requestPointerLock"); }; #endregion Native.body.onmousewheel += e => { camera_rotation_z += 0.1 * e.WheelDirection; ; }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // http://threejs.org/examples/#webgl_postprocessing_godrays // view-source:file:///X:/opensource/github/three.js/examples/webgl_postprocessing_godrays.html Native.body.style.margin = "0px"; Native.body.style.overflow = IStyle.OverflowEnum.hidden; Native.body.Clear(); var sunPosition = new THREE.Vector3(0, 1000, -1000); var screenSpacePosition = new THREE.Vector3(); var mouseX = 0; var mouseY = 0; var windowHalfX = Native.window.Width / 2; var windowHalfY = Native.window.Height / 2; //var postprocessing = { enabled : true }; var orbitRadius = 200; var bgColor = 0x000511; var sunColor = 0xffee00; // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151112 var camera = new THREE.PerspectiveCamera(70, Native.window.aspect, 1, 3000); camera.position.z = 200; var scene = new THREE.Scene(); // var materialDepth = new THREE.MeshDepthMaterial(new { }); #region tree // X:\jsc.svn\examples\javascript\WebGL\WebGLGodRay\WebGLGodRay\Application.cs var materialScene = new THREE.MeshBasicMaterial(new { color = 0x000000, shading = THREE.FlatShading }); var loader = new THREE.JSONLoader(); // http://stackoverflow.com/questions/16539736/do-not-use-system-runtime-compilerservices-dynamicattribute-use-the-dynamic // https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.dynamicattribute%28v=vs.110%29.aspx //System.Runtime.CompilerServices.DynamicAttribute loader.load( new Models.tree().Content.src, new Action <THREE.Geometry>( xgeometry => { var treeMesh = new THREE.Mesh(xgeometry, materialScene); treeMesh.position.set(0, -150, -150); var tsc = 400; treeMesh.scale.set(tsc, tsc, tsc); treeMesh.matrixAutoUpdate = false; treeMesh.updateMatrix(); treeMesh.AttachTo(scene); } ) ); #endregion // sphere var geo = new THREE.SphereGeometry(1, 20, 10); var sphereMesh = new THREE.Mesh(geo, materialScene); var sc = 20; sphereMesh.scale.set(sc, sc, sc); scene.add(sphereMesh); var renderer = new THREE.WebGLRenderer(new { antialias = false }); renderer.setClearColor(bgColor); //renderer.setPixelRatio(window.devicePixelRatio); renderer.setSize(Native.window.Width, Native.window.Height); renderer.domElement.AttachToDocument(); renderer.autoClear = false; renderer.sortObjects = false; var postprocessing_scene = new THREE.Scene(); var postprocessing_camera = new THREE.OrthographicCamera(Native.window.Width / -2, Native.window.Width / 2, Native.window.Height / 2, Native.window.Height / -2, -10000, 10000); postprocessing_camera.position.z = 100; postprocessing_scene.add(postprocessing_camera); var pars = new { minFilter = THREE.LinearFilter, magFilter = THREE.LinearFilter, format = THREE.RGBFormat }; var postprocessing_rtTextureColors = new THREE.WebGLRenderTarget(Native.window.Width, Native.window.Height, pars); // Switching the depth formats to luminance from rgb doesn't seem to work. I didn't // investigate further for now. // pars.format = THREE.LuminanceFormat; // I would have this quarter size and use it as one of the ping-pong render // targets but the aliasing causes some temporal flickering var postprocessing_rtTextureDepth = new THREE.WebGLRenderTarget(Native.window.Width, Native.window.Height, pars); // Aggressive downsize god-ray ping-pong render targets to minimize cost var w = Native.window.Width / 4; var h = Native.window.Height / 4; var postprocessing_rtTextureGodRays1 = new THREE.WebGLRenderTarget(w, h, pars); var postprocessing_rtTextureGodRays2 = new THREE.WebGLRenderTarget(w, h, pars); // god-ray shaders // X:\jsc.svn\market\synergy\THREE\THREE\opensource\gihtub\three.js\build\THREE.ShaderGodRays.idl // these are special <script src="js/ShaderGodRays.js"></script> var godraysGenShader = THREE.ShaderGodRays["godrays_generate"] as dynamic; var postprocessing_godrayGenUniforms = THREE.UniformsUtils.clone(godraysGenShader.uniforms); var postprocessing_materialGodraysGenerate = new THREE.ShaderMaterial(new { uniforms = postprocessing_godrayGenUniforms, vertexShader = godraysGenShader.vertexShader, fragmentShader = godraysGenShader.fragmentShader }); var godraysCombineShader = THREE.ShaderGodRays["godrays_combine"] as dynamic; var postprocessing_godrayCombineUniforms = THREE.UniformsUtils.clone(godraysCombineShader.uniforms); var postprocessing_materialGodraysCombine = new THREE.ShaderMaterial(new { uniforms = postprocessing_godrayCombineUniforms, vertexShader = godraysCombineShader.vertexShader, fragmentShader = godraysCombineShader.fragmentShader }); var godraysFakeSunShader = THREE.ShaderGodRays["godrays_fake_sun"] as dynamic; var postprocessing_godraysFakeSunUniforms = THREE.UniformsUtils.clone(godraysFakeSunShader.uniforms); var postprocessing_materialGodraysFakeSun = new THREE.ShaderMaterial(new { uniforms = postprocessing_godraysFakeSunUniforms, vertexShader = godraysFakeSunShader.vertexShader, fragmentShader = godraysFakeSunShader.fragmentShader }); postprocessing_godraysFakeSunUniforms.bgColor.value.setHex(bgColor); postprocessing_godraysFakeSunUniforms.sunColor.value.setHex(sunColor); postprocessing_godrayCombineUniforms.fGodRayIntensity.value = 0.75; var postprocessing_quad = new THREE.Mesh( new THREE.PlaneBufferGeometry(Native.window.Width, Native.window.Height), postprocessing_materialGodraysGenerate ); postprocessing_quad.position.z = -9900; postprocessing_scene.add(postprocessing_quad); #region create field // THREE.PlaneGeometry: Consider using THREE.PlaneBufferGeometry for lower memory footprint. var planeGeometry = new THREE.PlaneGeometry(1000, 1000); //var planeMaterial = new THREE.MeshLambertMaterial( // new // { // //map = THREE.ImageUtils.loadTexture(new HTML.Images.FromAssets.dirt_tx().src), // color = 0xA26D41 // //color = 0xff0000 // } //); //planeMaterial.map.repeat.x = 300; //planeMaterial.map.repeat.y = 300; //planeMaterial.map.wrapS = THREE.RepeatWrapping; //planeMaterial.map.wrapT = THREE.RepeatWrapping; var plane = new THREE.Mesh(planeGeometry, new THREE.MeshPhongMaterial(new { ambient = 0x101010, color = 0xA26D41, specular = 0xA26D41, shininess = 1 }) ); plane.castShadow = false; plane.receiveShadow = true; { var parent = new THREE.Object3D(); parent.add(plane); parent.position.y = -.5f * 100; parent.rotation.x = -Math.PI / 2; parent.scale.set(100, 100, 100); //scene.add(parent); } var random = new Random(); var meshArray = new List <THREE.Mesh>(); var geometry = new THREE.CubeGeometry(1, 1, 1); for (var i = 1; i < 100; i++) { //THREE.MeshPhongMaterial var ii = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial(new { ambient = 0x000000, color = 0xA06040, specular = 0xA26D41, shininess = 1 }) //new THREE.MeshLambertMaterial( //new //{ // color = (Convert.ToInt32(0xffffff * random.NextDouble())), // specular = 0xffaaaa, // ambient= 0x050505, //}) ); ii.position.x = i % 2 * 500 - 2.5f; // raise it up ii.position.y = .5f * 100; ii.position.z = -1 * i * 400; ii.castShadow = true; ii.receiveShadow = true; //ii.scale.set(100, 100, 100 * i); ii.scale.set(100, 100 * i, 100); meshArray.Add(ii); scene.add(ii); } #endregion #region Comanche new Comanche().Source.Task.ContinueWithResult( Comanche => { Comanche.position.y = 200; //dae.position.z = 280; Comanche.AttachTo(scene); //scene.add(dae); //oo.Add(Comanche); // wont do it //dae.castShadow = true; // http://stackoverflow.com/questions/15492857/any-way-to-get-a-bounding-box-from-a-three-js-object3d //var helper = new THREE.BoundingBoxHelper(dae, 0xff0000); //helper.update(); //// If you want a visible bounding box //scene.add(helper); Comanche.children[0].children[0].children.WithEach(x => x.castShadow = true); // the rotors? Comanche.children[0].children[0].children.Last().children.WithEach(x => x.castShadow = true); Comanche.scale.set(0.5, 0.5, 0.5); //helper.scale.set(0.5, 0.5, 0.5); var s2w = Stopwatch.StartNew(); Native.window.onframe += delegate { //dae.children[0].children[0].children.Last().al //dae.children[0].children[0].children.Last().rotation.z = sw.ElapsedMilliseconds * 0.01; //dae.children[0].children[0].children.Last().rotation.x = sw.ElapsedMilliseconds * 0.01; //rotation.y = sw.ElapsedMilliseconds * 0.01; Comanche.children[0].children[0].children.Last().rotation.y = s2w.ElapsedMilliseconds * 0.001; //dae.children[0].children[0].children.Last().app }; } ); #endregion var sw = Stopwatch.StartNew(); var controls = new THREE.OrbitControls(camera, renderer.domElement); // Show Details Severity Code Description Project File Line //Error CS0229 Ambiguity between 'THREE.Math' and 'Math' WebGLGodRay Application.cs 238 Native.window.onframe += delegate { //var time = IDate.now() / 4000; var time = sw.ElapsedMilliseconds / 4000.0; sphereMesh.position.x = orbitRadius * Math.Cos(time); sphereMesh.position.z = orbitRadius * Math.Sin(time) - 100; //controls.center.copy(blendMesh.position); //controls.center.y += radius * 2.0; controls.update(); //var camOffset = camera.position.clone().sub(controls.center); //camOffset.normalize().multiplyScalar(750); camera.position = controls.center.clone(); //camera.position.x += (mouseX - camera.position.x) * 0.036; //camera.position.y += (-(mouseY) - camera.position.y) * 0.036; //camera.lookAt(scene.position); // Find the screenspace position of the sun screenSpacePosition.copy(sunPosition).project(camera); screenSpacePosition.x = (screenSpacePosition.x + 1) / 2; screenSpacePosition.y = (screenSpacePosition.y + 1) / 2; // Give it to the god-ray and sun shaders postprocessing_godrayGenUniforms["vSunPositionScreenSpace"].value.x = screenSpacePosition.x; postprocessing_godrayGenUniforms["vSunPositionScreenSpace"].value.y = screenSpacePosition.y; postprocessing_godraysFakeSunUniforms["vSunPositionScreenSpace"].value.x = screenSpacePosition.x; postprocessing_godraysFakeSunUniforms["vSunPositionScreenSpace"].value.y = screenSpacePosition.y; // -- Draw sky and sun -- // Clear colors and depths, will clear to sky color renderer.clearTarget(postprocessing_rtTextureColors, true, true, false); // Sun render. Runs a shader that gives a brightness based on the screen // space distance to the sun. Not very efficient, so i make a scissor // rectangle around the suns position to avoid rendering surrounding pixels. var sunsqH = 0.74 * Native.window.Height; // 0.74 depends on extent of sun from shader var sunsqW = 0.74 * Native.window.Height; // both depend on height because sun is aspect-corrected screenSpacePosition.x *= Native.window.Width; screenSpacePosition.y *= Native.window.Height; renderer.setScissor(screenSpacePosition.x - sunsqW / 2, screenSpacePosition.y - sunsqH / 2, sunsqW, sunsqH); renderer.enableScissorTest(true); postprocessing_godraysFakeSunUniforms["fAspect"].value = Native.window.aspect; postprocessing_scene.overrideMaterial = postprocessing_materialGodraysFakeSun; renderer.render(postprocessing_scene, postprocessing_camera, postprocessing_rtTextureColors); renderer.enableScissorTest(false); // -- Draw scene objects -- // Colors scene.overrideMaterial = null; renderer.render(scene, camera, postprocessing_rtTextureColors); // Depth scene.overrideMaterial = materialDepth; renderer.render(scene, camera, postprocessing_rtTextureDepth, true); // -- Render god-rays -- // Maximum length of god-rays (in texture space [0,1]X[0,1]) var filterLen = 1.0; // Samples taken by filter var TAPS_PER_PASS = 6.0; // Pass order could equivalently be 3,2,1 (instead of 1,2,3), which // would start with a small filter support and grow to large. however // the large-to-small order produces less objectionable aliasing artifacts that // appear as a glimmer along the length of the beams // pass 1 - render into first ping-pong target var pass = 1.0; var stepLen = filterLen * Math.Pow(TAPS_PER_PASS, -pass); postprocessing_godrayGenUniforms["fStepSize"].value = stepLen; postprocessing_godrayGenUniforms["tInput"].value = postprocessing_rtTextureDepth; postprocessing_scene.overrideMaterial = postprocessing_materialGodraysGenerate; renderer.render(postprocessing_scene, postprocessing_camera, postprocessing_rtTextureGodRays2); // pass 2 - render into second ping-pong target pass = 2.0; stepLen = filterLen * Math.Pow(TAPS_PER_PASS, -pass); postprocessing_godrayGenUniforms["fStepSize"].value = stepLen; postprocessing_godrayGenUniforms["tInput"].value = postprocessing_rtTextureGodRays2; renderer.render(postprocessing_scene, postprocessing_camera, postprocessing_rtTextureGodRays1); // pass 3 - 1st RT pass = 3.0; stepLen = filterLen * Math.Pow(TAPS_PER_PASS, -pass); postprocessing_godrayGenUniforms["fStepSize"].value = stepLen; postprocessing_godrayGenUniforms["tInput"].value = postprocessing_rtTextureGodRays1; renderer.render(postprocessing_scene, postprocessing_camera, postprocessing_rtTextureGodRays2); // final pass - composite god-rays onto colors postprocessing_godrayCombineUniforms["tColors"].value = postprocessing_rtTextureColors; postprocessing_godrayCombineUniforms["tGodRays"].value = postprocessing_rtTextureGodRays2; postprocessing_scene.overrideMaterial = postprocessing_materialGodraysCombine; renderer.render(postprocessing_scene, postprocessing_camera); postprocessing_scene.overrideMaterial = null; }; new { }.With( async delegate { //while (true) do { camera.aspect = Native.window.aspect; camera.updateProjectionMatrix(); renderer.setSize(Native.window.Width, Native.window.Height); // convert to bool? } while (await Native.window.async.onresize); //} while (await Native.window.async.onresize != null); } ); //var ze = new ZeProperties(); //ze.Show(); //ze.treeView1.Nodes.Clear(); //ze.Add(() => renderer); //ze.Add(() => controls); //ze.Add(() => scene); //ze.Left = 0; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // "X:\opensource\github\three.js\examples\canvas_camera_orthographic.html" // if i type THREE, would jsc be able to add THREE package on rebuild? // Error 136 The type or namespace name 'THREE' could not be found (are you missing a using directive or an assembly reference?) X:\jsc.svn\examples\javascript\WebGL\WebGLOrthographicCamera\WebGLOrthographicCamera\Application.cs 35 26 WebGLOrthographicCamera // X:\jsc.svn\examples\javascript\WebGL\WebGLOrthographicCamera\WebGLOrthographicCamera\Application.cs var camera = new THREE.OrthographicCamera(Native.window.Width / -2, Native.window.Width / 2, Native.window.Height / 2, Native.window.Height / -2, -500, 1000); camera.position.x = 200; camera.position.y = 100; camera.position.z = 200; var scene = new THREE.Scene(); // Grid var size = 500; var step = 50; Func<double> random = new Random().NextDouble; { var geometry = new THREE.Geometry(); for (var i = -size; i <= size; i += step) { ((IArray<THREE.Vector3>)(object)geometry.vertices).push(new THREE.Vector3(-size, 0, i)); ((IArray<THREE.Vector3>)(object)geometry.vertices).push(new THREE.Vector3(size, 0, i)); ((IArray<THREE.Vector3>)(object)geometry.vertices).push(new THREE.Vector3(i, 0, -size)); ((IArray<THREE.Vector3>)(object)geometry.vertices).push(new THREE.Vector3(i, 0, size)); } var material = new THREE.LineBasicMaterial(new { color = 0x000000, opacity = 0.2 }); var line = new THREE.Line(geometry, material); line.type = THREE.LinePieces; scene.add(line); } #region Cubes { var geometry = new THREE.BoxGeometry(50, 50, 50); var material = new THREE.MeshLambertMaterial(new { color = 0xffffff, shading = THREE.FlatShading, overdraw = 0.5 }); for (var i = 0; i < 100; i++) { var cube = new THREE.Mesh(geometry, material); cube.scale.y = Math.Floor(random() * 2 + 1); cube.position.x = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; scene.add(cube); } } #endregion #region Lights var ambientLight = new THREE.AmbientLight((int)(random() * 0x10)); scene.add(ambientLight); { var directionalLight = new THREE.DirectionalLight((int)(random() * 0xffffff)); directionalLight.position.x = random() - 0.5; directionalLight.position.y = random() - 0.5; directionalLight.position.z = random() - 0.5; directionalLight.position.normalize(); scene.add(directionalLight); } { var directionalLight = new THREE.DirectionalLight((int)(random() * 0xffffff)); directionalLight.position.x = random() - 0.5; directionalLight.position.y = random() - 0.5; directionalLight.position.z = random() - 0.5; directionalLight.position.normalize(); scene.add(directionalLight); } #endregion //var renderer = new THREE.CanvasRenderer(); var renderer = new THREE.WebGLRenderer(); renderer.setClearColor(0xf0f0f0); //renderer.setSize(Native.window.Width, Native.window.Height); renderer.setSize(); renderer.domElement.AttachToDocument(); //window.addEventListener( 'resize', onWindowResize, false ); var s = Stopwatch.StartNew(); Native.window.onframe += e => { // jsc, when can we have the edit and continue already? //var timer = s.ElapsedMilliseconds * 0.1; var timer = s.ElapsedMilliseconds * 0.0001; camera.position.x = Math.Cos(timer) * 200; camera.position.z = Math.Sin(timer) * 200; camera.lookAt(scene.position); renderer.render(scene, camera); }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // "X:\opensource\github\three.js\examples\canvas_camera_orthographic.html" // if i type THREE, would jsc be able to add THREE package on rebuild? // Error 136 The type or namespace name 'THREE' could not be found (are you missing a using directive or an assembly reference?) X:\jsc.svn\examples\javascript\WebGL\WebGLOrthographicCamera\WebGLOrthographicCamera\Application.cs 35 26 WebGLOrthographicCamera // X:\jsc.svn\examples\javascript\WebGL\WebGLOrthographicCamera\WebGLOrthographicCamera\Application.cs var camera = new THREE.OrthographicCamera(Native.window.Width / -2, Native.window.Width / 2, Native.window.Height / 2, Native.window.Height / -2, -500, 1000); camera.position.x = 200; camera.position.y = 100; camera.position.z = 200; var scene = new THREE.Scene(); // Grid var size = 500; var step = 50; Func <double> random = new Random().NextDouble; { var geometry = new THREE.Geometry(); for (var i = -size; i <= size; i += step) { ((IArray <THREE.Vector3>)(object) geometry.vertices).push(new THREE.Vector3(-size, 0, i)); ((IArray <THREE.Vector3>)(object) geometry.vertices).push(new THREE.Vector3(size, 0, i)); ((IArray <THREE.Vector3>)(object) geometry.vertices).push(new THREE.Vector3(i, 0, -size)); ((IArray <THREE.Vector3>)(object) geometry.vertices).push(new THREE.Vector3(i, 0, size)); } var material = new THREE.LineBasicMaterial(new { color = 0x000000, opacity = 0.2 }); var line = new THREE.Line(geometry, material); line.type = THREE.LinePieces; scene.add(line); } #region Cubes { var geometry = new THREE.BoxGeometry(50, 50, 50); var material = new THREE.MeshLambertMaterial(new { color = 0xffffff, shading = THREE.FlatShading, overdraw = 0.5 }); for (var i = 0; i < 100; i++) { var cube = new THREE.Mesh(geometry, material); cube.scale.y = Math.Floor(random() * 2 + 1); cube.position.x = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; scene.add(cube); } } #endregion #region Lights var ambientLight = new THREE.AmbientLight((int)(random() * 0x10)); scene.add(ambientLight); { var directionalLight = new THREE.DirectionalLight((int)(random() * 0xffffff)); directionalLight.position.x = random() - 0.5; directionalLight.position.y = random() - 0.5; directionalLight.position.z = random() - 0.5; directionalLight.position.normalize(); scene.add(directionalLight); } { var directionalLight = new THREE.DirectionalLight((int)(random() * 0xffffff)); directionalLight.position.x = random() - 0.5; directionalLight.position.y = random() - 0.5; directionalLight.position.z = random() - 0.5; directionalLight.position.normalize(); scene.add(directionalLight); } #endregion //var renderer = new THREE.CanvasRenderer(); var renderer = new THREE.WebGLRenderer(); renderer.setClearColor(0xf0f0f0); //renderer.setSize(Native.window.Width, Native.window.Height); renderer.setSize(); renderer.domElement.AttachToDocument(); //window.addEventListener( 'resize', onWindowResize, false ); var s = Stopwatch.StartNew(); Native.window.onframe += e => { // jsc, when can we have the edit and continue already? //var timer = s.ElapsedMilliseconds * 0.1; var timer = s.ElapsedMilliseconds * 0.0001; camera.position.x = Math.Cos(timer) * 200; camera.position.z = Math.Sin(timer) * 200; camera.lookAt(scene.position); renderer.render(scene, camera); }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // http://threejs.org/examples/#webgl_postprocessing_godrays // view-source:file:///X:/opensource/github/three.js/examples/webgl_postprocessing_godrays.html Native.body.style.margin = "0px"; Native.body.style.overflow = IStyle.OverflowEnum.hidden; Native.body.Clear(); var sunPosition = new THREE.Vector3(0, 1000, -1000); var screenSpacePosition = new THREE.Vector3(); var mouseX = 0; var mouseY = 0; var windowHalfX = Native.window.Width / 2; var windowHalfY = Native.window.Height / 2; //var postprocessing = { enabled : true }; var orbitRadius = 200; var bgColor = 0x000511; var sunColor = 0xffee00; // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151112 var camera = new THREE.PerspectiveCamera(70, Native.window.aspect, 1, 3000); camera.position.z = 200; var scene = new THREE.Scene(); // var materialDepth = new THREE.MeshDepthMaterial(new { }); #region tree // X:\jsc.svn\examples\javascript\WebGL\WebGLGodRay\WebGLGodRay\Application.cs var materialScene = new THREE.MeshBasicMaterial(new { color = 0x000000, shading = THREE.FlatShading }); var loader = new THREE.JSONLoader(); // http://stackoverflow.com/questions/16539736/do-not-use-system-runtime-compilerservices-dynamicattribute-use-the-dynamic // https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.dynamicattribute%28v=vs.110%29.aspx //System.Runtime.CompilerServices.DynamicAttribute loader.load( new Models.tree().Content.src, new Action<THREE.Geometry>( xgeometry => { var treeMesh = new THREE.Mesh(xgeometry, materialScene); treeMesh.position.set(0, -150, -150); var tsc = 400; treeMesh.scale.set(tsc, tsc, tsc); treeMesh.matrixAutoUpdate = false; treeMesh.updateMatrix(); treeMesh.AttachTo(scene); } ) ); #endregion // sphere var geo = new THREE.SphereGeometry(1, 20, 10); var sphereMesh = new THREE.Mesh(geo, materialScene); var sc = 20; sphereMesh.scale.set(sc, sc, sc); scene.add(sphereMesh); var renderer = new THREE.WebGLRenderer(new { antialias = false }); renderer.setClearColor(bgColor); //renderer.setPixelRatio(window.devicePixelRatio); renderer.setSize(Native.window.Width, Native.window.Height); renderer.domElement.AttachToDocument(); renderer.autoClear = false; renderer.sortObjects = false; var postprocessing_scene = new THREE.Scene(); var postprocessing_camera = new THREE.OrthographicCamera(Native.window.Width / -2, Native.window.Width / 2, Native.window.Height / 2, Native.window.Height / -2, -10000, 10000); postprocessing_camera.position.z = 100; postprocessing_scene.add(postprocessing_camera); var pars = new { minFilter = THREE.LinearFilter, magFilter = THREE.LinearFilter, format = THREE.RGBFormat }; var postprocessing_rtTextureColors = new THREE.WebGLRenderTarget(Native.window.Width, Native.window.Height, pars); // Switching the depth formats to luminance from rgb doesn't seem to work. I didn't // investigate further for now. // pars.format = THREE.LuminanceFormat; // I would have this quarter size and use it as one of the ping-pong render // targets but the aliasing causes some temporal flickering var postprocessing_rtTextureDepth = new THREE.WebGLRenderTarget(Native.window.Width, Native.window.Height, pars); // Aggressive downsize god-ray ping-pong render targets to minimize cost var w = Native.window.Width / 4; var h = Native.window.Height / 4; var postprocessing_rtTextureGodRays1 = new THREE.WebGLRenderTarget(w, h, pars); var postprocessing_rtTextureGodRays2 = new THREE.WebGLRenderTarget(w, h, pars); // god-ray shaders // X:\jsc.svn\market\synergy\THREE\THREE\opensource\gihtub\three.js\build\THREE.ShaderGodRays.idl // these are special <script src="js/ShaderGodRays.js"></script> var godraysGenShader = THREE.ShaderGodRays["godrays_generate"] as dynamic; var postprocessing_godrayGenUniforms = THREE.UniformsUtils.clone(godraysGenShader.uniforms); var postprocessing_materialGodraysGenerate = new THREE.ShaderMaterial(new { uniforms = postprocessing_godrayGenUniforms, vertexShader = godraysGenShader.vertexShader, fragmentShader = godraysGenShader.fragmentShader }); var godraysCombineShader = THREE.ShaderGodRays["godrays_combine"] as dynamic; var postprocessing_godrayCombineUniforms = THREE.UniformsUtils.clone(godraysCombineShader.uniforms); var postprocessing_materialGodraysCombine = new THREE.ShaderMaterial(new { uniforms = postprocessing_godrayCombineUniforms, vertexShader = godraysCombineShader.vertexShader, fragmentShader = godraysCombineShader.fragmentShader }); var godraysFakeSunShader = THREE.ShaderGodRays["godrays_fake_sun"] as dynamic; var postprocessing_godraysFakeSunUniforms = THREE.UniformsUtils.clone(godraysFakeSunShader.uniforms); var postprocessing_materialGodraysFakeSun = new THREE.ShaderMaterial(new { uniforms = postprocessing_godraysFakeSunUniforms, vertexShader = godraysFakeSunShader.vertexShader, fragmentShader = godraysFakeSunShader.fragmentShader }); postprocessing_godraysFakeSunUniforms.bgColor.value.setHex(bgColor); postprocessing_godraysFakeSunUniforms.sunColor.value.setHex(sunColor); postprocessing_godrayCombineUniforms.fGodRayIntensity.value = 0.75; var postprocessing_quad = new THREE.Mesh( new THREE.PlaneBufferGeometry(Native.window.Width, Native.window.Height), postprocessing_materialGodraysGenerate ); postprocessing_quad.position.z = -9900; postprocessing_scene.add(postprocessing_quad); #region create field // THREE.PlaneGeometry: Consider using THREE.PlaneBufferGeometry for lower memory footprint. var planeGeometry = new THREE.PlaneGeometry(1000, 1000); //var planeMaterial = new THREE.MeshLambertMaterial( // new // { // //map = THREE.ImageUtils.loadTexture(new HTML.Images.FromAssets.dirt_tx().src), // color = 0xA26D41 // //color = 0xff0000 // } //); //planeMaterial.map.repeat.x = 300; //planeMaterial.map.repeat.y = 300; //planeMaterial.map.wrapS = THREE.RepeatWrapping; //planeMaterial.map.wrapT = THREE.RepeatWrapping; var plane = new THREE.Mesh(planeGeometry, new THREE.MeshPhongMaterial(new { ambient = 0x101010, color = 0xA26D41, specular = 0xA26D41, shininess = 1 }) ); plane.castShadow = false; plane.receiveShadow = true; { var parent = new THREE.Object3D(); parent.add(plane); parent.position.y = -.5f * 100; parent.rotation.x = -Math.PI / 2; parent.scale.set(100, 100, 100); //scene.add(parent); } var random = new Random(); var meshArray = new List<THREE.Mesh>(); var geometry = new THREE.CubeGeometry(1, 1, 1); for (var i = 1; i < 100; i++) { //THREE.MeshPhongMaterial var ii = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial(new { ambient = 0x000000, color = 0xA06040, specular = 0xA26D41, shininess = 1 }) //new THREE.MeshLambertMaterial( //new //{ // color = (Convert.ToInt32(0xffffff * random.NextDouble())), // specular = 0xffaaaa, // ambient= 0x050505, //}) ); ii.position.x = i % 2 * 500 - 2.5f; // raise it up ii.position.y = .5f * 100; ii.position.z = -1 * i * 400; ii.castShadow = true; ii.receiveShadow = true; //ii.scale.set(100, 100, 100 * i); ii.scale.set(100, 100 * i, 100); meshArray.Add(ii); scene.add(ii); } #endregion #region Comanche new Comanche().Source.Task.ContinueWithResult( Comanche => { Comanche.position.y = 200; //dae.position.z = 280; Comanche.AttachTo(scene); //scene.add(dae); //oo.Add(Comanche); // wont do it //dae.castShadow = true; // http://stackoverflow.com/questions/15492857/any-way-to-get-a-bounding-box-from-a-three-js-object3d //var helper = new THREE.BoundingBoxHelper(dae, 0xff0000); //helper.update(); //// If you want a visible bounding box //scene.add(helper); Comanche.children[0].children[0].children.WithEach(x => x.castShadow = true); // the rotors? Comanche.children[0].children[0].children.Last().children.WithEach(x => x.castShadow = true); Comanche.scale.set(0.5, 0.5, 0.5); //helper.scale.set(0.5, 0.5, 0.5); var s2w = Stopwatch.StartNew(); Native.window.onframe += delegate { //dae.children[0].children[0].children.Last().al //dae.children[0].children[0].children.Last().rotation.z = sw.ElapsedMilliseconds * 0.01; //dae.children[0].children[0].children.Last().rotation.x = sw.ElapsedMilliseconds * 0.01; //rotation.y = sw.ElapsedMilliseconds * 0.01; Comanche.children[0].children[0].children.Last().rotation.y = s2w.ElapsedMilliseconds * 0.001; //dae.children[0].children[0].children.Last().app }; } ); #endregion var sw = Stopwatch.StartNew(); var controls = new THREE.OrbitControls(camera, renderer.domElement); // Show Details Severity Code Description Project File Line //Error CS0229 Ambiguity between 'THREE.Math' and 'Math' WebGLGodRay Application.cs 238 Native.window.onframe += delegate { //var time = IDate.now() / 4000; var time = sw.ElapsedMilliseconds / 4000.0; sphereMesh.position.x = orbitRadius * Math.Cos(time); sphereMesh.position.z = orbitRadius * Math.Sin(time) - 100; //controls.center.copy(blendMesh.position); //controls.center.y += radius * 2.0; controls.update(); //var camOffset = camera.position.clone().sub(controls.center); //camOffset.normalize().multiplyScalar(750); camera.position = controls.center.clone(); //camera.position.x += (mouseX - camera.position.x) * 0.036; //camera.position.y += (-(mouseY) - camera.position.y) * 0.036; //camera.lookAt(scene.position); // Find the screenspace position of the sun screenSpacePosition.copy(sunPosition).project(camera); screenSpacePosition.x = (screenSpacePosition.x + 1) / 2; screenSpacePosition.y = (screenSpacePosition.y + 1) / 2; // Give it to the god-ray and sun shaders postprocessing_godrayGenUniforms["vSunPositionScreenSpace"].value.x = screenSpacePosition.x; postprocessing_godrayGenUniforms["vSunPositionScreenSpace"].value.y = screenSpacePosition.y; postprocessing_godraysFakeSunUniforms["vSunPositionScreenSpace"].value.x = screenSpacePosition.x; postprocessing_godraysFakeSunUniforms["vSunPositionScreenSpace"].value.y = screenSpacePosition.y; // -- Draw sky and sun -- // Clear colors and depths, will clear to sky color renderer.clearTarget(postprocessing_rtTextureColors, true, true, false); // Sun render. Runs a shader that gives a brightness based on the screen // space distance to the sun. Not very efficient, so i make a scissor // rectangle around the suns position to avoid rendering surrounding pixels. var sunsqH = 0.74 * Native.window.Height; // 0.74 depends on extent of sun from shader var sunsqW = 0.74 * Native.window.Height; // both depend on height because sun is aspect-corrected screenSpacePosition.x *= Native.window.Width; screenSpacePosition.y *= Native.window.Height; renderer.setScissor(screenSpacePosition.x - sunsqW / 2, screenSpacePosition.y - sunsqH / 2, sunsqW, sunsqH); renderer.enableScissorTest(true); postprocessing_godraysFakeSunUniforms["fAspect"].value = Native.window.aspect; postprocessing_scene.overrideMaterial = postprocessing_materialGodraysFakeSun; renderer.render(postprocessing_scene, postprocessing_camera, postprocessing_rtTextureColors); renderer.enableScissorTest(false); // -- Draw scene objects -- // Colors scene.overrideMaterial = null; renderer.render(scene, camera, postprocessing_rtTextureColors); // Depth scene.overrideMaterial = materialDepth; renderer.render(scene, camera, postprocessing_rtTextureDepth, true); // -- Render god-rays -- // Maximum length of god-rays (in texture space [0,1]X[0,1]) var filterLen = 1.0; // Samples taken by filter var TAPS_PER_PASS = 6.0; // Pass order could equivalently be 3,2,1 (instead of 1,2,3), which // would start with a small filter support and grow to large. however // the large-to-small order produces less objectionable aliasing artifacts that // appear as a glimmer along the length of the beams // pass 1 - render into first ping-pong target var pass = 1.0; var stepLen = filterLen * Math.Pow(TAPS_PER_PASS, -pass); postprocessing_godrayGenUniforms["fStepSize"].value = stepLen; postprocessing_godrayGenUniforms["tInput"].value = postprocessing_rtTextureDepth; postprocessing_scene.overrideMaterial = postprocessing_materialGodraysGenerate; renderer.render(postprocessing_scene, postprocessing_camera, postprocessing_rtTextureGodRays2); // pass 2 - render into second ping-pong target pass = 2.0; stepLen = filterLen * Math.Pow(TAPS_PER_PASS, -pass); postprocessing_godrayGenUniforms["fStepSize"].value = stepLen; postprocessing_godrayGenUniforms["tInput"].value = postprocessing_rtTextureGodRays2; renderer.render(postprocessing_scene, postprocessing_camera, postprocessing_rtTextureGodRays1); // pass 3 - 1st RT pass = 3.0; stepLen = filterLen * Math.Pow(TAPS_PER_PASS, -pass); postprocessing_godrayGenUniforms["fStepSize"].value = stepLen; postprocessing_godrayGenUniforms["tInput"].value = postprocessing_rtTextureGodRays1; renderer.render(postprocessing_scene, postprocessing_camera, postprocessing_rtTextureGodRays2); // final pass - composite god-rays onto colors postprocessing_godrayCombineUniforms["tColors"].value = postprocessing_rtTextureColors; postprocessing_godrayCombineUniforms["tGodRays"].value = postprocessing_rtTextureGodRays2; postprocessing_scene.overrideMaterial = postprocessing_materialGodraysCombine; renderer.render(postprocessing_scene, postprocessing_camera); postprocessing_scene.overrideMaterial = null; }; new { }.With( async delegate { //while (true) do { camera.aspect = Native.window.aspect; camera.updateProjectionMatrix(); renderer.setSize(Native.window.Width, Native.window.Height); // convert to bool? } while (await Native.window.async.onresize); //} while (await Native.window.async.onresize != null); } ); //var ze = new ZeProperties(); //ze.Show(); //ze.treeView1.Nodes.Clear(); //ze.Add(() => renderer); //ze.Add(() => controls); //ze.Add(() => scene); //ze.Left = 0; }
// new three broke it? // http://www.clicktorelease.com/code/perlin/explosion.html // http://www.webgl.com/2013/01/webgl-tutorial-vertex-displacement-with-a-noise-function-aka-fiery-explosion/ /// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IDefault page = null) { // http://inear.se/fireshader/ // http://stackoverflow.com/questions/16765120/ashima-perlin-noise-shader-not-working-with-recent-versions-of-three-js //var container, renderer, camera, mesh; var start = IDate.Now; var fov = 30; #region container Native.document.body.style.overflow = IStyle.OverflowEnum.hidden; var container = new IHTMLDiv(); container.AttachToDocument(); container.style.backgroundColor = "#000000"; container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height); #endregion var scene = new THREE.Scene(); var bkgScene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(fov, Native.window.aspect, 1, 10000); camera.position.z = 100; //camera.target = new THREE.Vector3(0, 0, 0); scene.add(camera); var bkgCamera = new THREE.OrthographicCamera( Native.window.Width / -2, Native.window.Width / 2, Native.window.Height / 2, Native.window.Height / -2, -10000, 10000 ); bkgScene.add(bkgCamera); var bkgShader = new THREE.ShaderMaterial( new { uniforms = new { tDiffuse = new { type = "t", value = THREE.ImageUtils.loadTexture( new HTML.Images.FromAssets.bkg().src ) }, resolution = new { type = "v2", value = new THREE.Vector2(Native.window.Width, Native.window.Height) } }, vertexShader = new Shaders.ExplosionVertexShader().ToString(), // fragmentShader: document.getElementById( 'fs_Gradient' ).textContent, //fragmentShader = new Shaders.GradientFragmentShader().ToString(), fragmentShader = new Shaders.ExplosionFragmentShader().ToString(), depthWrite = false, depthTest = false, transparent = true } ); var quad = new THREE.Mesh(new THREE.PlaneGeometry(Native.window.Width, Native.window.Height), bkgShader); quad.position.z = -100; quad.rotation.x = (float)Math.PI / 2; bkgScene.add(quad); var material = new THREE.ShaderMaterial( new { uniforms = new // material_uniforms { tExplosion = new //uniforms_item { type = "t", value = THREE.ImageUtils.loadTexture( new HTML.Images.FromAssets.explosion().src ) }, time = new { type = "f", value = 0.0 }, weight = new { type = "f", value = 8.0 }, }, vertexShader = new Shaders.ExplosionVertexShader().ToString(), fragmentShader = new Shaders.ExplosionFragmentShader().ToString(), depthWrite = false, depthTest = false, transparent = true } ); var mesh = new THREE.Mesh(new THREE.SphereGeometry(20, 200, 200), material); scene.add(mesh); var renderer = new THREE.WebGLRenderer(); renderer.setSize(Native.window.Width, Native.window.Height); renderer.autoClear = false; container.appendChild(renderer.domElement); var lon = 0.0; var phi = 0.0; var theta = 0.0; var lat = 15.0; var isUserInteracting = false; var scale = 0.0; #region render Native.window.onframe += delegate { ((material_uniforms)material.uniforms).time.value = .00025 * (IDate.Now - start); scale += .005; scale %= 2; lat = Math.Max(-85, Math.Min(85, lat)); phi = (90 - lat) * Math.PI / 180; theta = lon * Math.PI / 180; camera.position.x = (float)(100 * Math.Sin(phi) * Math.Cos(theta)); camera.position.y = (float)(100 * Math.Cos(phi)); camera.position.z = (float)(100 * Math.Sin(phi) * Math.Sin(theta)); //mesh.rotation.x += .012; //mesh.rotation.y += .01; camera.lookAt(scene.position); // //renderer.render( bkgScene, bkgCamera ); renderer.render(scene, camera); // stats.update(); }; #endregion #region IsDisposed Dispose = delegate { if (IsDisposed) { return; } IsDisposed = true; container.Orphanize(); }; #endregion #region AtResize Action AtResize = delegate { container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height); renderer.setSize(Native.window.Width, Native.window.Height); camera.projectionMatrix.makePerspective(fov, Native.window.aspect, 1, 1100); //camera.aspect = Native.Window.Width / Native.Window.Height; //camera.updateProjectionMatrix(); }; Native.window.onresize += delegate { AtResize(); }; AtResize(); #endregion var ze = new ZeProperties(); ze.Show(); ze.treeView1.Nodes.Clear(); ze.Add(() => renderer); //ze.Add(() => controls); ze.Add(() => scene); ze.Left = 0; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // https://chrome.google.com/webstore/detail/dglmddjmdpdbijfkoaiadbpmjampfdjh/publish-delayed #region ChromeTCPServer dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_socket = self_chrome.socket; if (self_chrome_socket != null) { #region AtFormCreated FormStyler.AtFormCreated = ss => { ss.Context.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; // this is working? var x = new ChromeTCPServerWithFrameNone.HTML.Pages.AppWindowDrag().AttachTo(ss.Context.GetHTMLTarget()); }; #endregion chrome.Notification.DefaultTitle = "Heat Zeeker"; chrome.Notification.DefaultIconUrl = new HTML.Images.FromAssets.Promotion3D_iso1_tiltshift_128().src; ChromeTCPServer.TheServerWithStyledForm.Invoke( AppSource.Text, AtFormCreated: FormStyler.AtFormCreated ); return; } #endregion Native.body.style.margin = "0px"; Native.body.style.overflow = IStyle.OverflowEnum.hidden; // jsc, add THREE // ... ok. // X:\jsc.svn\examples\javascript\WebGL\WebGLOrthographicCamera\WebGLOrthographicCamera\Application.cs // this is not isometric. // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151112 var camera = new THREE.OrthographicCamera( Native.window.Width / -2, Native.window.Width / 2, Native.window.Height / 2, Native.window.Height / -2 , // if we change these values what will change? -1000, 1000 ); camera.position.x = 200; camera.position.y = 100; camera.position.z = 200; var scene = new THREE.Scene(); // Grid var size = 600; var step = 50; Func <double> random = new Random().NextDouble; // how do I add a new ground box? { var geometry = new THREE.BoxGeometry(size * 2, 2, size * 2); var material = new THREE.MeshLambertMaterial(new { color = 0xB27D51 // , shading = THREE.FlatShading, overdraw = 0.5 }); { var cube = new THREE.Mesh(geometry, material); // why cant we get the shadows?? cube.receiveShadow = true; cube.scale.y = Math.Floor(random() * 2 + 1); cube.position.x = 0; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.y = -2; cube.position.z = 0; scene.add(cube); } } { var geometry = new THREE.Geometry(); for (var i = -size; i <= size; i += step) { ((IArray <THREE.Vector3>)(object) geometry.vertices).push(new THREE.Vector3(-size, 0, i)); ((IArray <THREE.Vector3>)(object) geometry.vertices).push(new THREE.Vector3(size, 0, i)); ((IArray <THREE.Vector3>)(object) geometry.vertices).push(new THREE.Vector3(i, 0, -size)); ((IArray <THREE.Vector3>)(object) geometry.vertices).push(new THREE.Vector3(i, 0, size)); } var material = new THREE.LineBasicMaterial(new { color = 0, opacity = 0.2 }); var line = new THREE.Line(geometry, material, mode: THREE.LinePieces); scene.add(line); } var interactiveObjects = new List <THREE.Object3D>(); #region Cubes { for (var i = 0; i < 8; i++) { new HZBunker().Source.Task.ContinueWithResult( cube => { // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 2.0; cube.scale.y = 2.0; cube.scale.z = 2.0; //cube.castShadow = true; //dae.receiveShadow = true; cube.position.x = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; scene.add(cube); interactiveObjects.Add(cube); } ); new HZWaterTower().Source.Task.ContinueWithResult( cube => { // https://github.com/mrdoob/three.js/issues/1285 // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); // http://stackoverflow.com/questions/15906248/three-js-objloader-obj-model-not-casting-shadows // http://stackoverflow.com/questions/22895120/imported-3d-objects-are-not-casting-shadows-with-three-js //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 2.0; cube.scale.y = 2.0; cube.scale.z = 2.0; //cube.castShadow = true; //dae.receiveShadow = true; cube.position.x = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; scene.add(cube); interactiveObjects.Add(cube); } ); new HZCannon().Source.Task.ContinueWithResult( cube => { // https://github.com/mrdoob/three.js/issues/1285 //cube.children.WithEach(c => c.castShadow = true); //cube.traverse( // new Action<THREE.Object3D>( // child => // { // // does it work? do we need it? // //if (child is THREE.Mesh) // child.castShadow = true; // child.receiveShadow = true; // } // ) //); // um can edit and continue insert code going back in time? cube.scale.x = 2.0; cube.scale.y = 2.0; cube.scale.z = 2.0; //cube.castShadow = true; //dae.receiveShadow = true; cube.position.x = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; //cube.position.y = (cube.scale.y * 50) / 2; cube.position.z = Math.Floor((random() * 1000 - 500) / 50) * 50 + 25; // if i want to rotate, how do I do it? //cube.rotation.z = random() + Math.PI; //cube.rotation.x = random() + Math.PI; cube.rotation.y = random() * Math.PI * 2; scene.add(cube); interactiveObjects.Add(cube); } ); } } #endregion // we need expression evaluator with intellisense for live debugging sessions #region Lights var ambientLight = new THREE.AmbientLight((int)(random() * 0x10)); scene.add(ambientLight); // can we get our shadows? { var directionalLight = new THREE.DirectionalLight((int)(random() * 0xffffff), 0.5); directionalLight.position.x = random() - 0.5; directionalLight.position.y = 400; directionalLight.position.z = random() - 0.5; directionalLight.position.normalize(); scene.add(directionalLight); } { var directionalLight = new THREE.DirectionalLight((int)(random() * 0xffffff), 0.5); directionalLight.position.x = random() - 0.5; directionalLight.position.y = 400; directionalLight.position.z = random() - 0.5; directionalLight.position.normalize(); scene.add(directionalLight); } #endregion //var renderer = new THREE.CanvasRenderer(); var renderer = new THREE.WebGLRenderer(); renderer.shadowMapEnabled = true; // background-color: #B27D51; renderer.setClearColor(0xB27D51); //renderer.setSize( // Native.window.Width , // Native.window.Height * 10 // ); renderer.setSize(); renderer.domElement.AttachToDocument(); Native.window.onresize += delegate { camera.left = Native.window.Width / -2; camera.right = Native.window.Width / 2; camera.top = Native.window.Height / 2; camera.bottom = Native.window.Height / -2; camera.updateProjectionMatrix(); renderer.setSize(); }; //window.addEventListener( 'resize', onWindowResize, false ); //#region Comanche //new Comanche().Source.Task.ContinueWithResult( // Comanche => // { // Comanche.position.y = 200; // //dae.position.z = 280; // Comanche.AttachTo(scene); // //scene.add(dae); // //oo.Add(Comanche); // // wont do it // //dae.castShadow = true; // // http://stackoverflow.com/questions/15492857/any-way-to-get-a-bounding-box-from-a-three-js-object3d // //var helper = new THREE.BoundingBoxHelper(dae, 0xff0000); // //helper.update(); // //// If you want a visible bounding box // //scene.add(helper); // Comanche.children[0].children[0].children.WithEach(x => x.castShadow = true); // // the rotors? // Comanche.children[0].children[0].children.Last().children.WithEach(x => x.castShadow = true); // Comanche.scale.set(0.5, 0.5, 0.5); // //helper.scale.set(0.5, 0.5, 0.5); // var sw = Stopwatch.StartNew(); // Native.window.onframe += delegate // { // //dae.children[0].children[0].children.Last().al // //dae.children[0].children[0].children.Last().rotation.z = sw.ElapsedMilliseconds * 0.01; // //dae.children[0].children[0].children.Last().rotation.x = sw.ElapsedMilliseconds * 0.01; // //rotation.y = sw.ElapsedMilliseconds * 0.01; // Comanche.children[0].children[0].children.Last().rotation.y = sw.ElapsedMilliseconds * 0.001; // //dae.children[0].children[0].children.Last().app // }; // } //); //#endregion //#region ee //// X:\jsc.svn\examples\javascript\forms\NumericTextBox\NumericTextBox\ApplicationControl.cs //// can we restile the window as the pin window in IDE? //var ee = new Form { Left = 0, StartPosition = FormStartPosition.Manual }; //var ee_camera_y = new TextBox { Dock = DockStyle.Fill, Text = camera.position.y + "" }.AttachTo(ee); ////ee.AutoSize = AutoSizeMode. ////ee.ClientSize = new System.Drawing.Size(ee_camera_y.Width, ee_camera_y.Height); //ee.ClientSize = new System.Drawing.Size(200, 24); //ee.Show(); ////ee_camera_y. //ee_camera_y.TextChanged += delegate //{ // camera.position.y = double.Parse(ee_camera_y.Text); //}; //#endregion var s = Stopwatch.StartNew(); var controls = new THREE.OrbitControls(camera, renderer.domElement); // http://stackoverflow.com/questions/26497903/nested-webglrendertargets-in-three-js // var effect = new THREE.OculusRiftEffect( //renderer, new //{ // worldScale = 100, // //HMD // } //); // effect.setSize(1920, 1080); Native.window.onframe += e => { // jsc, when can we have the edit and continue already? //var timer = s.ElapsedMilliseconds * 0.1; //var timer = s.ElapsedMilliseconds * 0.0001; //camera.position.x = Math.Cos(timer) * 200; //camera.position.z = Math.Sin(timer) * 200; // camera.position.z = 200; //camera.position.y = 100; //camera.position.y = Math.Sin(timer * 0.1) * 200; controls.update(); camera.position = controls.center.clone(); renderer.render(scene, camera); //effect.render(scene, camera); }; //var ze = new ZeProperties(); //ze.Show(); //ze.treeView1.Nodes.Clear(); //ze.Add(() => renderer); ////ze.Add(() => controls); //ze.Add(() => scene); //ze.Left = 0; // view-source:http://mrdoob.github.io/three.js/examples/webgl_interactive_voxelpainter.html //var mouse2D = new THREE.Vector3(0, 10000, 0.5); //renderer.domElement.onclick += // e => // { // e.preventDefault(); // mouse2D.x = (e.CursorX / (double)Native.window.Width) * 2 - 1; // mouse2D.y = -(e.CursorY / (double)Native.window.Height) * 2 + 1; // var vector = new THREE.Vector3( // (e.CursorX / (double)Native.window.Width) * 2 - 1, // -(e.CursorY / (double)Native.window.Height) * 2 + 1, // 0.5); // // X:\jsc.svn\examples\javascript\WebGL\WebGLInteractiveCubes\WebGLInteractiveCubes\Application.cs // var projector = new THREE.Projector(); // projector.unprojectVector(vector, camera); // // http://stackoverflow.com/questions/18553209/orthographic-camera-and-selecting-objects-with-raycast // // http://stackoverflow.com/questions/20361776/orthographic-camera-and-pickingray // // view-source:http://stemkoski.github.io/Three.js/Mouse-Click.html // // http://stackoverflow.com/questions/11921033/projector-and-ray-with-orthographiccamera // // use picking ray since it's an orthographic camera // // doesnt fkin work ??? // //var raycaster = projector.pickingRay(vector, camera); // var raycaster = projector.pickingRay(mouse2D.clone(), camera); // //var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize()); // var intersects = raycaster.intersectObjects(interactiveObjects.ToArray()); // // https://github.com/mrdoob/three.js/issues/599 // Native.document.title = new { intersects.Length }.ToString(); // }; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // SCENE scene = new THREE.Scene(); // CAMERA var SCREEN_WIDTH = Native.window.Width; var SCREEN_HEIGHT = Native.window.Height; var VIEW_ANGLE = 45; var ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT; var NEAR = 0.1; var FAR = 20000; // perspective cameras perspectiveCamera = new THREE.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR); perspectiveCamera.position.set(0,200,550); perspectiveCamera.lookAt(scene.position); scene.add(perspectiveCamera); // orthographic cameras mapCamera = new THREE.OrthographicCamera( Native.window.Width / -2, // Left Native.window.Width / 2, // Right Native.window.Height / 2, // Top Native.window.Height / -2, // Bottom -5000, // Near 10000 ); // Far mapCamera.up = new THREE.Vector3(0,0,-1); mapCamera.lookAt( new THREE.Vector3(0,-1,0) ); scene.add(mapCamera); renderer = new THREE.WebGLRenderer( new { antialias = true } ); // RENDERER renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT); this.container = (IHTMLCanvas)renderer.domElement; this.container.AttachToDocument(); this.container.style.SetLocation(0, 0); // EVENTS //THREEx.WindowResize(renderer, mapCamera); //THREEx.FullScreen.bindKey({ charCode : 'm'.charCodeAt(0) }); // STATS //stats = new Stats(); //stats.domElement.style.position = 'absolute'; //stats.domElement.style.bottom = '0px'; //stats.domElement.style.zIndex = 100; //container.appendChild( stats.domElement ); // LIGHT var light = new THREE.PointLight(0xffffff); light.position.set(0,250,0); scene.add(light); // FLOOR var img = new uvgrid01(); var floorTexture = new THREE.Texture().With( async s => { s.image = await img; s.needsUpdate = true; }); floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping; floorTexture.repeat.set( 10, 10 ); var floorMaterial = new THREE.MeshBasicMaterial( new { map = floorTexture, side = THREE.DoubleSide } ); var floorGeometry = new THREE.PlaneGeometry(2000, 2000, 10, 10); var floor = new THREE.Mesh(floorGeometry, floorMaterial); floor.position.y = -0.5; floor.rotation.x = Math.PI / 2; scene.add(floor); //////////// // CUSTOM // //////////// // materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/xpos.png' ) })); //materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/xneg.png' ) })); //materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/ypos.png' ) })); //materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/yneg.png' ) })); //materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/zpos.png' ) })); //materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/zneg.png' ) })); // create an array with six textures for cube var materialArray = new THREE.MeshBasicMaterial[6]; materialArray[0] = (new THREE.MeshBasicMaterial( new { map = new THREE.Texture().With( async s => { s.image = await new xpos(); s.needsUpdate = true; }) })); materialArray[1] = (new THREE.MeshBasicMaterial( new { map = new THREE.Texture().With( async s => { s.image = await new xneg(); s.needsUpdate = true; }) })); materialArray[2] = (new THREE.MeshBasicMaterial( new { map = new THREE.Texture().With( async s => { s.image = await new ypos(); s.needsUpdate = true; }) })); materialArray[3] = (new THREE.MeshBasicMaterial( new { map = new THREE.Texture().With( async s => { s.image = await new yneg(); s.needsUpdate = true; }) })); materialArray[4] = (new THREE.MeshBasicMaterial( new {map = new THREE.Texture().With( async s => { s.image = await new zpos(); s.needsUpdate = true; }) })); materialArray[5] = (new THREE.MeshBasicMaterial( new { map = new THREE.Texture().With( async s => { s.image = await new zneg(); s.needsUpdate = true; }) })); //var MovingCubeMat = new THREE.MeshFaceMaterial(new { material = materialArray }); var MovingCubeGeom = new THREE.CubeGeometry(50, 50, 50, 1, 1, 1); var MovingCube = new THREE.Mesh(MovingCubeGeom, new THREE.MeshBasicMaterial(new { color = new THREE.Color(0xFFFFFF) })); MovingCube.position.set(0, 25.1, 0); scene.add(MovingCube); // a little bit of scenery... var ambientlight = new THREE.AmbientLight(0x111111); scene.add( ambientlight ); // torus knot var colorMaterial = new THREE.MeshLambertMaterial(new { color = new THREE.Color(0xff3333) }); var shape = new THREE.Mesh(new THREE.TorusKnotGeometry(30, 6, 160, 10, 2, 5, 4), colorMaterial); shape.position.set(-200, 50, -200); scene.add(shape); // torus knot var colorMaterial2 = new THREE.MeshLambertMaterial(new { color = new THREE.Color(0x33ff33) }); var shape2 = new THREE.Mesh(new THREE.TorusKnotGeometry(30, 6, 160, 10, 3, 2, 4), colorMaterial2); shape2.position.set(200, 50, -200); scene.add(shape2); // torus knot var colorMaterial3 = new THREE.MeshLambertMaterial(new { color = new THREE.Color(0xffff33) }); var shape3 = new THREE.Mesh(new THREE.TorusKnotGeometry(30, 6, 160, 10, 4, 3, 4), colorMaterial3); shape3.position.set(200, 50, 200); scene.add(shape3); // torus knot var colorMaterial4 = new THREE.MeshLambertMaterial(new { color = new THREE.Color(0x3333ff) }); var shape4 = new THREE.Mesh(new THREE.TorusKnotGeometry(30, 6, 160, 10, 3, 4, 4), colorMaterial4); shape4.position.set(-200, 50, 200); scene.add(shape4); renderer.setSize(Native.window.Width, Native.window.Height); renderer.setClearColor( 0x000000, 1 ); renderer.autoClear = false; Native.window.onframe += e => { perspectiveCamera.updateProjectionMatrix(); render(); }; var isPushed = false; this.container.onkeydown += m => { isPushed = true; if (isPushed) { //var delta = clock.getDelta(); // seconds. var moveDistance = 200 * 2; // 200 pixels per second var rotateAngle = Math.PI / 2 * 2; // pi/2 radians (90 degrees) per second // local transformations // move forwards/backwards/left/right if (m.KeyCode == 87) MovingCube.translateZ(-moveDistance); if (m.KeyCode == 83) MovingCube.translateZ(moveDistance); if (m.KeyCode == 81) MovingCube.translateX(-moveDistance); if (m.KeyCode == 69) MovingCube.translateX(moveDistance); //// rotate left/right/up/down //var rotation_matrix = new THREE.Matrix4().identity(); //if (m.KeyCode == 65) // MovingCube.rotateOnAxis(new THREE.Vector3(0, 1, 0), rotateAngle); //if (m.KeyCode == 68) // MovingCube.rotateOnAxis(new THREE.Vector3(0, 1, 0), -rotateAngle); //if (m.KeyCode == 90) //{ // MovingCube.position.set(0, 25.1, 0); // MovingCube.rotation.set(0, 0, 0); //} } }; this.container.onkeyup += e => { isPushed = false; }; Native.window.onresize += delegate { //if (canvas.parentNode == Native.document.body) // are we embedded? if (page != null) renderer.setSize(); }; }