Example #1
0
        private void ShowGeometry()
        {
            if (currentMesh != null)
            {
                scene.remove(currentMesh);
            }

            if (geometryIndex < 0)
            {
                geometryIndex = 0;
            }

            GeometryFunction f = functions[geometryIndex];

            THREE.Geometry geometry = f.function();

            THREE.Material mat = new THREE.MeshLambertMaterial();
            mat.color = new THREE.Color().setHex(Math.Random() * 0xffffff);


            currentMesh = new THREE.Mesh(geometry, mat);
            scene.add(currentMesh);

            dropDownButton.Text(f.name);
            Render();
        }
Example #2
0
        static THREE.Geometry cube(double size = 50)
        {
            var h = size * 0.5;

            var geometry = new THREE.Geometry();

            geometry.vertices = new[] {
                new THREE.Vector3(-h, -h, -h),
                new THREE.Vector3(-h, h, -h),

                new THREE.Vector3(-h, h, -h),
                new THREE.Vector3(h, h, -h),

                new THREE.Vector3(h, h, -h),
                new THREE.Vector3(h, -h, -h),

                new THREE.Vector3(h, -h, -h),
                new THREE.Vector3(-h, -h, -h),


                new THREE.Vector3(-h, -h, h),
                new THREE.Vector3(-h, h, h),

                new THREE.Vector3(-h, h, h),
                new THREE.Vector3(h, h, h),

                new THREE.Vector3(h, h, h),
                new THREE.Vector3(h, -h, h),

                new THREE.Vector3(h, -h, h),
                new THREE.Vector3(-h, -h, h),

                new THREE.Vector3(-h, -h, -h),
                new THREE.Vector3(-h, -h, h),

                new THREE.Vector3(-h, h, -h),
                new THREE.Vector3(-h, h, h),

                new THREE.Vector3(h, h, -h),
                new THREE.Vector3(h, h, h),

                new THREE.Vector3(h, -h, -h),
                new THREE.Vector3(h, -h, h)
            };

            return(geometry);
        }
Example #3
0
            public List <Vector2> generateTopUV(THREE.Geometry geometry, Shape extrudedShape, int indexA, int indexB, int indexC)
            {
                float ax = geometry.vertices[indexA].x;
                float ay = geometry.vertices[indexA].y;

                float bx = geometry.vertices[indexB].x;
                float by = geometry.vertices[indexB].y;

                float cx = geometry.vertices[indexC].x;
                float cy = geometry.vertices[indexC].y;

                return(new List <Vector2>(new Vector2[] {
                    new Vector2(ax, ay),
                    new Vector2(bx, by),
                    new Vector2(cx, cy)
                }));
            }
Example #4
0
            public List <Vector2> generateSideWallUV(THREE.Geometry geometry, Shape extrudedShape, List <Vector3> wallContour,
                                                     int indexA, int indexB, int indexC, int indexD, int stepIndex, int stepsLength,
                                                     int contourIndex1, int contourIndex2)
            {
                float ax = geometry.vertices[indexA].x,
                      ay = geometry.vertices[indexA].y,
                      az = geometry.vertices[indexA].z,

                      bx = geometry.vertices[indexB].x,
                      by = geometry.vertices[indexB].y,
                      bz = geometry.vertices[indexB].z,

                      cx = geometry.vertices[indexC].x,
                      cy = geometry.vertices[indexC].y,
                      cz = geometry.vertices[indexC].z,

                      dx = geometry.vertices[indexD].x,
                      dy = geometry.vertices[indexD].y,
                      dz = geometry.vertices[indexD].z;

                if (Mathf.Abs(ay - by) < 0.01f)
                {
                    return(new List <Vector2>(new Vector2[] {
                        new Vector2(ax, 1 - az),
                        new Vector2(bx, 1 - bz),
                        new Vector2(cx, 1 - cz),
                        new Vector2(dx, 1 - dz)
                    }));
                }
                else
                {
                    return(new List <Vector2>(new Vector2[] {
                        new Vector2(ay, 1 - az),
                        new Vector2(by, 1 - bz),
                        new Vector2(cy, 1 - cz),
                        new Vector2(dy, 1 - dz)
                    }));
                }
            }
Example #5
0
 public List <Vector2> generateBottomUV(THREE.Geometry geometry, Shape extrudedShape, int indexA, int indexB, int indexC)
 {
     return(this.generateTopUV(geometry, extrudedShape, indexA, indexB, indexC));
 }
		/// <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();
			//    };
		}
Example #7
0
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150812/cssstereo

        //0001 02000178 ScriptCoreLib::ScriptCoreLib.Shared.BCLImplementation.System.Security.Cryptography.__MD5CryptoServiceProvider
        //script: error JSC1000: Java : Opcode not implemented: stind.i1 at ScriptCoreLib.Shared.BCLImplementation.System.Security.Cryptography.__MD5CryptoServiceProviderByMahmood.CreatePaddedBuffer
        //internal compiler error at method

        //       script: error JSC1000: Java :
        //BCL needs another method, please define it.
        //Cannot call type without script attribute :
        //System.Threading.Monitor for Void Enter(System.Object, Boolean ByRef) used at
        //WebGLVRCreativeLeadership.Activities.ApplicationWebServiceActivity+<>c__DisplayClass24.<CreateServer>b__29 at offset 0018.
        //If the use of this method is intended, an implementation should be provided with the attribute[Script(Implements = typeof(...)] set.You may have mistyped it.

        //		I/chromium(13596): [INFO: CONSOLE(97050)] "THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter is set to THREE.LinearFilter or THREE.NearestFilter. ( undefined )", source: http://192.168.1.228:23993/view-source (97050)
        //I/chromium(13596): [INFO: CONSOLE(97050)] "THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter is set to THREE.LinearFilter or THREE.NearestFilter. ( undefined )", source: http://192.168.1.228:23993/view-source (97050)

        public Application(com.abstractatech.apps.vr.HTML.Pages.IApp page)
        {
            #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)
            {
                ChromeTCPServer.TheServerWithAppWindow.Invoke(com.abstractatech.apps.vr.HTML.Pages.AppSource.Text);

                return;
            }
            #endregion

            // https://play.google.com/store/apps/details?id=com.abstractatech.vr
            // could we display LAN UDP notifications too. like
            // which youtube video is playing?

            Native.body.Clear();
            Native.body.style.margin          = "0px";
            Native.body.style.backgroundColor = "black";

            // https://vronecontest.zeiss.com/index.php?controller=ideas&view=show&id=652

            //          hResolution: 1920,
            //vResolution: 1080,

            // "X:\jsc.svn\examples\javascript\synergy\webgl\WebGLEquirectangularPanorama\WebGLEquirectangularPanorama.sln"

            // http://oculusstreetview.eu.pn/?lat=44.301987&lng=9.211561999999958&q=3&s=false&heading=0
            // https://github.com/troffmo5/OculusStreetView

            // http://stackoverflow.com/questions/23817633/threejs-using-a-sprite-with-the-oculusrifteffect
            // http://laht.info/dk2-parameters-for-three-oculusrifteffect-js/

            // http://stemkoski.github.io/Three.js/Sprites.html
            // http://stemkoski.github.io/Three.js/Texture-Animation.html
            // http://blog.thematicmapping.org/2013/10/terrain-visualization-with-threejs-and.html

            // http://mrdoob.github.io/three.js/examples/webgl_panorama_equirectangular.html

            var window = Native.window;

            var fov = 70.0;

            var camera = new THREE.PerspectiveCamera(fov,
                                                     window.aspect, 1, 1100);
            var target = new THREE.Vector3(0, 0, 0);

            //(camera as dynamic).target = target;

            var scene = new THREE.Scene();
            //scene.add(new THREE.AmbientLight(0xffffff));
            //scene.add(new THREE.AmbientLight(0xafafaf));

            // http://www.html5canvastutorials.com/three/html5-canvas-webgl-ambient-lighting-with-three-js/

            // http://stackoverflow.com/questions/14717135/three-js-ambient-light-unexpected-effect

            scene.add(new THREE.AmbientLight(0x2f2f2f));


            //var light = new THREE.DirectionalLight(0xffffff, 1.0);
            #region light
            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.3;
            //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 mesh = new THREE.Mesh(new THREE.SphereGeometry(500, 60, 40),
                                      new THREE.MeshBasicMaterial(new
            {
                map = THREE.ImageUtils.loadTexture(
                    new _2294472375_24a3b8ef46_o().src
                    //new WebGLEquirectangularPanorama.HTML.Images.FromAssets.PANO_20130616_222058().src
                    //new WebGLEquirectangularPanorama.HTML.Images.FromAssets.PANO_20121225_210448().src

                    )
            }));
            mesh.scale.x = -1;
            scene.add(mesh);

            #region sprite2
            var crateTexture = THREE.ImageUtils.loadTexture(
                new ChromeCreativeLeadership.HTML.Images.FromAssets.Mockup().src

                );

            var crateMaterial = new THREE.SpriteMaterial(
                new
            {
                map = crateTexture,
                useScreenCoordinates = false,
                //color = 0xff0000
                color = 0xffffff
            }
                );



            var sprite2 = new THREE.Sprite(crateMaterial);

            //floor
            //sprite2.position.set(0, -200, 0);

            // left
            //sprite2.position.set(200, 50, 0);

            sprite2.position.set(0, 0, 200);

            //sprite2.position.set(-100, 0, 0);
            sprite2.scale.set(
                _2294472375_24a3b8ef46_o.ImageDefaultWidth * 0.08,
                _2294472375_24a3b8ef46_o.ImageDefaultHeight * 0.08,
                //64, 64,
                1.0);                 // imageWidth, imageHeight
            scene.add(sprite2);
            #endregion


            #region ColladaAudiA4
            new ColladaAudiA4().Source.Task.ContinueWithResult(
                dae =>
            {
                // 90deg
                //dae.rotation.x = -Math.Cos(Math.PI);

                //dae.scale.x = 30;
                //dae.scale.y = 30;
                //dae.scale.z = 30;
                //dae.position.z = 65;

                // right
                dae.position.z = -20;
                dae.position.x = -100;
                dae.position.y = -90;


                // jsc, do we have ILObserver available yet?
                dae.scale.x = 1.0;
                dae.scale.y = 1.0;
                dae.scale.z = 1.0;

                //dae.position.y = -80;

                scene.add(dae);
                //oo.Add(dae);
            }
                );
            #endregion



            #region nexus7
            new nexus7().Source.Task.ContinueWithResult(
                dae =>
            {
                // 90deg
                dae.rotation.x = -Math.Cos(Math.PI);

                //dae.scale.x = 30;
                //dae.scale.y = 30;
                //dae.scale.z = 30;
                //dae.position.z = 65;

                // left
                //dae.position.x = 200;

                dae.position.z = -100;
                dae.position.y = -50;

                //dae.position.z = 100;



                // jsc, do we have ILObserver available yet?
                dae.scale.x = 13.5;
                dae.scale.y = 13.5;
                dae.scale.z = 13.5;

                //dae.position.y = -80;

                scene.add(dae);
                //oo.Add(dae);
            }
                );
            #endregion



            //          // DK2
            //          hResolution: 1920,
            //vResolution: 1080,

            var renderer = new THREE.WebGLRenderer();
            renderer.setSize(1920, 1080);


            // broken?
            var distortionK       = new double[] { 1.0, 0.22, 0.24, 0.0 };
            var chromaAbParameter = new double[] { 0.996, -0.004, 1.014, 0.0 };

            var HMD = new OculusRiftEffectOptions
            {
                hResolution = window.Width,
                vResolution = window.Height,

                hScreenSize            = 0.12576,
                vScreenSize            = 0.07074,
                interpupillaryDistance = 0.0635,
                lensSeparationDistance = 0.0635,
                eyeToScreenDistance    = 0.041,

                //  j.distortionK = [0, 1.875, -71.68, 1.595, -3.218644E+26, 1.615, 0, 0];
                //distortionK = new double[] { 1.0, 0.22, 0.24, 0.0 },
                distortionK = distortionK,

                // j.chromaAbParameter = [1.609382E+22, 1.874, -5.189695E+11, -0.939, 4.463059E-29, 1.87675, 0, 0];
                //chromaAbParameter = new double[] { 0.996, -0.004, 1.014, 0.0 }
                chromaAbParameter = chromaAbParameter
            };

            var effect = new THREE.OculusRiftEffect(
                renderer, new
            {
                worldScale = 100,

                //HMD
            }
                );

            effect.setSize(1920, 1080);


            renderer.domElement.AttachToDocument();

            //renderer.domElement.style.position = IStyle.PositionEnum.absolute;
            renderer.domElement.style.SetLocation(0, 0);

            Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;

            // x:\jsc.svn\examples\javascript\synergy\comanchebysiorki\comanchebysiorki\application.cs


            #region onresize
            new { }.With(
                async delegate
            {
                retry:

                var s = (double)Native.window.Width / 1920.0;


                Native.document.body.style.transform       = "scale(" + s + ")";
                Native.document.body.style.transformOrigin = "0% 0%";

                await Native.window.async.onresize;
                goto retry;
            }
                );
            #endregion



            //#region onresize
            //Native.window.onresize +=
            //    delegate
            //    {
            //        camera.aspect = Native.window.aspect;
            //        camera.updateProjectionMatrix();

            //        renderer.setSize(window.Width, window.Height);
            //        effect.setSize(window.Width, window.Height);
            //    };
            //#endregion


            //Native.document.body.onmousewheel +=
            //    e =>
            //    {
            //        fov -= e.WheelDirection * 5.0;
            //        camera.projectionMatrix.makePerspective(fov,
            //            (double)window.Width / window.Height, 1, 1100);
            //    };

            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 camera_rotation_z = 0.0;


            var labove = new NotificationLayout();

            #region sprite2 above
            {
                labove.Message.innerText       = "VR CREATIVE LEADERSHIP";
                labove.layout.style.background = "";

                new { }.With(
                    async delegate
                {
                    retry:

                    // make it blink. gaze cursor is on it?


                    labove.box.style.background = "rgba(255,255,0,0.7)";
                    labove.box.setAttribute("invoke", "onmutation1");
                    await Task.Delay(1500);

                    // is mutation observer noticing it?
                    labove.box.style.background = "rgba(255,255,255,0.7)";
                    labove.box.setAttribute("invoke", "onmutation2");
                    await Task.Delay(1500);


                    goto retry;
                }
                    );



                var c = labove.AsCanvas();

                var xcrateTexture = new THREE.Texture(c);

                // like video texture
                Native.window.onframe += delegate { xcrateTexture.needsUpdate = true; };

                var xcrateMaterial = new THREE.SpriteMaterial(
                    new
                {
                    map = xcrateTexture,
                    useScreenCoordinates = false,
                    //color = 0xff0000
                    color = 0xffffff
                }
                    );



                var xsprite2 = new THREE.Sprite(xcrateMaterial);

                //floor
                //sprite2.position.set(0, -200, 0);

                // left
                xsprite2.position.set(200, 0, 0);

                //sprite2.position.set(0, 0, 200);

                //sprite2.position.set(-100, 0, 0);
                xsprite2.scale.set(
                    c.width * 0.5,
                    c.height * 0.5,
                    //64, 64,
                    1.0);                     // imageWidth, imageHeight
                scene.add(xsprite2);
            }
            #endregion



            //var lineTo = new List<THREE.Vector3>();
            var others = new
            {
                ui     = default(NotificationLayout),
                canvas = default(IHTMLCanvas),

                map = default(THREE.Texture),

                sprite = default(THREE.Sprite)
            }.ToEmptyList();

            #region add
            Action <NotificationLayout> add = ui =>
            {
                ui.layout.style.background = "";

                var canvas = ui.AsCanvas();
                var index  = others.Count;

                //ui.Message  += new { index };
                //ui.Message.innerText += new { index };

                //lbelow0.Message = new { THREE.REVISION }.ToString();

                // THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter is set to THREE.LinearFilter or THREE.NearestFilter. ( undefined )

                var map = new THREE.Texture(canvas);

                map.minFilter = THREE.LinearFilter;

                // like video texture

                var xcrateMaterial = new THREE.SpriteMaterial(
                    new
                {
                    map,
                    useScreenCoordinates = false,
                    //color = 0xff0000
                    color = 0xffffff
                }
                    );



                var sprite = new THREE.Sprite(xcrateMaterial);

                //floor
                //sprite2.position.set(0, -200, 0);

                // left middle
                //sprite2.position.set(200, 0, 0);
                //sprite.position.set(250, -50, 50);
                //lineTo.Add(sprite.position);



                //sprite2.position.set(0, 0, 200);

                //sprite2.position.set(-100, 0, 0);
                sprite.scale.set(
                    canvas.width * 0.5,
                    canvas.height * 0.5,
                    //64, 64,
                    1.0);                     // imageWidth, imageHeight
                scene.add(sprite);

                others.Add(
                    new
                {
                    ui,
                    canvas,
                    map,
                    sprite
                }
                    );

                var sw = Stopwatch.StartNew();

                Native.window.onframe += delegate
                {
                    // can we get some of the crazy c++ template bitmapbuffer code from the past?
                    map.needsUpdate = true;

                    var offset = Math.PI * 2 * ((double)(index + 1) / others.Count);

                    sprite.position.x = 300;

                    sprite.position.z = Math.Sin(sw.ElapsedMilliseconds * 0.00001 + offset) * 120;
                    sprite.position.y = Math.Cos(sw.ElapsedMilliseconds * 0.00001 + offset) * 120;
                };
            };
            #endregion


            #region NotificationLayout
            add(
                new NotificationLayout
            {
                // keep attributes around?
                // like we do with XElement sync?
                Icon = new _0_10122014_ECAF4B1F638429B44F4B142C2A4F38EE().With(
                    x =>
                {
                    x.style.width  = "96px";
                    x.style.height = "96px";
                }
                    ),
                Message = "Advanced Mechanics by Portugal Design Lab"
            }
                );

            add(
                new NotificationLayout
            {
                // keep attributes around?
                // like we do with XElement sync?
                Icon = new _42_08122014_D2639E0AAA3E54E5F4568760AEE605EE().With(
                    x =>
                {
                    x.style.width  = "96px";
                    x.style.height = "96px";
                }
                    ),
                Message = "Face Value by mshariful"
            }
                );



            add(
                new NotificationLayout
            {
                // keep attributes around?
                // like we do with XElement sync?
                Icon = new _371_28122014_2045510F2F7974319A9F7E9F4B39DF07().With(
                    x =>
                {
                    x.style.width  = "96px";
                    x.style.height = "96px";
                }
                    ),
                Message = "Mind Wall. by Sumit Goski"
            }
                );
            #endregion



            #region lines
            {
                var geometry = new THREE.Geometry
                {
                    // how can we keep streaming verticies data points to gpu?
                    vertices =

                        others.SelectMany(
                            lineTo =>
                            new[]
                    {
                        new THREE.Vector3(200, 0, 0),
                        lineTo.sprite.position
                    }
                            ).ToArray()

                        // https://github.com/mrdoob/three.js/wiki/Updates
                        // http://stackoverflow.com/questions/17842521/adding-geometry-to-a-three-js-mesh-after-render
                        //verticesNeedUpdate = true
                };

                Native.window.onframe += delegate { geometry.verticesNeedUpdate = true; };

                var o = new THREE.Line(geometry, new THREE.LineDashedMaterial(
                                           new { color = 0x00aaff, dashSize = 1, gapSize = 0.5, linewidth = 1 }
                                           ), THREE.LineStrip);

                //objects.Add(o);
                scene.add(o);
            }
            #endregion

            Native.window.onframe +=
                ee =>
            {
                // look we are having html in 3D in VR!



                //if (Native.document.pointerLockElement == Native.document.body)
                //    lon += 0.00;
                //else
                //    lon += 0.01;

                //lat = Math.Max(-85, Math.Min(85, lat));

                //Native.document.title = new { lon, lat }.ToString();


                phi   = THREE.Math.degToRad(90 - lat);
                theta = THREE.Math.degToRad(lon);

                target.x = 500 * Math.Sin(phi) * Math.Cos(theta);
                target.y = 500 * Math.Cos(phi);
                target.z = 500 * Math.Sin(phi) * Math.Sin(theta);

                camera.lookAt(target);
                camera.rotation.z += camera_rotation_z;

                //renderer.render(scene, camera);
                effect.render(scene, camera);
            };



            // http://blog.thematicmapping.org/2013/10/terrain-visualization-with-threejs-and.html

            // http://stackoverflow.com/questions/13278087/determine-vertical-direction-of-a-touchmove



            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;;
            };
            // https://developer.android.com/training/system-ui/immersive.html
        }
        public Application(IApp page)
        {
            // view-source:http://oos.moxiecode.com/js_webgl/dna/

            var scene = new THREE.Scene();
            scene.fog = new THREE.Fog(0x000000, 20, 70);

            var camera = new THREE.PerspectiveCamera(70, Native.window.aspect, 1, 10000);
            camera.position.z = -50;
            camera.lookAt(scene.position);
            scene.add(camera);

            var pg = new THREE.PlaneGeometry(170, 10, 80, 1);
            var il = pg.vertices.Length;

            for (var i = 0; i < il; i++)
            {
                pg.vertices[i].z = (4 + (i / 15.0)) * Math.Cos(i / 5.0);
                pg.vertices[i].y = (6 + (i / 30.0)) * Math.Sin(i / 5.0);
            }

            var mat = new THREE.MeshBasicMaterial(new { wireframe = true, color = 0xb2ffd8 });
            var mesh = new THREE.Mesh(pg, mat);
            mesh.rotation.x = -Math.PI / 2;
            scene.add(mesh);

            var vertices = pg.vertices;
            var vl = vertices.Length;
            var geometry = new THREE.Geometry();
            // c#, you can look ahead an realize how long our array needs to be!
            var vertices_tmp = new double[vl][];

            for (var i = 0; i < vl; i++)
            {
                var p = vertices[i];

                geometry.vertices[i] = p.clone();
                vertices_tmp[i] = new[] { p.x, p.y, p.z, 0, 0 };

            }


            var material = new THREE.ParticleSystemMaterial(
                new
            {
                map = THREE.ImageUtils.loadTexture(new bob().src),
                color = 0xb2ffd8,
                depthTest = false,
                size = 5,
                blending = THREE.NormalBlending
            }
            );

            var pmesh = new THREE.ParticleSystem(geometry, material);
            scene.add(pmesh);

            var renderer = new THREE.WebGLRenderer(new { antialias = false });
            renderer.setSize();
            renderer.autoClear = false;

            renderer.domElement.AttachToDocument();
            //renderer.domElement.style.position = IStyle.PositionEnum.@fixed;
            renderer.domElement.style.SetLocation(0, 0);
            renderer.setSize();

            Native.window.onresize +=
                delegate
                {
            renderer.setSize();
            };

            var w = Stopwatch.StartNew();

            Native.window.onframe +=
                delegate
            {
                var time = w.ElapsedMilliseconds;

                mesh.rotation.x += 0.02 + Math.Abs(Math.Sin(time / 3000.0)) / 40;
                pmesh.rotation.x = mesh.rotation.x;

                mesh.scale.y = Math.Cos(time / 2500.0) * 2.0;
                pmesh.scale.y = mesh.scale.y;

                renderer.render(scene, camera);
            };

        }
Example #9
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);
            };
        }
Example #10
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:\jsc.svn\examples\javascript\CanvasMarchinAntsExperiment\CanvasMarchinAntsExperiment\Application.cs
            // http://mattdesl.svbtle.com/drawing-lines-is-hard

            Native.body.Clear();
            Native.body.style.margin   = "0px";
            Native.body.style.overflow = IStyle.OverflowEnum.hidden;


            // http://threejs.org/examples/webgl_lines_dashed.html

            var objects = new List <THREE.Line>();

            var camera = new THREE.PerspectiveCamera(60,
                                                     Native.window.aspect, 1, 200);

            camera.position.z = 150;

            var scene = new THREE.Scene();

            scene.fog = new THREE.Fog(0x111111, 150, 200);

            var root = new THREE.Object3D();

            var subdivisions = 6;
            var recursion    = 1;

            var points = hilbert3D(new THREE.Vector3(), 25.0, recursion, 0, 1, 2, 3, 4, 5, 6, 7);

            Console.WriteLine(
                new { points.Length }
                );

            #region spline
            var spline         = new THREE.Spline(points);
            var geometrySpline = new THREE.Geometry();

            for (var i = 0; i < points.Length * subdivisions; i++)
            {
                var index    = (double)i / (points.Length * subdivisions);
                var position = spline.getPoint(index);

                geometrySpline.vertices[i] = new THREE.Vector3(position.x, position.y, position.z);

                Console.WriteLine(
                    new { i, index, position.x, position.y, position.z }
                    );
            }
            #endregion

            var geometryCube = cube(50);

            geometryCube.computeLineDistances();
            geometrySpline.computeLineDistances();

            {
                var ogeometrySpline = new THREE.Line(geometrySpline, new THREE.LineDashedMaterial(
                                                         new { color = 0xffffff, dashSize = 1, gapSize = 0.5 }
                                                         ), THREE.LineStrip);

                objects.Add(ogeometrySpline);
                scene.add(ogeometrySpline);
                ogeometrySpline.AttachTo(scene);
            }
            {
                var ogeometryCube = new THREE.Line(geometryCube, new THREE.LineDashedMaterial(
                                                       new { color = 0xffaa00, dashSize = 3, gapSize = 1, linewidth = 2 }
                                                       ), THREE.LinePieces);

                objects.Add(ogeometryCube);
                ogeometryCube.AttachTo(scene);
            }

            {
                var geometry = new THREE.Geometry
                {
                    vertices = new[] {
                        new THREE.Vector3(0, 0, 0),
                        new THREE.Vector3(100, 0, 0)
                    }
                };


                var oline = new THREE.Line(geometry, new THREE.LineDashedMaterial(
                                               new { color = 0x00aaff, dashSize = 3, gapSize = 3, linewidth = 20 }
                                               ), THREE.LinePieces);

                objects.Add(oline);
                //scene.add(o);
                oline.AttachTo(scene);
            }

            var renderer = new THREE.WebGLRenderer(new { antialias = true });
            renderer.setClearColor(0x111111);
            //renderer.setPixelRatio( window.devicePixelRatio );
            renderer.setSize(
                Native.window.Width,
                Native.window.Height
                );


            renderer.domElement.AttachToDocument();


            var controls = new THREE.OrbitControls(camera, renderer.domElement);

            var sw = Stopwatch.StartNew();

            Native.window.onframe +=
                delegate
            {
                //var time = sw.ElapsedMilliseconds * 0.001;

                //for (var i = 0; i < objects.Count; i++)
                //{

                //    var o = objects[i];

                //    //object.rotation.x = 0.25 * time * ( i%2 == 1 ? 1 : -1);
                //    o.rotation.x = 0.25 * time;
                //    o.rotation.y = 0.25 * time;

                //}


                controls.update();
                camera.position = controls.center.clone();

                renderer.render(scene, camera);
            };



            //var ze = new ZeProperties
            //{
            //    //() => renderer
            //};

            //ze.Show();

            //ze.treeView1.Nodes.Clear();

            //ze.Add(() => renderer);
            //ze.Add(() => controls);
            //ze.Add(() => scene);

            //ze.Left = 0;
        }
Example #11
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)
        {
            // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150824

            // http://stackoverflow.com/questions/14103986/canvas-and-spritematerial

            // X:\jsc.svn\examples\javascript\WebGL\WebGLSVGAnonymous\WebGLSVGAnonymous\Application.cs
            // X:\jsc.svn\examples\javascript\WebGL\WebGLVRCreativeLeadership\WebGLVRCreativeLeadership\Application.cs
            // X:\jsc.svn\examples\javascript\WebGL\WebGLSVGSprite\WebGLSVGSprite\Application.cs

            //var l = new NotificationLayout().layout;

            //l.AttachToDocument();

            // : INodeConvertible<IHTMLElement>
            //var c = (IHTMLCanvas)l.layout;
            //var c = (IHTMLCanvas)l;

            // look we have a databound 2D image!

            // make it implicit operator for assetslibrary?

            //l.style



            //c.AttachToDocument();



            // https://play.google.com/store/apps/details?id=com.abstractatech.vr
            // could we display LAN UDP notifications too. like
            // which youtube video is playing?

            Native.body.Clear();
            Native.body.style.margin = "0px";
            Native.body.style.backgroundColor = "black";

            // https://vronecontest.zeiss.com/index.php?controller=ideas&view=show&id=652

            //          hResolution: 1920,
            //vResolution: 1080,

            // "X:\jsc.svn\examples\javascript\synergy\webgl\WebGLEquirectangularPanorama\WebGLEquirectangularPanorama.sln"

            // http://oculusstreetview.eu.pn/?lat=44.301987&lng=9.211561999999958&q=3&s=false&heading=0
            // https://github.com/troffmo5/OculusStreetView

            // http://stackoverflow.com/questions/23817633/threejs-using-a-sprite-with-the-oculusrifteffect
            // http://laht.info/dk2-parameters-for-three-oculusrifteffect-js/

            // http://stemkoski.github.io/Three.js/Sprites.html
            // http://stemkoski.github.io/Three.js/Texture-Animation.html
            // http://blog.thematicmapping.org/2013/10/terrain-visualization-with-threejs-and.html

            // http://mrdoob.github.io/three.js/examples/webgl_panorama_equirectangular.html

            var window = Native.window;

            var fov = 70.0;

            var camera = new THREE.PerspectiveCamera(fov,
                1920.0 / 1080.0,
                //window.aspect,
                1, 1100);
            var target = new THREE.Vector3(0, 0, 0);

            //(camera as dynamic).target = target;

            var scene = new THREE.Scene();
            //scene.add(new THREE.AmbientLight(0xffffff));
            //scene.add(new THREE.AmbientLight(0xafafaf));

            // http://www.html5canvastutorials.com/three/html5-canvas-webgl-ambient-lighting-with-three-js/

            // http://stackoverflow.com/questions/14717135/three-js-ambient-light-unexpected-effect

            scene.add(new THREE.AmbientLight(0x2f2f2f));


            //var light = new THREE.DirectionalLight(0xffffff, 1.0);
            #region light
            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.3;
            //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 mesh = new THREE.Mesh(new THREE.SphereGeometry(500, 60, 40),
                new THREE.MeshBasicMaterial(new
                {
                    map = THREE.ImageUtils.loadTexture(
                        new _2294472375_24a3b8ef46_o().src
                        //new WebGLEquirectangularPanorama.HTML.Images.FromAssets.PANO_20130616_222058().src
                        //new WebGLEquirectangularPanorama.HTML.Images.FromAssets.PANO_20121225_210448().src

                        )
                }));
            mesh.scale.x = -1;
            scene.add(mesh);

            var labove = new NotificationLayout();

            #region sprite2 above
            {
                labove.Message.innerText = "VR CREATIVE LEADERSHIP";
                labove.layout.style.background = "";

                new { }.With(
                    async delegate
                    {
                        retry:

                        // make it blink. gaze cursor is on it?


                        labove.box.style.background = "rgba(255,255,0,0.7)";
                        labove.box.setAttribute("invoke", "onmutation1");
                        await Task.Delay(1500);

                        // is mutation observer noticing it?
                        labove.box.style.background = "rgba(255,255,255,0.7)";
                        labove.box.setAttribute("invoke", "onmutation2");
                        await Task.Delay(1500);


                        goto retry;
                    }
                );



                var c = labove.AsCanvas();

                var xcrateTexture = new THREE.Texture(c);

                // like video texture
                Native.window.onframe += delegate { xcrateTexture.needsUpdate = true; };

                var xcrateMaterial = new THREE.SpriteMaterial(
                    new
                    {
                        map = xcrateTexture,
                        useScreenCoordinates = false,
                        //color = 0xff0000
                        color = 0xffffff
                    }
            );



                var xsprite2 = new THREE.Sprite(xcrateMaterial);

                //floor
                //sprite2.position.set(0, -200, 0);

                // left
                xsprite2.position.set(200, 0, 0);

                //sprite2.position.set(0, 0, 200);

                //sprite2.position.set(-100, 0, 0);
                xsprite2.scale.set(
                   c.width * 0.5,
                   c.height * 0.5,
                    //64, 64,
                    1.0); // imageWidth, imageHeight
                scene.add(xsprite2);
            }
            #endregion




            //var lineTo = new List<THREE.Vector3>();
            var others = new
            {
                ui = default(NotificationLayout),
                canvas = default(IHTMLCanvas),

                map = default(THREE.Texture),

                sprite = default(THREE.Sprite)

            }.ToEmptyList();

            #region add
            Action<NotificationLayout> add = ui =>
            {
                ui.layout.style.background = "";

                var canvas = ui.AsCanvas();
                var index = others.Count;

                //ui.Message  += new { index };
                //ui.Message.innerText += new { index };

                //lbelow0.Message = new { THREE.REVISION }.ToString();

                // THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter is set to THREE.LinearFilter or THREE.NearestFilter. ( undefined )

                var map = new THREE.Texture(canvas);

                map.minFilter = THREE.LinearFilter;

                // like video texture

                var xcrateMaterial = new THREE.SpriteMaterial(
                    new
                    {
                        map,
                        useScreenCoordinates = false,
                        //color = 0xff0000
                        color = 0xffffff
                    }
                );



                var sprite = new THREE.Sprite(xcrateMaterial);

                //floor
                //sprite2.position.set(0, -200, 0);

                // left middle
                //sprite2.position.set(200, 0, 0);
                //sprite.position.set(250, -50, 50);
                //lineTo.Add(sprite.position);




                //sprite2.position.set(0, 0, 200);

                //sprite2.position.set(-100, 0, 0);
                sprite.scale.set(
                   canvas.width * 0.5,
                   canvas.height * 0.5,
                    //64, 64,
                    1.0); // imageWidth, imageHeight
                scene.add(sprite);

                others.Add(
                    new
                    {
                        ui,
                        canvas,
                        map,
                        sprite
                    }
                );

                var sw = Stopwatch.StartNew();

                Native.window.onframe += delegate
                {
                    // can we get some of the crazy c++ template bitmapbuffer code from the past?
                    map.needsUpdate = true;

                    var offset = Math.PI * 2 * ((double)(index + 1) / others.Count);

                    sprite.position.x = 300;

                    sprite.position.z = Math.Sin(sw.ElapsedMilliseconds * 0.00001 + offset) * 120;
                    sprite.position.y = Math.Cos(sw.ElapsedMilliseconds * 0.00001 + offset) * 120;
                };

            };
            #endregion


            add(
                new NotificationLayout
                {
                    // keep attributes around?
                    // like we do with XElement sync?
                    Icon = new HTML.Images.FromAssets._0_10122014_ECAF4B1F638429B44F4B142C2A4F38EE().With(
                        x =>
                        {
                            x.style.width = "96px";
                            x.style.height = "96px";
                        }
                    ),
                    Message = "Advanced Mechanics by Portugal Design Lab"
                }
              );

            add(
                   new NotificationLayout
                   {
                       // keep attributes around?
                       // like we do with XElement sync?
                       Icon = new HTML.Images.FromAssets._42_08122014_D2639E0AAA3E54E5F4568760AEE605EE().With(
                           x =>
                           {
                               x.style.width = "96px";
                               x.style.height = "96px";
                           }
                       ),
                       Message = "Face Value by mshariful"
                   }
                 );



            add(
                   new NotificationLayout
                   {
                       // keep attributes around?
                       // like we do with XElement sync?
                       Icon = new HTML.Images.FromAssets._371_28122014_2045510F2F7974319A9F7E9F4B39DF07().With(
                           x =>
                           {
                               x.style.width = "96px";
                               x.style.height = "96px";
                           }
                       ),
                       Message = "Mind Wall. by Sumit Goski"
                   }
                 );


            #region lines
            {
                var geometry = new THREE.Geometry
                {
                    // how can we keep streaming verticies data points to gpu?
                    vertices =

                        others.SelectMany(
                            lineTo =>
                                new[]
                                {
                                    new THREE.Vector3(200, 0, 0),
                                    lineTo.sprite.position
                                }
                        ).ToArray()

                    // https://github.com/mrdoob/three.js/wiki/Updates
                    // http://stackoverflow.com/questions/17842521/adding-geometry-to-a-three-js-mesh-after-render
                    //verticesNeedUpdate = true
                };

                Native.window.onframe += delegate { geometry.verticesNeedUpdate = true; };

                var o = new THREE.Line(geometry, new THREE.LineDashedMaterial(
                    new { color = 0x00aaff, dashSize = 1, gapSize = 0.5, linewidth = 1 }
                    ), THREE.LineStrip);

                //objects.Add(o);
                scene.add(o);
            }
            #endregion


            //          // DK2
            //          hResolution: 1920,
            //vResolution: 1080,

            var renderer = new THREE.WebGLRenderer();
            renderer.setSize(1920, 1080);

            #region HMD
            // broken?
            var distortionK = new double[] { 1.0, 0.22, 0.24, 0.0 };
            var chromaAbParameter = new double[] { 0.996, -0.004, 1.014, 0.0 };

            var HMD = new OculusRiftEffectOptions
            {
                hResolution = window.Width,
                vResolution = window.Height,

                hScreenSize = 0.12576,
                vScreenSize = 0.07074,
                interpupillaryDistance = 0.0635,
                lensSeparationDistance = 0.0635,
                eyeToScreenDistance = 0.041,

                //  j.distortionK = [0, 1.875, -71.68, 1.595, -3.218644E+26, 1.615, 0, 0];
                //distortionK = new double[] { 1.0, 0.22, 0.24, 0.0 },
                distortionK = distortionK,

                // j.chromaAbParameter = [1.609382E+22, 1.874, -5.189695E+11, -0.939, 4.463059E-29, 1.87675, 0, 0];
                //chromaAbParameter = new double[] { 0.996, -0.004, 1.014, 0.0 }
                chromaAbParameter = chromaAbParameter

            };
            #endregion


            //var effect = new THREE.OculusRiftEffect(
            //    renderer, new
            //    {
            //        worldScale = 100,

            //        //HMD
            //    }
            //    );

            //effect.setSize(1920, 1080);


            renderer.domElement.AttachToDocument();

            //renderer.domElement.style.position = IStyle.PositionEnum.absolute;
            renderer.domElement.style.SetLocation(0, 0);

            Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;

            // x:\jsc.svn\examples\javascript\synergy\comanchebysiorki\comanchebysiorki\application.cs

            new { }.With(
                     async delegate
                     {
                         retry:

                         var s = (double)Native.window.Width / 1920.0;


                         Native.document.body.style.transform = "scale(" + s + ")";
                         Native.document.body.style.transformOrigin = "0% 0%";

                         await Native.window.async.onresize;
                         goto retry;
                     }
                   );

            //#region onresize
            //Native.window.onresize +=
            //    delegate
            //    {
            //        camera.aspect = Native.window.aspect;
            //        camera.updateProjectionMatrix();

            //        renderer.setSize(window.Width, window.Height);
            //        effect.setSize(window.Width, window.Height);
            //    };
            //#endregion


            //Native.document.body.onmousewheel +=
            //    e =>
            //    {
            //        fov -= e.WheelDirection * 5.0;
            //        camera.projectionMatrix.makePerspective(fov,
            //            (double)window.Width / window.Height, 1, 1100);
            //    };

            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.document.onmousemove +=
            //  e =>
            //  {

            //      l.Message = new { e.CursorX, e.CursorY }.ToString();
            //  };


            Native.window.onframe +=
                        ee =>
                        {
                            //labove.Message = new
                            //{
                            //    lon,
                            //    lat,
                            //    ee.counter
                            //}.ToString();

                            //if (Native.document.pointerLockElement == Native.document.body)
                            //    lon += 0.00;
                            //else
                            //    lon += 0.01;

                            //lat = Math.Max(-85, Math.Min(85, lat));

                            //Native.document.title = new { lon, lat }.ToString();


                            phi = THREE.Math.degToRad(90 - lat);
                            theta = THREE.Math.degToRad(lon);

                            target.x = 500 * Math.Sin(phi) * Math.Cos(theta);
                            target.y = 500 * Math.Cos(phi);
                            target.z = 500 * Math.Sin(phi) * Math.Sin(theta);


                            //controls.update();
                            //camera.position = controls.center.clone();


                            camera.lookAt(target);
                            camera.rotation.z += camera_rotation_z;

                            renderer.render(scene, camera);

                            //effect.render(scene, camera);
                        };



            // http://blog.thematicmapping.org/2013/10/terrain-visualization-with-threejs-and.html

            // http://stackoverflow.com/questions/13278087/determine-vertical-direction-of-a-touchmove



            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; ;

                };
            // https://developer.android.com/training/system-ui/immersive.html




            //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 = null)
        {
            // 20140704 no balls shown?
            // broken?
            // view-source:http://www.mrdoob.com/lab/javascript/beachballs/
            //Action Toggle = DiagnosticsConsole.ApplicationContent.BindKeyboardToDiagnosticsConsole();


            var origin = new THREE.Vector3(0, 15, 0);
            var isMouseDown = false;



            var renderer = new THREE.WebGLRenderer(
                new
                {
                    antialias = true,
                    alpha = false
                });
            renderer.setClearColor(new THREE.Color(0x101010));

            renderer.domElement.AttachToDocument();



            // scene

            var camera = new THREE.PerspectiveCamera(
                40,
                Native.window.aspect, 1,
                1000
                );

            camera.position.x = -30;
            camera.position.y = 10;
            camera.position.z = 30;
            camera.lookAt(new THREE.Vector3(0, 10, 0));


            #region AtResize
            Action AtResize = delegate
            {
                camera.aspect = (double)Native.window.aspect;
                camera.updateProjectionMatrix();
                renderer.setSize(Native.window.Width, Native.window.Height);
            };
            Native.window.onresize +=
              delegate
              {
                  AtResize();
              };

            AtResize();
            #endregion


            var scene = new THREE.Scene();

            var light = new THREE.HemisphereLight(0xffffff, 0x606060, 1.2);
            light.position.set(-10, 10, 10);
            scene.add(light);

            {
                var geometry = new THREE.CubeGeometry(20, 20, 20);
                var material = new THREE.MeshBasicMaterial(
                    new { wireframe = true, opacity = 0.1, transparent = true });
                var mesh = new THREE.Mesh(geometry, material);
                mesh.position.y = 10;
                scene.add(mesh);
            }

            var intersectionPlane = new THREE.Mesh(new THREE.PlaneGeometry(20, 20, 8, 8));
            intersectionPlane.position.y = 10;
            intersectionPlane.visible = false;
            scene.add(intersectionPlane);

            // geometry

            var ballGeometry = new THREE.Geometry();

            var ballMaterial = new THREE.MeshPhongMaterial(

                new __MeshPhongMaterialDictionary
                {
                    vertexColors = THREE.FaceColors,
                    specular = 0x808080,
                    shininess = 2000
                }
             );

            //

            var colors = new[] {
                    new THREE.Color( 0xe52b30 ),
                    new THREE.Color( 0xe52b30 ),
                    new THREE.Color( 0x2e1b6a ),
                    new THREE.Color( 0xdac461 ),
                    new THREE.Color( 0xf07017 ),
                    new THREE.Color( 0x38b394 ),
                    new THREE.Color( 0xeaf1f7 )
                };

            var amount = colors.Length;

            var geometryTop = new THREE.SphereGeometry(1, 5 * amount, 2, 0, Math.PI * 2.0, 0, 0.30);

            for (var j = 0; j < geometryTop.faces.Length; j++)
            {

                geometryTop.faces[j].color = colors[0];

            }

            THREE.GeometryUtils.merge(ballGeometry, geometryTop);

            var geometryBottom = new THREE.SphereGeometry(1, 5 * amount, 2, 0, Math.PI * 2, Math.PI - 0.30, 0.30);

            for (var j = 0; j < geometryBottom.faces.Length; j++)
            {

                geometryBottom.faces[j].color = colors[0];

            }

            THREE.GeometryUtils.merge(ballGeometry, geometryBottom);

            {
                var sides = amount - 1;
                var size = (Math.PI * 2) / sides;

                for (var i = 0; i < sides; i++)
                {

                    var patch = new THREE.SphereGeometry(1, 5, 10, i * size, size, 0.30, Math.PI - 0.60);

                    for (var j = 0; j < patch.faces.Length; j++)
                    {

                        patch.faces[j].color = colors[i + 1];

                    }

                    THREE.GeometryUtils.merge(ballGeometry, patch);

                }

            }
            // physics

            var world = new CANNON.World();
            world.broadphase = new CANNON.NaiveBroadphase();
            world.gravity.set(0, -15, 0);
            world.solver.iterations = 7;
            world.solver.tolerance = 0.1;

            var groundShape = new CANNON.Plane();
            var groundMaterial = new CANNON.Material();
            var groundBody = new CANNON.RigidBody(0, groundShape, groundMaterial);
            groundBody.quaternion.setFromAxisAngle(new CANNON.Vec3(1, 0, 0), -Math.PI / 2.0);
            world.add(groundBody);

            var planeShapeXmin = new CANNON.Plane();
            var planeXmin = new CANNON.RigidBody(0, planeShapeXmin, groundMaterial);
            planeXmin.quaternion.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), Math.PI / 2.0);
            planeXmin.position.set(-10, 0, 0);
            world.add(planeXmin);

            var planeShapeXmax = new CANNON.Plane();
            var planeXmax = new CANNON.RigidBody(0, planeShapeXmax, groundMaterial);
            planeXmax.quaternion.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), -Math.PI / 2.0);
            planeXmax.position.set(10, 0, 0);
            world.add(planeXmax);

            var planeShapeYmin = new CANNON.Plane();
            var planeZmin = new CANNON.RigidBody(0, planeShapeYmin, groundMaterial);
            planeZmin.position.set(0, 0, -10);
            world.add(planeZmin);

            var planeShapeYmax = new CANNON.Plane();
            var planeZmax = new CANNON.RigidBody(0, planeShapeYmax, groundMaterial);
            planeZmax.quaternion.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), Math.PI);
            planeZmax.position.set(0, 0, 10);
            world.add(planeZmax);

            var ballBodyMaterial = new CANNON.Material();
            world.addContactMaterial(new CANNON.ContactMaterial(groundMaterial, ballBodyMaterial, 0.2, 0.5));
            world.addContactMaterial(new CANNON.ContactMaterial(ballBodyMaterial, ballBodyMaterial, 0.2, 0.8));



            var spheres = new Queue<THREE.Mesh>();
            var bodies = new Queue<CANNON.RigidBody>();

            Func<double> random = new Random().NextDouble;


            #region addBall
            Action<double, double, double> addBall = (x, y, z) =>
            {

                x = Math.Max(-10, Math.Min(10, x));
                y = Math.Max(5, y);
                z = Math.Max(-10, Math.Min(10, z));

                var size = 1.25;

                var sphere = new THREE.Mesh(ballGeometry, ballMaterial);
                sphere.scale.multiplyScalar(size);
                //sphere.useQuaternion = true;
                scene.add(sphere);

                spheres.Enqueue(sphere);

                var sphereShape = new CANNON.Sphere(size);
                var sphereBody = new CANNON.RigidBody(0.1, sphereShape, ballBodyMaterial);
                sphereBody.position.set(x, y, z);

                var q = new
                {
                    a = random() * 3.0,
                    b = random() * 3.0,
                    c = random() * 3.0,
                    d = random() * 3.0
                };
                Console.WriteLine("addBall " + new { x, y, z, q });

                //sphereBody.quaternion.set(q.a, q.b, q.c, q.d);
                world.add(sphereBody);

                bodies.Enqueue(sphereBody);

            };
            #endregion


            for (var i = 0; i < 100; i++)
            {

                addBall(
                   random() * 10 - 5,
                   random() * 20,
                   random() * 10 - 5
                );

            }

            //

            var projector = new THREE.Projector();
            var ray = new THREE.Raycaster();
            var mouse3D = new THREE.Vector3();

            Native.Document.body.ontouchstart +=
               e =>
               {
                   e.preventDefault();
                   isMouseDown = true;
               };


            Native.Document.body.ontouchmove +=
               e =>
               {
                   e.preventDefault();
               };

            Native.Document.body.ontouchend +=
            e =>
            {
                e.preventDefault();
                isMouseDown = false;
            };

            #region onmousemove
            Native.document.body.onmousedown +=
                e =>
                {
                    e.preventDefault();
                    isMouseDown = true;
                };
            Native.document.body.onmouseup +=
                 e =>
                 {
                     e.preventDefault();
                     isMouseDown = false;



                     if (e.MouseButton == IEvent.MouseButtonEnum.Middle)
                     {
                         if (Native.Document.pointerLockElement == Native.Document.body)
                         {
                             // cant requestFullscreen while pointerLockElement
                             Console.WriteLine("exitPointerLock");
                             Native.Document.exitPointerLock();
                             Native.Document.exitFullscreen();
                             return;
                         }

                         Console.WriteLine("requestFullscreen");
                         Native.Document.body.requestFullscreen();
                         Native.Document.body.requestPointerLock();
                         return;
                     }
                 };
            Native.document.body.onmousemove +=
               e =>
               {

                   mouse3D.set(
                       ((double)e.CursorX / (double)Native.window.Width) * 2 - 1,
                       -((double)e.CursorY / (double)Native.window.Height) * 2 + 1,
                       0.5
                   );

                   projector.unprojectVector(mouse3D, camera);

                   ray.set(camera.position, mouse3D.sub(camera.position).normalize());

                   var intersects = ray.intersectObject(intersectionPlane);

                   if (intersects.Length > 0)
                   {

                       origin.copy(intersects[0].point);

                   }
               };
            #endregion








            #region removeBall
            Action removeBall = delegate
            {

                scene.remove(spheres.Dequeue());
                world.remove(bodies.Dequeue());

            };
            #endregion




            var sw0 = Stopwatch.StartNew();
            var sw = Stopwatch.StartNew();
            //var time = Native.window.performance.now();
            //var lastTime = Native.window.performance.now();

            #region animate
            Action render =
                delegate
                {

                    var delta = sw.ElapsedMilliseconds;
                    sw.Restart();

                    //time = Native.window.performance.now();

                    camera.position.x = -Math.Cos(sw.ElapsedMilliseconds * 0.0001) * 40;
                    camera.position.z = Math.Sin(sw.ElapsedMilliseconds * 0.0001) * 40;
                    camera.lookAt(new THREE.Vector3(0, 10, 0));

                    intersectionPlane.lookAt(camera.position);

                    world.step(delta * 0.001);
                    //lastTime = time;

                    for (var i = 0; i < spheres.Count; i++)
                    {

                        var sphere = spheres.ElementAt(i);
                        var body = bodies.ElementAt(i);

                        sphere.position.copy(body.position);
                        sphere.quaternion.copy(body.quaternion);

                    }

                    renderer.render(scene, camera);

                };



            Native.window.onframe += delegate
            {


                if (isMouseDown)
                {

                    if (spheres.Count > 200)
                    {

                        removeBall();

                    }

                    addBall(
                        origin.x + (random() * 4.0 - 2),
                        origin.y + (random() * 4.0 - 2),
                        origin.z + (random() * 4.0 - 2)
                    );

                }

                render();

            };

            #endregion


        }
Example #14
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(IDefault page = null)
        {
            // used by
            // X:\jsc.svn\examples\javascript\WebGL\WebGLGoldDropletTransactions\WebGLGoldDropletTransactions\Application.cs


            if (DisableBackground)
            {
                // nop
            }
            else
            {
                //page.body.style.backgroundColor = "#4584b4";

                container.style.backgroundColor = "#4584b4";
            }

            // Bg gradient

            //var canvas = new IHTMLCanvas();
            //canvas.width = 32;
            //canvas.height = Native.Window.Height;

            //var context = (CanvasRenderingContext2D)canvas.getContext("2d");

            //var gradient = context.createLinearGradient(0, 0, 0, canvas.height);
            //gradient.addColorStop(0f, "#1e4877");
            //gradient.addColorStop(0.5f, "#4584b4");

            //context.fillStyle = gradient;
            //context.fillRect(0, 0, canvas.width, canvas.height);


            // Clouds

            //var , , renderer, sky, mesh, , material,
            //, h, color, colors = [], sprite, size, x, y, z;

            var mouseX     = 0f;
            var start_time = new IDate().getTime();

            Console.WriteLine(new { Native.window.Width, Native.window.Height });

            var windowHalfX = Native.window.Width / 2;
            var windowHalfY = Native.window.Height / 2;

            Console.WriteLine(new { DefaultMouseY });

            var mouseY = (float)((Native.window.Height * DefaultMouseY - windowHalfY) * 0.15);

            //Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;

            if (page == null)
            {
                container.AttachToDocument();
            }
            else
            {
                container.AttachTo(page.body);
            }

            container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height);
            //container.style.background = "url(" + canvas.toDataURL("image/png") + ")";

            #region Dispose
            var IsDisposed = false;

            Dispose = delegate
            {
                if (IsDisposed)
                {
                    return;
                }

                IsDisposed = true;

                container.Orphanize();
            };
            #endregion



            var camera = new THREE.PerspectiveCamera(30, Native.window.aspect, 1, 3000);
            camera.position.z = 6000;

            var scene = new THREE.Scene();

            var geometry = new THREE.Geometry();

            //var texture = THREE.ImageUtils.loadTexture(new HTML.Images.FromAssets.cloud10().src);
            var texture = THREE.ImageUtils.loadTexture(CloudTexture);

            texture.magFilter = THREE.LinearMipMapLinearFilter;
            texture.minFilter = THREE.LinearMipMapLinearFilter;

            // FogColor
            //var fog = new THREE.Fog(0x4584b4, -100, 3000);
            var fog = new THREE.Fog(FogColor, -100, 3000);


            // what about sprites?
            var material = new THREE.ShaderMaterial(

                new
            {
                uniforms = new
                {
                    map      = new { type = "t", value = texture },
                    fogColor = new { type = "c", value = fog.color },
                    fogNear  = new { type = "f", value = fog.near },
                    fogFar   = new { type = "f", value = fog.far },
                },

                vertexShader   = new GeometryVertexShader().ToString(),
                fragmentShader = new GeometryFragmentShader().ToString(),
                depthWrite     = false,
                depthTest      = false,
                transparent    = true
            }
                );

            var          r           = new Random();
            Func <float> Math_random = () => (float)r.NextDouble();

            var plane = new THREE.Mesh(new THREE.PlaneGeometry(64, 64));

            for (var i = 0; i < 8000; i++)
            {
                plane.position.x = Math_random() * 1000 - 500;
                plane.position.y = -Math_random() * Math_random() * 200 - 15;
                plane.position.z = i;
                plane.rotation.z = (f)(Math_random() * Math.PI);
                plane.scale.x    = Math_random() * Math_random() * 1.5f + 0.5f;
                plane.scale.y    = plane.scale.x;

                THREE.GeometryUtils.merge(geometry, plane);
            }

            var mesh = new THREE.Mesh(geometry, material);
            scene.add(mesh);

            mesh            = new THREE.Mesh(geometry, material);
            mesh.position.z = -8000;
            scene.add(mesh);

            var renderer = new THREE.WebGLRenderer(new { antialias = false });
            renderer.setSize(Native.window.Width, Native.window.Height);
            container.appendChild(renderer.domElement);

            container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height);

            #region onresize
            Native.window.onresize +=
                delegate
            {
                container.style.SetSize(Native.window.Width, Native.window.Height);

                camera.aspect = Native.window.aspect;
                camera.updateProjectionMatrix();

                renderer.setSize(Native.window.Width, Native.window.Height);
            };
            #endregion



            #region animate

            Native.window.onframe += delegate
            {
                if (IsDisposed)
                {
                    return;
                }

                var position = ((new IDate().getTime() - start_time) * 0.03) % 8000;


                camera.position.x += (float)((mouseX - camera.position.x) * 0.01);
                camera.position.y += (float)((-mouseY - camera.position.y) * 0.01);

                camera.position.z = (f)(-position + 8000);



                renderer.render(scene, camera);
            };

            #endregion

            Native.document.onmousemove +=
                e =>
            {
                mouseX = (float)((e.CursorX - windowHalfX) * 0.25);
                mouseY = (float)((e.CursorY - windowHalfY) * 0.15);
            };



            //var ze = new ZeProperties();

            //ze.Show();


            //ze.Add(() => renderer);
            ////ze.Add(() => controls);
            //ze.Add(() => scene);
        }
        /// <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:\jsc.svn\examples\javascript\CanvasMarchinAntsExperiment\CanvasMarchinAntsExperiment\Application.cs
			// http://mattdesl.svbtle.com/drawing-lines-is-hard

			Native.body.Clear();
            Native.body.style.margin = "0px";
            Native.body.style.overflow = IStyle.OverflowEnum.hidden;


            // http://threejs.org/examples/webgl_lines_dashed.html

            var objects = new List<THREE.Line>();

            var camera = new THREE.PerspectiveCamera(60,
                Native.window.aspect, 1, 200);
            camera.position.z = 150;

            var scene = new THREE.Scene();

            scene.fog = new THREE.Fog(0x111111, 150, 200);

            var root = new THREE.Object3D();

            var subdivisions = 6;
            var recursion = 1;

            var points = hilbert3D(new THREE.Vector3(), 25.0, recursion, 0, 1, 2, 3, 4, 5, 6, 7);

            Console.WriteLine(
                new { points.Length }
            );

            #region spline
            var spline = new THREE.Spline(points);
            var geometrySpline = new THREE.Geometry();

            for (var i = 0; i < points.Length * subdivisions; i++)
            {

                var index = (double)i / (points.Length * subdivisions);
                var position = spline.getPoint(index);

                geometrySpline.vertices[i] = new THREE.Vector3(position.x, position.y, position.z);

                Console.WriteLine(
           new { i, index, position.x, position.y, position.z }
       );

            }
            #endregion

            var geometryCube = cube(50);

            geometryCube.computeLineDistances();
            geometrySpline.computeLineDistances();

            {
                var ogeometrySpline = new THREE.Line(geometrySpline, new THREE.LineDashedMaterial(
                    new { color = 0xffffff, dashSize = 1, gapSize = 0.5 }
                    ), THREE.LineStrip);

                objects.Add(ogeometrySpline);
                scene.add(ogeometrySpline);
                ogeometrySpline.AttachTo(scene);
            }
            {

                var ogeometryCube = new THREE.Line(geometryCube, new THREE.LineDashedMaterial(
                    new { color = 0xffaa00, dashSize = 3, gapSize = 1, linewidth = 2 }
                    ), THREE.LinePieces);

                objects.Add(ogeometryCube);
                ogeometryCube.AttachTo(scene);
            }

            {
                var geometry = new THREE.Geometry
                {
                    vertices = new[] {
                        new THREE.Vector3(0, 0, 0),
                        new THREE.Vector3(100, 0, 0)
                    }
                };


                var oline = new THREE.Line(geometry, new THREE.LineDashedMaterial(
                    new { color = 0x00aaff, dashSize = 3, gapSize = 3, linewidth = 20 }
                    ), THREE.LinePieces);

                objects.Add(oline);
                //scene.add(o);
                oline.AttachTo(scene);
            }

            var renderer = new THREE.WebGLRenderer(new { antialias = true });
            renderer.setClearColor(0x111111);
            //renderer.setPixelRatio( window.devicePixelRatio );
            renderer.setSize(
                Native.window.Width,
                Native.window.Height
                );


            renderer.domElement.AttachToDocument();


            var controls = new THREE.OrbitControls(camera, renderer.domElement);

            var sw = Stopwatch.StartNew();

            Native.window.onframe +=
                delegate
                {
                    //var time = sw.ElapsedMilliseconds * 0.001;

                    //for (var i = 0; i < objects.Count; i++)
                    //{

                    //    var o = objects[i];

                    //    //object.rotation.x = 0.25 * time * ( i%2 == 1 ? 1 : -1);
                    //    o.rotation.x = 0.25 * time;
                    //    o.rotation.y = 0.25 * time;

                    //}


                    controls.update();
                    camera.position = controls.center.clone();

                    renderer.render(scene, camera);
                };



            //var ze = new ZeProperties
            //{
            //    //() => renderer
            //};

            //ze.Show();

            //ze.treeView1.Nodes.Clear();

            //ze.Add(() => renderer);
            //ze.Add(() => controls);
            //ze.Add(() => scene);

            //ze.Left = 0;

        }
        static THREE.Geometry cube(double size = 50)
        {

            var h = size * 0.5;

            var geometry = new THREE.Geometry();

            geometry.vertices = new[] {
                new THREE.Vector3(-h, -h, -h),
                new THREE.Vector3(-h, h, -h),

                new THREE.Vector3(-h, h, -h),
                new THREE.Vector3(h, h, -h),

                new THREE.Vector3(h, h, -h),
                new THREE.Vector3(h, -h, -h),

                new THREE.Vector3(h, -h, -h),
                new THREE.Vector3(-h, -h, -h),


                new THREE.Vector3(-h, -h, h),
                new THREE.Vector3(-h, h, h),

                new THREE.Vector3(-h, h, h),
                new THREE.Vector3(h, h, h),

                new THREE.Vector3(h, h, h),
                new THREE.Vector3(h, -h, h),

                new THREE.Vector3(h, -h, h),
                new THREE.Vector3(-h, -h, h),

                new THREE.Vector3(-h, -h, -h),
                new THREE.Vector3(-h, -h, h),

                new THREE.Vector3(-h, h, -h),
                new THREE.Vector3(-h, h, h),

                new THREE.Vector3(h, h, -h),
                new THREE.Vector3(h, h, h),

                new THREE.Vector3(h, -h, -h),
                new THREE.Vector3(h, -h, h)
             };

            return geometry;

        }
        /// <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)
        {
            // used by
            // X:\jsc.svn\examples\javascript\WebGL\WebGLGoldDropletTransactions\WebGLGoldDropletTransactions\Application.cs


            if (DisableBackground)
            {
                // nop
            }
            else
            {
                //page.body.style.backgroundColor = "#4584b4";

                container.style.backgroundColor = "#4584b4";
            }

            // Bg gradient

            //var canvas = new IHTMLCanvas();
            //canvas.width = 32;
            //canvas.height = Native.Window.Height;

            //var context = (CanvasRenderingContext2D)canvas.getContext("2d");

            //var gradient = context.createLinearGradient(0, 0, 0, canvas.height);
            //gradient.addColorStop(0f, "#1e4877");
            //gradient.addColorStop(0.5f, "#4584b4");

            //context.fillStyle = gradient;
            //context.fillRect(0, 0, canvas.width, canvas.height);


            // Clouds

            //var , , renderer, sky, mesh, , material,
            //, h, color, colors = [], sprite, size, x, y, z;

            var mouseX = 0f;
            var start_time = new IDate().getTime();

            Console.WriteLine(new { Native.window.Width, Native.window.Height });

            var windowHalfX = Native.window.Width / 2;
            var windowHalfY = Native.window.Height / 2;

            Console.WriteLine(new { DefaultMouseY });

            var mouseY = (float)((Native.window.Height * DefaultMouseY - windowHalfY) * 0.15);

            //Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;

            if (page == null)
            {
                container.AttachToDocument();
            }
            else
            {
                container.AttachTo(page.body);
            }

            container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height);
            //container.style.background = "url(" + canvas.toDataURL("image/png") + ")";

            #region Dispose
            var IsDisposed = false;

            Dispose = delegate
            {
                if (IsDisposed)
                    return;

                IsDisposed = true;

                container.Orphanize();
            };
            #endregion





            var camera = new THREE.PerspectiveCamera(30, Native.window.aspect, 1, 3000);
            camera.position.z = 6000;

            var scene = new THREE.Scene();

            var geometry = new THREE.Geometry();

            //var texture = THREE.ImageUtils.loadTexture(new HTML.Images.FromAssets.cloud10().src);
            var texture = THREE.ImageUtils.loadTexture(CloudTexture);

            texture.magFilter = THREE.LinearMipMapLinearFilter;
            texture.minFilter = THREE.LinearMipMapLinearFilter;

            // FogColor
            //var fog = new THREE.Fog(0x4584b4, -100, 3000);
            var fog = new THREE.Fog(FogColor, -100, 3000);


            // what about sprites?
            var material = new THREE.ShaderMaterial(

                new
                {
                    uniforms = new
                    {
                        map = new { type = "t", value = texture },
                        fogColor = new { type = "c", value = fog.color },
                        fogNear = new { type = "f", value = fog.near },
                        fogFar = new { type = "f", value = fog.far },
                    },

                    vertexShader = new GeometryVertexShader().ToString(),
                    fragmentShader = new GeometryFragmentShader().ToString(),
                    depthWrite = false,
                    depthTest = false,
                    transparent = true

                }
            );

            var r = new Random();
            Func<float> Math_random = () => (float)r.NextDouble();

            var plane = new THREE.Mesh(new THREE.PlaneGeometry(64, 64));

            for (var i = 0; i < 8000; i++)
            {

                plane.position.x = Math_random() * 1000 - 500;
                plane.position.y = -Math_random() * Math_random() * 200 - 15;
                plane.position.z = i;
                plane.rotation.z = (f)(Math_random() * Math.PI);
                plane.scale.x = Math_random() * Math_random() * 1.5f + 0.5f;
                plane.scale.y = plane.scale.x;

                THREE.GeometryUtils.merge(geometry, plane);

            }

            var mesh = new THREE.Mesh(geometry, material);
            scene.add(mesh);

            mesh = new THREE.Mesh(geometry, material);
            mesh.position.z = -8000;
            scene.add(mesh);

            var renderer = new THREE.WebGLRenderer(new { antialias = false });
            renderer.setSize(Native.window.Width, Native.window.Height);
            container.appendChild(renderer.domElement);

            container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height);

            #region onresize
            Native.window.onresize +=
                delegate
                {
                    container.style.SetSize(Native.window.Width, Native.window.Height);

                    camera.aspect = Native.window.aspect;
                    camera.updateProjectionMatrix();

                    renderer.setSize(Native.window.Width, Native.window.Height);
                };
            #endregion





            #region animate

            Native.window.onframe += delegate
            {
                if (IsDisposed)
                    return;

                var position = ((new IDate().getTime() - start_time) * 0.03) % 8000;


                camera.position.x += (float)((mouseX - camera.position.x) * 0.01);
                camera.position.y += (float)((-mouseY - camera.position.y) * 0.01);

                camera.position.z = (f)(-position + 8000);



                renderer.render(scene, camera);

            };

            #endregion

            Native.document.onmousemove +=
                e =>
                {
                    mouseX = (float)((e.CursorX - windowHalfX) * 0.25);
                    mouseY = (float)((e.CursorY - windowHalfY) * 0.15);
                };



            //var ze = new ZeProperties();

            //ze.Show();


            //ze.Add(() => renderer);
            ////ze.Add(() => controls);
            //ze.Add(() => scene);

        }
        /// <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 = null)
        {
            InitializeComponent();

            // http://johnstejskal.com/wp/super-hero-city-my-3d-webgl-game-using-three-js/
            // http://www.johnstejskal.com/dev/super-hero-city/

            //DiagnosticsConsole.ApplicationContent.BindKeyboardToDiagnosticsConsole();


            // decent simcity comes to mind
            // http://www.mrdoob.com/lab/javascript/webgl/city/01/

            //var renderer = this.renderer.renderer;

            var renderer = new THREE.WebGLRenderer(
                new { antialias = false, alpha = false }
            );

            renderer.setClearColor(new THREE.Color(0xd8e7ff));

            renderer.setSize(Native.window);

            // INodeConvertible?
            renderer.domElement.AttachToDocument();
            renderer.domElement.style.SetLocation(0, 0);

            var camera = new THREE.PerspectiveCamera(40, Native.window.aspect, 1, 3000);
            camera.position.y = 80;

            var scene = new THREE.Scene();
            scene.fog = new THREE.FogExp2(0xd0e0f0, 0.0025);


            {
                var light = new THREE.HemisphereLight(0xfffff0, 0x101020, 1.25);
                light.position.set(0.75, 1, 0.25);
                scene.add(light);
            }



            var plane = new THREE.Mesh(
                new THREE.PlaneGeometry(2000, 2000),
                new THREE.MeshBasicMaterial(new { color = 0x101018 })
            );

            plane.rotation.x = -90 * Math.PI / 180;
            scene.add(plane);







            var building_geometry = new THREE.CubeGeometry(1, 1, 1);
            building_geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0.5, 0));

            ((IArray<THREE.Face4>)(object)building_geometry.faces).splice(3, 1);

            ((IArray<object>)(object)building_geometry.faceVertexUvs[0]).splice(3, 1);

            building_geometry.faceVertexUvs[0][2][0].set(0, 0);
            building_geometry.faceVertexUvs[0][2][1].set(0, 0);
            building_geometry.faceVertexUvs[0][2][2].set(0, 0);

            // Uncaught TypeError: Cannot call method 'set' of undefined view-source:84609
            //building_geometry.faceVertexUvs[0][2][3].set(0, 0);


            Func<double> random = new Random().NextDouble;


            var building = new THREE.Mesh(building_geometry);
            var city = new THREE.Geometry();

            {
                var light = new THREE.Color(0xffffff);
                var shadow = new THREE.Color(0x303050);

                #region city
                for (var i = 0; i < 20000; i++)
                {

                    var value = 1 - random() * random();
                    var color = new THREE.Color(0).setRGB(value + random() * 0.1, value, value + random() * 0.1);

                    var top = color.clone().multiply(light);
                    var bottom = color.clone().multiply(shadow);

                    building.position.x = Math.Floor(random() * 200 - 100) * 10;
                    building.position.z = Math.Floor(random() * 200 - 100) * 10;
                    building.rotation.y = random();

                    building.scale.z = random() * random() * random() * random() * 50 + 10;
                    building.scale.x = building.scale.z;

                    building.scale.y = (random() * random() * random() * building.scale.x) * 8 + 8;

                    var geometry = building.geometry;

                    var jl = geometry.faces.Length;

                    for (var j = 0; j < jl; j++)
                    {
                        if (j == 2)
                        {
                            geometry.faces[j].vertexColors = new[] { color, color, color, color };
                        }
                        else
                        {
                            geometry.faces[j].vertexColors = new[] { top, bottom, bottom, top };
                        }
                    }

                    // THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.
                    // stop moving around code!


                    //city.merge
                    //city.merge(building.geometry);
                    // how??
                    THREE.GeometryUtils.merge(city, building);

                }
                #endregion

                #region generateTexture
                Func<IHTMLCanvas> generateTexture = delegate
                {


                    var context1 = new CanvasRenderingContext2D(32, 64);

                    context1.fillStyle = "#ffffff";
                    context1.fillRect(0, 0, 32, 64);

                    for (var y = 2; y < 64; y += 2)
                        for (var x = 0; x < 32; x += 2)
                        {

                            var value = Math.Floor(random() * 64);
                            context1.fillStyle = "rgb(" + value + "," + value + "," + value + ")";
                            context1.fillRect(x, y, 2, 1);

                        }


                    var context = new CanvasRenderingContext2D(512, 1024)
                    {
                        ImageSmoothingEnabled = false
                    };


                    context.drawImage(context1.canvas, 0, 0, context.canvas.width, context.canvas.height);

                    return context.canvas;

                };
                #endregion

                var texture = new THREE.Texture(generateTexture())
                {
                    anisotropy = renderer.getMaxAnisotropy(),
                    needsUpdate = true
                };

                var mesh = new THREE.Mesh(city, new THREE.MeshLambertMaterial(new { map = texture, vertexColors = THREE.VertexColors }));
                scene.add(mesh);
            }


            var controls = new THREE.FirstPersonControls(camera)
            {
                movementSpeed = 20,
                lookSpeed = 0.05,
                lookVertical = true
            };


            //var lastTime = Native.window.performance.now() / 1000;
            var delta = new Stopwatch();

            Native.window.onframe +=
                delegate
                {
                    //var time = Native.window.performance.now() / 1000;

                    controls.update(delta.ElapsedMilliseconds);
                    renderer.render(scene, camera);

                    //lastTime = time;
                };
        }