Exemplo n.º 1
0
    public static void GenerateSphere(int resolution, Mesh mesh, Color color)
    {
        if (cachedGeometries.ContainsKey(resolution))
        {
            cachedGeometries [resolution].SetMesh(mesh, color);
        }
        else
        {
            //Generate new sphere
            Dictionary <long, int> cachedVertIndices = new Dictionary <long, int> ();
            List <Vector3>         vertices          = GetIcosahedronVertices();
            List <Face>            faces             = GetIcosahedronFaces();

            for (int subdivision = 0; subdivision < resolution; subdivision++)
            {
                int faceCount = faces.Count;
                for (int faceIndex = 0; faceIndex < faceCount; faceIndex++)
                {
                    RefineFace(faceIndex, faces, vertices, cachedVertIndices);
                }
            }

            int[] triangles = FacesToTriangles(faces);

            Vector3[] verts = vertices.ToArray();

            SphereGeometry sphere = new SphereGeometry(triangles, verts, verts);
            sphere.SetMesh(mesh, color);

            cachedGeometries [resolution] = sphere;
        }
    }
Exemplo n.º 2
0
 internal static SphereGeometry BakeToBodySpace(
     this SphereGeometry sphere, float4x4 localToWorld, float4x4 shapeToWorld, ref EulerAngles orientation
     )
 {
     using (var geometry = new NativeArray <SphereGeometry>(1, Allocator.TempJob)
     {
         [0] = sphere
     })
         using (var outOrientation = new NativeArray <EulerAngles>(1, Allocator.TempJob)
         {
             [0] = orientation
         })
         {
             var job = new BakeSphereJob
             {
                 Sphere       = geometry,
                 Orientation  = outOrientation,
                 localToWorld = localToWorld,
                 shapeToWorld = shapeToWorld
             };
             job.Run();
             orientation = outOrientation[0];
             return(geometry[0]);
         }
 }
        public void TestSphereColliderCreateInvalid()
        {
            var sphere = new SphereGeometry
            {
                Center = new float3(-10.34f, 0.0f, -1.54f),
                Radius = 1.25f
            };

            // positive inf center
            {
                var invalidSphere = sphere;
                invalidSphere.Center = new float3(float.PositiveInfinity, 0.0f, 0.0f);
                TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere));
            }

            // negative inf center
            {
                var invalidSphere = sphere;
                invalidSphere.Center = new float3(float.NegativeInfinity, 0.0f, 0.0f);
                TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere));
            }

            // nan center
            {
                var invalidSphere = sphere;
                invalidSphere.Center = new float3(float.NaN, 0.0f, 0.0f);
                TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere));
            }

            // negative radius
            {
                var invalidSphere = sphere;
                invalidSphere.Radius = -0.5f;
                TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere));
            }

            // positive inf radius
            {
                var invalidSphere = sphere;
                invalidSphere.Radius = float.PositiveInfinity;
                TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere));
            }

            // negative inf radius
            {
                var invalidSphere = sphere;
                invalidSphere.Radius = float.NegativeInfinity;
                TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere));
            }

            // nan radius
            {
                var invalidSphere = sphere;
                invalidSphere.Radius = float.NaN;
                TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere));
            }
        }
Exemplo n.º 4
0
    void Start()
    {
        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        EntityArchetype entityArchetype = entityManager.CreateArchetype(
            typeof(LevelComponent),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld),
            typeof(RenderBounds),
            typeof(MoveSpeedComponent),
            typeof(Scale),
            typeof(PhysicsCollider)
            );
        NativeArray <Entity> entityArray = new NativeArray <Entity>(100000, Allocator.Temp);

        entityManager.CreateEntity(entityArchetype, entityArray);

        SphereGeometry sg     = new SphereGeometry();
        float          radius = 0.1f;

        sg.Radius = radius;
        sg.Center = new float3(0, 0, 0);

        for (int i = 0; i < entityArray.Length; i++)
        {
            Entity entity = entityArray[i];

            float3 position = new float3(Random.Range(-8f, 8f), Random.Range(-8f, 8f), Random.Range(-8f, 8f));

            entityManager.SetComponentData(entity, new LevelComponent {
                level = 10
            });
            entityManager.SetComponentData(entity, new MoveSpeedComponent {
                moveSpeed = Random.Range(0.1f, 0.2f)
            });
            entityManager.SetComponentData(entity, new Translation {
                Value = position
            });
            entityManager.SetComponentData(entity, new Scale {
                Value = radius
            });
            entityManager.SetSharedComponentData(entity, new RenderMesh
            {
                mesh     = mesh,
                material = material
            });


            entityManager.SetComponentData(entity, new PhysicsCollider
            {
                Value = Unity.Physics.SphereCollider.Create(sg)
            });
        }

        entityArray.Dispose();
    }
    public override void CreateScene(CompoundDemoScene sceneSettings)
    {
        //         // Floor
        //         {
        //             BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.BoxCollider.Create(new float3(0, -0.1f, 0), Quaternion.identity, new float3(10.0f, 0.1f, 10.0f), 0.05f);
        //             CreatedColliders.Add(collider);
        //             CreateStaticBody(float3.zero, quaternion.identity, collider);
        //         }

        // Dynamic compound
        {
            var box = new BoxGeometry
            {
                Center      = float3.zero,
                Orientation = quaternion.identity,
                Size        = new float3(1),
                BevelRadius = 0.05f
            };

            var sphere = new SphereGeometry
            {
                Center = float3.zero,
                Radius = 0.5f
            };

            var children = new NativeArray <CompoundCollider.ColliderBlobInstance>(3, Allocator.Temp)
            {
                [0] = new CompoundCollider.ColliderBlobInstance
                {
                    CompoundFromChild = new RigidTransform(quaternion.identity, new float3(-1, 0, 0)),
                    Collider          = Unity.Physics.BoxCollider.Create(box)
                },
                [1] = new CompoundCollider.ColliderBlobInstance
                {
                    CompoundFromChild = RigidTransform.identity,
                    Collider          = Unity.Physics.SphereCollider.Create(sphere)
                },
                [2] = new CompoundCollider.ColliderBlobInstance
                {
                    CompoundFromChild = new RigidTransform(quaternion.identity, new float3(1, 0, 0)),
                    Collider          = Unity.Physics.BoxCollider.Create(box)
                }
            };
            foreach (var child in children)
            {
                CreatedColliders.Add(child.Collider);
            }

            BlobAssetReference <Unity.Physics.Collider> collider = CompoundCollider.Create(children);
            CreatedColliders.Add(collider);
            children.Dispose();

            CreateDynamicBody(new float3(0, 1, 0), quaternion.identity, collider, float3.zero, float3.zero, 1.0f);
        }
    }
        public void GetWorldBounds()
        {
            var sphere = new SphereGeometry(5);

            var bounds = GeometryQuery.GetWorldBounds(sphere, Matrix4x4.Identity);

            // We started with a sphere of radius 5,
            // the bounding size + inflation value (3rd optional arg) results
            // in a box of size 10.1 whd
            Assert.AreEqual(new Bounds3(new Vector3(10.1f, 10.1f, 10.1f)), bounds);
        }
Exemplo n.º 7
0
    protected unsafe override void Start()
    {
        //float3 gravity = new float3(0, -9.81f, 0);
        float3 gravity = float3.zero;

        base.init(gravity);

        //         // Floor
        //         {
        //             BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.BoxCollider.Create(new float3(0, -0.1f, 0), Quaternion.identity, new float3(10.0f, 0.1f, 10.0f), 0.05f);
        //             CreateStaticBody(float3.zero, quaternion.identity, collider);
        //         }

        // Dynamic compound
        {
            var box = new BoxGeometry
            {
                Center      = float3.zero,
                Orientation = quaternion.identity,
                Size        = new float3(1),
                BevelRadius = 0.05f
            };

            var sphere = new SphereGeometry
            {
                Center = float3.zero,
                Radius = 0.5f
            };

            var children = new NativeArray <CompoundCollider.ColliderBlobInstance>(3, Allocator.Temp)
            {
                [0] = new CompoundCollider.ColliderBlobInstance
                {
                    CompoundFromChild = new RigidTransform(quaternion.identity, new float3(-1, 0, 0)),
                    Collider          = Unity.Physics.BoxCollider.Create(box)
                },
                [1] = new CompoundCollider.ColliderBlobInstance
                {
                    CompoundFromChild = RigidTransform.identity,
                    Collider          = Unity.Physics.SphereCollider.Create(sphere)
                },
                [2] = new CompoundCollider.ColliderBlobInstance
                {
                    CompoundFromChild = new RigidTransform(quaternion.identity, new float3(1, 0, 0)),
                    Collider          = Unity.Physics.BoxCollider.Create(box)
                }
            };

            BlobAssetReference <Unity.Physics.Collider> collider = CompoundCollider.Create(children);
            children.Dispose();

            CreateDynamicBody(new float3(0, 1, 0), quaternion.identity, collider, float3.zero, float3.zero, 1.0f);
        }
    }
Exemplo n.º 8
0
		public void GetWorldBounds()
		{
			var sphere = new SphereGeometry(5);

			var bounds = GeometryQuery.GetWorldBounds(sphere, Matrix.Identity);

			// We started with a sphere of radius 5,
			// the bounding size + inflation value (3rd optional arg) results
			// in a box of size 10.1 whd
			Assert.AreEqual(new Bounds3(new Vector3(10.1f, 10.1f, 10.1f)), bounds);
		}
Exemplo n.º 9
0
        public void SphereCollider_Create_WhenRadiusInvalid_Throws(
            [Values(float.PositiveInfinity, float.NegativeInfinity, float.NaN, -1f)] float value
            )
        {
            var geometry = new SphereGeometry {
                Radius = value
            };

            var ex = Assert.Throws <ArgumentException>(() => SphereCollider.Create(geometry));

            Assert.That(ex.Message, Does.Match(nameof(SphereGeometry.Radius)));
        }
Exemplo n.º 10
0
        public static PointLightHelper Create(Renderer renderer, PointLight light)
        {
            var geometry = new SphereGeometry(0.25f, 4, 3);
            var material = new MeshBasicMaterial(renderer)
            {
                UseWireframe = true,
                UseFog       = false,
                Diffuse      = light.Color.Multiply(light.Intensity)
            };
            var helper = new PointLightHelper(light, geometry, material);

            return(helper);
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        public override void Load(Control control)
        {
            base.Load(control);

            camera = new PerspectiveCamera(70, control.Width / (float)control.Height, 1, 1000);
            this.camera.Position.Z = 400;

            scene     = new Scene();
            scene.Fog = new Fog(Color.Black, 1, 1000);

            object3D = new Object3D();
            scene.Add(object3D);

            var geometry = new SphereGeometry(1, 4, 4);
            var material = new MeshPhongMaterial()
            {
                Color = Color.White, Shading = ThreeCs.Three.FlatShading
            };

            for (var i = 0; i < 100; i++)
            {
                var mesh = new Mesh(geometry, material);
                mesh.Position.set(Mat.Random() - 0.5f, Mat.Random() - 0.5f, Mat.Random() - 0.5f).Normalize();
                mesh.Position.MultiplyScalar(Mat.Random() * 400);
                mesh.Rotation.set(Mat.Random() * 2, Mat.Random() * 2, Mat.Random() * 2);
                mesh.Scale.X = mesh.Scale.Y = mesh.Scale.Z = Mat.Random() * 50;
                object3D.Add(mesh);
            }

            scene.Add(new AmbientLight((Color)colorConvertor.ConvertFromString("#222222")));

            light = new DirectionalLight(Color.White);
            light.Position.set(1, 1, 1);
            scene.Add(light);

            // postprocessing

            composer = new EffectComposer(renderer, control);
            composer.AddPass(new RenderPass(scene, camera));

            var effect1 = new ShaderPass(new DotScreenShader());

            effect1.Uniforms["scale"]["value"] = 4;
            composer.AddPass(effect1);

            var effect2 = new ShaderPass(new RGBShiftShader());

            effect2.Uniforms["amount"]["value"] = 0.0015f;
            effect2.RenderToScreen = true;
            composer.AddPass(effect2);
        }
Exemplo n.º 12
0
		private static void CreateSpheres(Scene scene, Material material)
		{
			for (int i = 0; i < 10; i++)
			{
				var rigidActor = scene.Physics.CreateRigidDynamic();

				var sphereGeom = new SphereGeometry(radius: 2);
				var boxShape = rigidActor.CreateShape(sphereGeom, material);

				rigidActor.GlobalPose = Matrix.Translation(-10, 30 + i * (sphereGeom.Radius * 2 + 0.5f), 0);
				rigidActor.SetMassAndUpdateInertia(10);

				scene.AddActor(rigidActor);
			}
		}
Exemplo n.º 13
0
        private static void CreateSpheres(Scene scene, Material material)
        {
            for (int i = 0; i < 10; i++)
            {
                var rigidActor = scene.Physics.CreateRigidDynamic();

                var sphereGeom = new SphereGeometry(radius: 2);
                var boxShape   = rigidActor.CreateShape(sphereGeom, material);

                rigidActor.GlobalPose = Matrix4x4.CreateTranslation(-10, 30 + i * (sphereGeom.Radius * 2 + 0.5f), 0);
                rigidActor.SetMassAndUpdateInertia(10);

                scene.AddActor(rigidActor);
            }
        }
Exemplo n.º 14
0
        public unsafe void RigidBodyCalculateAabb_SphereColliderTest()
        {
            var geometry = new SphereGeometry
            {
                Center = float3.zero,
                Radius = 1.0f
            };

            Physics.RigidBody rigidbodySphere = Unity.Physics.RigidBody.Zero;
            rigidbodySphere.Collider = (Collider *)SphereCollider.Create(geometry).GetUnsafePtr();

            var sphereAabb = rigidbodySphere.CalculateAabb();
            var sphere     = (Collider *)SphereCollider.Create(geometry).GetUnsafePtr();

            Assert.IsTrue(sphereAabb.Equals(sphere->CalculateAabb()));
        }
Exemplo n.º 15
0
        public void Sweep()
        {
            var sweeper  = new SphereGeometry(5);
            var obstacle = new SphereGeometry(3);

            var hit = GeometryQuery.Sweep
                      (
                new Vector3(0, 0, 1),
                100,
                sweeper,
                Matrix4x4.CreateTranslation(0, 5, 0),
                obstacle,
                Matrix4x4.CreateTranslation(0, 5, 10)
                      );

            Assert.IsNotNull(hit);
            Assert.AreEqual(2.0f, hit.Distance);
        }
Exemplo n.º 16
0
		public void Sweep()
		{
			var sweeper = new SphereGeometry(5);
			var obstacle = new SphereGeometry(3);

			var hit = GeometryQuery.Sweep
			(
				new Vector3(0, 0, 1),
				100,
				sweeper,
				Matrix.Translation(0, 5, 0),
				obstacle,
				Matrix.Translation(0, 5, 10)
			);

			Assert.IsNotNull(hit);
			Assert.AreEqual(2.0f, hit.Distance);
		}
        unsafe public void TestSphereColliderCreate()
        {
            var sphere = new SphereGeometry
            {
                Center = new float3(-8.45f, 9.65f, -0.10f),
                Radius = 0.98f
            };

            var collider       = SphereCollider.Create(sphere);
            var sphereCollider = UnsafeUtilityEx.AsRef <SphereCollider>(collider.GetUnsafePtr());

            TestUtils.AreEqual(sphere.Center, sphereCollider.Center, 1e-3f);
            TestUtils.AreEqual(sphere.Center, sphereCollider.Geometry.Center, 1e-3f);
            TestUtils.AreEqual(sphere.Radius, sphereCollider.Radius, 1e-3f);
            TestUtils.AreEqual(sphere.Radius, sphereCollider.Geometry.Radius, 1e-3f);
            Assert.AreEqual(ColliderType.Sphere, sphereCollider.Type);
            Assert.AreEqual(CollisionType.Convex, sphereCollider.CollisionType);
        }
Exemplo n.º 18
0
            public void Execute()
            {
                var center      = Sphere[0].Center;
                var radius      = Sphere[0].Radius;
                var orientation = Orientation[0];

                var basisToWorld  = GetBasisToWorldMatrix(localToWorld, center, orientation, 1f);
                var basisPriority = basisToWorld.HasShear() ? GetBasisAxisPriority(basisToWorld) : k_DefaultAxisPriority;
                var bakeToShape   = GetPrimitiveBakeToShapeMatrix(localToWorld, shapeToWorld, ref center, ref orientation, 1f, basisPriority);

                radius *= math.cmax(bakeToShape.DecomposeScale());

                Sphere[0] = new SphereGeometry
                {
                    Center = center,
                    Radius = radius
                };
                Orientation[0] = orientation;
            }
Exemplo n.º 19
0
    public unsafe static NativeArray <Entity> GetNearbyObjects(Entity e, float3 translation, quaternion rotation, PhysicsCollider physicsCollider, BuildPhysicsWorld physicsWorldSystem)
    {
        CollisionWorld       world = physicsWorldSystem.PhysicsWorld.CollisionWorld;;
        NativeArray <Entity> context;
        var filter = new CollisionFilter()
        {
            BelongsTo    = ~0u,
            CollidesWith = ~0u, // all 1s, so all layers, collide with everything
            GroupIndex   = 0
        };

        SphereGeometry sphereGeometry = new SphereGeometry()
        {
            Center = float3.zero, Radius = 3f
        };
        BlobAssetReference <Collider> sphereCollider = SphereCollider.Create(sphereGeometry, filter);
        NativeList <ColliderCastHit>  colliderHit    = new NativeList <ColliderCastHit>();
        ColliderCastInput             input          = new ColliderCastInput()
        {
            Collider    = (Collider *)sphereCollider.GetUnsafePtr(),
            Orientation = quaternion.identity,
            Start       = translation,
            End         = translation
        };

        if (world.CastCollider(input, ref colliderHit))
        {
            int compteur = 0;
            context = new NativeArray <Entity>(colliderHit.Length, Allocator.Temp);
            foreach (var collider in colliderHit)
            {
                context[compteur] = collider.Entity;
                compteur++;
            }
            Debug.Log(context.Length);
        }
        else
        {
            context = new NativeArray <Entity>(0, Allocator.Temp);
            Debug.Log("inhere");
        }
        return(context);
    }
Exemplo n.º 20
0
    public unsafe Entity SphereCast(float3 RayFrom, float3 RayTo, float radius)
    {
        var physicsWorldSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem <Unity.Physics.Systems.BuildPhysicsWorld>();
        var collisionWorld     = physicsWorldSystem.PhysicsWorld.CollisionWorld;

        var filter = new CollisionFilter()
        {
            BelongsTo    = ~0u,
            CollidesWith = ~0u, // all 1s, so all layers, collide with everything
            GroupIndex   = 0
        };

        SphereGeometry sphereGeometry = new SphereGeometry()
        {
            Center = float3.zero, Radius = radius
        };
        BlobAssetReference <Unity.Physics.Collider> sphereCollider = Unity.Physics.SphereCollider.Create(sphereGeometry, filter);

        ColliderCastInput input = new ColliderCastInput()
        {
            Collider    = (Unity.Physics.Collider *)sphereCollider.GetUnsafePtr(),
            Orientation = quaternion.identity,
            Start       = RayFrom,
            End         = RayTo
        };

        ColliderCastHit hit     = new ColliderCastHit();
        bool            haveHit = collisionWorld.CastCollider(input, out hit);

        if (haveHit)
        {
            // see hit.Position
            // see hit.SurfaceNormal
            Entity e = physicsWorldSystem.PhysicsWorld.Bodies[hit.RigidBodyIndex].Entity;
            return(e);
        }

        sphereCollider.Dispose();

        return(Entity.Null);
    }
Exemplo n.º 21
0
		private void ShootSphere()
		{
			const float force = 5000;

			var cameraPos = Camera.Position.AsPhysX();
			var cameraDir = Camera.Direction.AsPhysX();

			var material = this.Scene.Physics.CreateMaterial(0.1f, 0.5f, 0.5f);

			var rigidActor = this.Scene.Physics.CreateRigidDynamic();

			var sphereGeom = new SphereGeometry(2);
			var boxShape = rigidActor.CreateShape(sphereGeom, material);

			rigidActor.GlobalPose = PhysX.Math.Matrix.Translation(cameraPos);
			rigidActor.SetMassAndUpdateInertia(100);

			this.Scene.AddActor(rigidActor);

			rigidActor.AddForceAtLocalPosition(cameraDir * force, new Math.Vector3(0, 0, 0), ForceMode.Impulse, true);
		}
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        public override void Load(Control control)
        {
            base.Load(control);

            this.camera = new PerspectiveCamera(75, control.Width / (float)control.Height, 1, 1100);
            this.target = new Vector3(0, 0, 0);

            this.scene = new Scene();

            var geometry = new SphereGeometry(500, 60, 40);

            geometry.ApplyMatrix(new Matrix4().MakeScale(-1, 1, 1));

            var material = new MeshBasicMaterial {
                Map = ImageUtils.LoadTexture(@"examples/textures/2294472375_24a3b8ef46_o.jpg")
            };

            this.mesh = new Mesh(geometry, material);

            this.scene.Add(mesh);
        }
Exemplo n.º 23
0
        private void ShootSphere()
        {
            const float force = 5000;

            var cameraPos = Camera.Position.AsPhysX();
            var cameraDir = Camera.Direction.AsPhysX();

            var material = this.Scene.Physics.CreateMaterial(0.1f, 0.5f, 0.5f);

            var rigidActor = this.Scene.Physics.CreateRigidDynamic();

            var sphereGeom = new SphereGeometry(2);
            var boxShape   = RigidActorExt.CreateExclusiveShape(rigidActor, sphereGeom, material, null);

            rigidActor.GlobalPose = Matrix4x4.CreateTranslation(cameraPos);
            rigidActor.SetMassAndUpdateInertia(100);

            this.Scene.AddActor(rigidActor);

            rigidActor.AddForceAtLocalPosition(cameraDir * force, new System.Numerics.Vector3(0, 0, 0), ForceMode.Impulse, true);
        }
Exemplo n.º 24
0
    protected unsafe override void OnUpdate()
    {
        float          time       = Time.DeltaTime;
        float          dirForward = Input.GetAxis("Vertical");
        float          dirAngle   = Input.GetAxis("Horizontal");
        CollisionWorld world      = physicsWorldSystem.PhysicsWorld.CollisionWorld;

        Entities.ForEach((Entity e, ref PhysicsVelocity physicsVelocity, ref Rotation rotation, ref Translation translation, ref PhysicsCollider physicsCollider) =>
        {
            var filter = new CollisionFilter()
            {
                BelongsTo    = ~0u,
                CollidesWith = ~0u, // all 1s, so all layers, collide with everything
                GroupIndex   = 0
            };

            SphereGeometry sphereGeometry = new SphereGeometry()
            {
                Center = translation.Value, Radius = 10f
            };
            BlobAssetReference <Collider> sphereCollider = SphereCollider.Create(sphereGeometry, filter);
            NativeList <ColliderCastHit> colliderHit     = new NativeList <ColliderCastHit>(Allocator.Temp);
            ColliderCastInput input = new ColliderCastInput()
            {
                Collider    = (Collider *)sphereCollider.GetUnsafePtr(),
                Orientation = quaternion.identity,
                Start       = translation.Value,
                End         = translation.Value
            };
            world.CastCollider(input, ref colliderHit);
            //for (int i = 0; i < colliderHit.Length; i++)
            //{
            //Debug.Log(colliderHit[i].Entity + " / " + e.Index);
            //}
            //Debug.Log(colliderHit.Length);
            colliderHit.Dispose();
            //NativeArray<Entity> context = GetNearbyObjects(e, translation.Value, rotation.Value, physicsCollider, test);
            //context.Dispose();
        }).ScheduleParallel();
    }
Exemplo n.º 25
0
        public override void Render()
        {
            var widthSegments = (int)(Mat.Random() * 64);

            if (widthSegments <= 0)
            {
                widthSegments = 1;
            }
            var heightSegments = (int)(Mat.Random() * 32);

            if (heightSegments <= 0)
            {
                heightSegments = 1;
            }

            var geometry = new SphereGeometry(50, widthSegments, heightSegments);

            var texture = ImageUtils.LoadTexture(@"examples/textures/crate.gif");

            texture.NeedsUpdate = true;

            var material = new MeshBasicMaterial()
            {
                Map = texture, Wireframe = true
            };

            var mesh = new Mesh(geometry, material);

            scene.Add(mesh);

            renderer.Render(scene, camera);

            scene.Remove(mesh);

            // clean up

            geometry.Dispose();
            material.Dispose();
            texture.Dispose();
        }
Exemplo n.º 26
0
        protected override void OnCreate()
        {
            this.buildPhysicsWorldSystem = World.GetOrCreateSystem <BuildPhysicsWorld>();
            this.stepPhysicsWorldSystem  = World.GetOrCreateSystem <StepPhysicsWorld>();
            //this.ImpulseGroup = GetEntityQuery( new EntityQueryDesc
            //{
            //    All = new ComponentType[] { typeof( MoveChData ), }
            //} );

            var geom = new SphereGeometry()
            {
                Center = float3.zero,
                Radius = 0.15f,
            };
            var filter = new CollisionFilter
            {
                BelongsTo        = 1u << 23,
                    CollidesWith = 1u << 20 | 1u << 22,// | 1u<<23,
                    GroupIndex   = 0,
            };

            this.movebodySphereCollider = SphereCollider.Create(geom, filter);
        }
Exemplo n.º 27
0
    protected unsafe override void OnUpdate()
    {
        var _physicsWorldSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem <Unity.Physics.Systems.BuildPhysicsWorld>();
        var _collisionWorld     = _physicsWorldSystem.PhysicsWorld.CollisionWorld;

        var _ecb = m_EntityCommandBufferSystem.CreateCommandBuffer();

        var _filter = new CollisionFilter()
        {
            BelongsTo    = ~0u,
            CollidesWith = ~0u, // all 1s, so all layers, collide with everything
            GroupIndex   = 0
        };

        SphereGeometry sphereGeometry = new SphereGeometry()
        {
            Center = float3.zero, Radius = 100
        };
        BlobAssetReference <Unity.Physics.Collider> sphereCollider = Unity.Physics.SphereCollider.Create(sphereGeometry, _filter);

        /*Vector3
         * Unity.Physics.ColliderCastInput input = new Unity.Physics.ColliderCastInput()
         * {
         *  Collider = (Unity.Physics.Collider*)sphereCollider.GetUnsafePtr(),
         *  Orientation = quaternion.identity,
         *  Start = RayFrom,
         *  End = RayTo
         * };*/

        /*Entities.
         *  ForEach((ref Translation _translation, in Entity _entity) =>
         *  {
         *      _ecb.AddComponent(_entity, new UnitSelected());
         *
         *  }).Schedule();*/
    }
    /// <summary>
    /// Generates a collider using a PhysicsShapeAuthoring and PhysicsMaterialsExtensionComponent
    /// </summary>
    /// <param name="shape"></param>
    /// <param name="shapeExt"></param>
    /// <param name="offsetPosition"></param>
    /// <param name="offsetRotation"></param>
    /// <returns></returns>
    BlobAssetReference <Unity.Physics.Collider> GenerateCollider(PhysicsShapeAuthoring shape, PhysicsMaterialsExtensionComponent shapeExt, out float3 offsetPosition, out quaternion offsetRotation)
    {
        CollisionFilter filter = new CollisionFilter
        {
            CollidesWith = shape.CollidesWith.Value,
            BelongsTo    = shape.BelongsTo.Value,
            GroupIndex   = 0
        };

        Unity.Physics.Material material = new Unity.Physics.Material
        {
            CollisionResponse        = shape.CollisionResponse,
            CustomTags               = shape.CustomTags.Value,
            Friction                 = shape.Friction.Value,
            FrictionCombinePolicy    = shape.Friction.CombineMode,
            Restitution              = shape.Restitution.Value,
            RestitutionCombinePolicy = shape.Restitution.CombineMode,
            EnableMassFactors        = shapeExt != null ? shapeExt.EnableMassFactors : false,
            EnableSurfaceVelocity    = shapeExt != null ? shapeExt.EnableSurfaceVelocity : false
        };
        switch (shape.ShapeType)
        {
        case ShapeType.Box:
            var boxProperties = shape.GetBoxProperties();
            offsetPosition = boxProperties.Center;
            offsetRotation = boxProperties.Orientation;
            return(Unity.Physics.BoxCollider.Create(boxProperties, filter, material));

        case ShapeType.Capsule:
            var capsuleProperties = shape.GetCapsuleProperties();
            var capsuleGeometry   = new CapsuleGeometry
            {
                Radius  = capsuleProperties.Radius,
                Vertex0 = capsuleProperties.Center - capsuleProperties.Height / 2 - capsuleProperties.Radius,
                Vertex1 = capsuleProperties.Center + capsuleProperties.Height / 2 - capsuleProperties.Radius
            };
            offsetPosition = capsuleProperties.Center;
            offsetRotation = capsuleProperties.Orientation;
            return(Unity.Physics.CapsuleCollider.Create(capsuleGeometry, filter, material));

        case ShapeType.Cylinder:
            var cylinderProperties = shape.GetCylinderProperties();
            offsetPosition = cylinderProperties.Center;
            offsetRotation = cylinderProperties.Orientation;
            return(CylinderCollider.Create(cylinderProperties, filter, material));

        case ShapeType.Sphere:
            var sphereProperties = shape.GetSphereProperties(out var orientation);
            var SphereGeometry   = new SphereGeometry
            {
                Center = sphereProperties.Center,
                Radius = sphereProperties.Radius
            };
            offsetPosition = sphereProperties.Center;
            offsetRotation = quaternion.identity;
            return(Unity.Physics.SphereCollider.Create(SphereGeometry, filter, material));

        case ShapeType.ConvexHull:
            NativeList <float3> points = new NativeList <float3>(Allocator.Temp);
            shape.GetConvexHullProperties(points);
            var ConvexCollider = Unity.Physics.ConvexCollider.Create(points, shape.ConvexHullGenerationParameters, filter, material);
            //    points.Dispose();
            offsetPosition = float3.zero;
            offsetRotation = quaternion.identity;
            return(ConvexCollider);

        case ShapeType.Mesh:
            NativeList <float3> verts = new NativeList <float3>(Allocator.Temp);
            NativeList <int3>   tris  = new NativeList <int3>(Allocator.Temp);
            shape.GetMeshProperties(verts, tris);
            offsetPosition = float3.zero;
            offsetRotation = quaternion.identity;
            return(Unity.Physics.MeshCollider.Create(verts, tris, filter, material));

        default:
            UnityEngine.Debug.LogWarning("GenerateCollider:: cannot generate collider for shapetype \"" + shape.ShapeType + "\"");
            offsetPosition = float3.zero;
            offsetRotation = quaternion.identity;
            return(new BlobAssetReference <Unity.Physics.Collider>());
        }
    }
Exemplo n.º 29
0
    BlobAssetReference <Unity.Physics.Collider> GenerateCollider(PhysicsShapeAuthoring shape, out float3 offsetPosition, out quaternion offsetRotation)
    {
        switch (shape.ShapeType)
        {
        case ShapeType.Box:
            var boxProperties = shape.GetBoxProperties();
            offsetPosition = boxProperties.Center;
            offsetRotation = boxProperties.Orientation;
            return(Unity.Physics.BoxCollider.Create(boxProperties));

        case ShapeType.Capsule:
            var capsuleProperties = shape.GetCapsuleProperties();
            var capsuleGeometry   = new CapsuleGeometry
            {
                Radius  = capsuleProperties.Radius,
                Vertex0 = capsuleProperties.Center - capsuleProperties.Height / 2 - capsuleProperties.Radius,
                Vertex1 = capsuleProperties.Center + capsuleProperties.Height / 2 - capsuleProperties.Radius
            };
            offsetPosition = capsuleProperties.Center;
            offsetRotation = capsuleProperties.Orientation;
            return(Unity.Physics.CapsuleCollider.Create(capsuleGeometry));

        case ShapeType.Cylinder:
            var cylinderProperties = shape.GetCylinderProperties();
            offsetPosition = cylinderProperties.Center;
            offsetRotation = cylinderProperties.Orientation;
            return(CylinderCollider.Create(cylinderProperties));

        case ShapeType.Sphere:
            var sphereProperties = shape.GetSphereProperties(out var orientation);
            var SphereGeometry   = new SphereGeometry
            {
                Center = sphereProperties.Center,
                Radius = sphereProperties.Radius
            };
            offsetPosition = sphereProperties.Center;
            offsetRotation = quaternion.identity;
            return(Unity.Physics.SphereCollider.Create(SphereGeometry));

        case ShapeType.ConvexHull:
            NativeList <float3> points = new NativeList <float3>(Allocator.Temp);
            shape.GetConvexHullProperties(points);
            var ConvexCollider = Unity.Physics.ConvexCollider.Create(points, shape.ConvexHullGenerationParameters);
            //    points.Dispose();
            offsetPosition = float3.zero;
            offsetRotation = quaternion.identity;
            return(ConvexCollider);

        case ShapeType.Mesh:
            NativeList <float3> verts = new NativeList <float3>(Allocator.Temp);
            NativeList <int3>   tris  = new NativeList <int3>(Allocator.Temp);
            shape.GetMeshProperties(verts, tris);
            offsetPosition = float3.zero;
            offsetRotation = quaternion.identity;
            return(Unity.Physics.MeshCollider.Create(verts, tris));

        default:
            UnityEngine.Debug.LogWarning("GenerateCollider:: cannot generate collider for shapetype \"" + shape.ShapeType + "\"");
            offsetPosition = float3.zero;
            offsetRotation = quaternion.identity;
            return(new BlobAssetReference <Unity.Physics.Collider>());
        }
    }
Exemplo n.º 30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        public override void Load(Control control)
        {
            base.Load(control);

            camera = new PerspectiveCamera(60, control.Width / (float)control.Height, 1, 10000);
            this.camera.Position.Z = 100;

            this.cameraRtt            = new OrthographicCamera(control.Width / -2, control.Width / 2, control.Height / 2, control.Height / -2, -10000, 10000);
            this.cameraRtt.Position.Z = 100;

            scene         = new Scene();
            this.sceneRtt = new Scene();
            sceneScreen   = new Scene();

            var light = new DirectionalLight(Color.White);

            light.Position.set(0, 0, 1).Normalize();
            this.sceneRtt.Add(light);

            light = new DirectionalLight((Color)colorConvertor.ConvertFromString("#ffaaaa"), 1.5f);
            light.Position.set(0, 0, -1).Normalize();
            this.sceneRtt.Add(light);

            rtTexture = new WebGLRenderTarget(control.Width, control.Height)
            {
                MinFilter = ThreeCs.Three.LinearFilter, MagFilter = ThreeCs.Three.NearestFilter, Format = ThreeCs.Three.RGBFormat
            };

            material = new ShaderMaterial()
            {
                Uniforms = new Uniforms {
                    { "time", new Uniform()
                      {
                          { "type", "f" }, { "value", 0.0f }
                      } }
                },
                VertexShader   = VertexShader,
                FragmentShader = FragmentShaderPass1,
            };

            materialScreen = new ShaderMaterial()
            {
                Uniforms = new Uniforms {
                    { "tDiffuse", new Uniform()
                      {
                          { "type", "t" }, { "value", rtTexture }
                      } }
                },
                VertexShader   = VertexShader,
                FragmentShader = FragmentShaderScreen,
            };

            var plane = new PlaneBufferGeometry(control.Width, control.Height);

            quad            = new Mesh(plane, material);
            quad.Position.Z = -100;
            this.sceneRtt.Add(quad);

            var geometry = new TorusGeometry(100, 25, 15, 30);

            var mat1 = new MeshPhongMaterial()
            {
                Color = (Color)colorConvertor.ConvertFromString("#555555"), Specular = (Color)colorConvertor.ConvertFromString("#ffaa00"), Shininess = 5
            };
            var mat2 = new MeshPhongMaterial()
            {
                Color = (Color)colorConvertor.ConvertFromString("#550000"), Specular = (Color)colorConvertor.ConvertFromString("#ff2200"), Shininess = 5
            };

            zmesh1 = new Mesh(geometry, mat1);
            zmesh1.Position.set(0, 0, 100);
            zmesh1.Scale.set(1.5f, 1.5f, 1.5f);
            this.sceneRtt.Add(zmesh1);

            zmesh2 = new Mesh(geometry, mat2);
            zmesh2.Position.set(0, 150, 100);
            zmesh2.Scale.set(0.75f, 0.75f, 0.75f);
            this.sceneRtt.Add(zmesh2);

            quad            = new Mesh(plane, materialScreen);
            quad.Position.Z = -100;
            sceneScreen.Add(quad);

            //
            var geometry3 = new SphereGeometry(10, 64, 32);
            var material2 = new MeshBasicMaterial()
            {
                Color = Color.White                                                  /*, Map = rtTexture*/
            };

            int n = 5;

            for (var j = 0; j < n; j++)
            {
                for (var i = 0; i < n; i++)
                {
                    var mesh = new Mesh(geometry3, material2);

                    mesh.Position.X = (i - (n - 1) / 2) * 20;
                    mesh.Position.Y = (j - (n - 1) / 2) * 20;
                    mesh.Position.Z = 0;

                    mesh.Rotation.Y = (float)-Math.PI / 2.0f;

                    scene.Add(mesh);
                }
            }

            renderer.AutoClear = false;
        }
Exemplo n.º 31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        public override void Load(Control control)
        {
            base.Load(control);

            camera = new PerspectiveCamera(40, control.Width / (float)control.Height, 1, 2000);
            this.camera.Position.Z = 800;

            scene = new Scene();

            const int Size = 150;

            var geometryLines = new BoxGeometry(Size, Size, Size);
            var geometryTris  = new BoxGeometry(Size, Size, Size);

            // wireframe using gl.LINES

            var materialLines = new MeshBasicMaterial()
            {
                Wireframe = true
            };

            meshLines            = new Mesh(geometryLines, materialLines);
            meshLines.Position.X = -150;
            scene.Add(meshLines);

            // wireframe using gl.TRIANGLES (interpreted as triangles)

            var attributesTris = new Attributes
            {
                { "center", new Attribute {
                      { "type", "v3" }, { "value", new List <List <Vector3> >() }, { "boundTo", "faceVertices" },
                  } }
            };

            SetupAttributes(geometryTris, (List <List <Vector3> >)(attributesTris["center"])["value"]);

            var materialTris = new ShaderMaterial()
            {
                Attributes = attributesTris, VertexShader = VertexShader, FragmentShader = FragmentShader
            };

            meshTris            = new Mesh(geometryTris, materialTris);
            meshTris.Position.X = 150;
            scene.Add(meshTris);

            // wireframe using gl.TRIANGLES (mixed triangles and quads)

            var mixedGeometry = new SphereGeometry(Size / 2, 32, 16);

            var attributesMixed = new Attributes
            {
                { "center", new Attribute {
                      { "type", "v3" }, { "value", new List <List <Vector3> >() }, { "boundTo", "faceVertices" },
                  } }
            };

            SetupAttributes(mixedGeometry, (List <List <Vector3> >)attributesMixed["center"]["value"]);

            var materialMixed = new ShaderMaterial()
            {
                Attributes     = attributesMixed,
                VertexShader   = VertexShader,
                FragmentShader = FragmentShader
            };

            meshMixed            = new Mesh(mixedGeometry, materialMixed);
            meshMixed.Position.X = -150;
            scene.Add(meshMixed);
        }
Exemplo n.º 32
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        public override void Load(Control control)
        {
            base.Load(control);

            camera = new PerspectiveCamera(70, control.Width / (float)control.Height, 1, 10000);

            scene = new Scene();

            var sphereGeometry = new SphereGeometry(5);
            var material       = new MeshBasicMaterial()
            {
                Color = Color.Red
            };

            sphereInter         = new Mesh(sphereGeometry, material);
            sphereInter.Visible = false;
            scene.Add(sphereInter);

            var geometry = new Geometry();

            var point     = new Vector3();
            var direction = new Vector3();

            for (var i = 0; i < 100; i++)
            {
                direction.X += Mat.Random() - 0.5f;
                direction.Y += Mat.Random() - 0.5f;
                direction.Z += Mat.Random() - 0.5f;
                direction.Normalize().MultiplyScalar(5);

                point.Add(direction);

                geometry.Vertices.Add((Vector3)point.Clone());
            }

            parentTransform            = new Object3D();
            parentTransform.Position.X = Mat.Random() * 40 - 20;
            parentTransform.Position.Y = Mat.Random() * 40 - 20;
            parentTransform.Position.Z = Mat.Random() * 40 - 20;

            parentTransform.Rotation.X = Mat.Random() * 2 * (float)Math.PI;
            parentTransform.Rotation.Y = Mat.Random() * 2 * (float)Math.PI;
            parentTransform.Rotation.Z = Mat.Random() * 2 * (float)Math.PI;

            parentTransform.Scale.X = Mat.Random() + 0.5f;
            parentTransform.Scale.Y = Mat.Random() + 0.5f;
            parentTransform.Scale.Z = Mat.Random() + 0.5f;

            for (var i = 0; i < 50; i++)
            {
                var type     = Mat.Random() > 0.5f ? Three.LineStrip : Three.LinePieces;
                var object3D = new Line(geometry, new LineBasicMaterial()
                {
                    Color = new Color().Random()
                }, type);

                object3D.Position.X = Mat.Random() * 400 - 200;
                object3D.Position.Y = Mat.Random() * 400 - 200;
                object3D.Position.Z = Mat.Random() * 400 - 200;

                object3D.Rotation.X = Mat.Random() * 2 * (float)Math.PI;
                object3D.Rotation.Y = Mat.Random() * 2 * (float)Math.PI;
                object3D.Rotation.Z = Mat.Random() * 2 * (float)Math.PI;

                object3D.Scale.X = Mat.Random() + 0.5f;
                object3D.Scale.Y = Mat.Random() + 0.5f;
                object3D.Scale.Z = Mat.Random() + 0.5f;

                parentTransform.Add(object3D);
            }

            scene.Add(parentTransform);

            raycaster = new Raycaster();
            raycaster.LinePrecision = 3;

            renderer.SetClearColor((Color)colorConvertor.ConvertFromString("#f0f0f0"));
        }
Exemplo n.º 33
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        public override void Load(Control control)
        {
            base.Load(control);

            camera = new PerspectiveCamera(30, control.Width / (float)control.Height, 1, 10000);
            this.camera.Position.Z = 300;

            scene = new Scene();

            attributes = new Attributes
            {
                { "displacement", new ThreeCs.Renderers.Shaders.Attribute()
                  {
                      { "type", "f" }, { "value", new float[0] }
                  } }
            };

            uniforms = new Uniforms
            {
                { "amplitude", new Uniform()
                  {
                      { "type", "f" }, { "value", 1.0f }
                  } },
                { "color", new Uniform()
                  {
                      { "type", "c" }, { "value", (Color)colorConvertor.ConvertFromString("#ff2200") }
                  } },
                { "texture", new Uniform()
                  {
                      { "type", "t" }, { "value", ImageUtils.LoadTexture(@"examples\textures/water.jpg") }
                  } },
            };

            var texture = uniforms["texture"]["value"] as Texture;

            texture.WrapS = texture.WrapT = ThreeCs.Three.RepeatWrapping;

            var shaderMaterial = new ShaderMaterial
            {
                Uniforms       = uniforms,
                Attributes     = attributes,
                VertexShader   = VertexShader,
                FragmentShader = FragmentShader,
            };

            const float Radius = 50.0f; const int Segments = 128; const int Rings = 64;
            var         geometry = new SphereGeometry(Radius, Segments, Rings);

            geometry.Dynamic = true;

            sphere = new Mesh(geometry, shaderMaterial);

            var vertices = geometry.Vertices;

            attributes["displacement"]["value"] = new float[vertices.Count];
            var values = (float[])attributes["displacement"]["value"];

            noise = new float[vertices.Count];

            for (var v = 0; v < vertices.Count; v++)
            {
                values[v] = 0;
                noise[v]  = Mat.Random() * 5;
            }

            scene.Add(sphere);

            renderer.SetClearColor((Color)colorConvertor.ConvertFromString("#050505"));
        }
Exemplo n.º 34
0
        static void Main(string[] args)
        {
            var scene = new Scene
            {
                Background = new  Color(255, 0, 255).ToInt(),
                Name       = "My Scene"
            };

            var verts = new List <float[]>
            {
                new float[] { 0, 0, 0 },
                new float[] { 0, 0, 10.1234f },
                new float[] { 10, 0, 10 },
                new float[] { 10, 0, 0 }
            };

            var norms = new List <float[]>
            {
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 },
                new float[] { 0, 1, 0 }
            };

            var vertices = Geometry.ProcessVertexArray(verts);

            var normals = Geometry.ProcessNormalArray(norms);

            var face = new int[] { 0, 1, 2, 3 };

            var faces = Geometry.ProcessFaceArray(new List <int[]> {
                { face }
            }, false, false);

            var geometry  = new Geometry(vertices, faces, normals);
            var geometry2 = new Geometry(vertices, faces, normals);
            var material  = MeshStandardMaterial.Default();

            var mesh = new Mesh
            {
                Geometry = geometry,
                Material = material,
                Name     = "My Mesh"
            };

            scene.Add(mesh);

            var material2 = MeshStandardMaterial.Default();

            material2.Roughness = 0.25;

            var mesh2 = new Mesh
            {
                Geometry = geometry,
                Material = material2,
                Position = new Vector3(20, 20, 20),
                Name     = "My Mesh2"
            };

            scene.Add(mesh2);

            var material3 = MeshStandardMaterial.Default();

            var mesh3 = new Mesh
            {
                Geometry = geometry2,
                Material = material3,
                Position = new Vector3(30, 30, 30),
                Name     = "My Mesh3"
            };

            scene.Add(mesh3);

            var line = new Line
            {
                Geometry = new Geometry(vertices),
                Material = new LineBasicMaterial {
                    Color = new Color(255, 0, 0).ToInt(), LineWidth = 20
                },
                Name = "My Curves"
            };

            scene.Add(line);

            var points = new Points
            {
                Geometry = new Geometry(vertices),
                Material = new PointsMaterial {
                    Color = new Color(255, 255, 255).ToInt()
                },
                Name = "My Points"
            };

            scene.Add(points);

            var group = new Group();

            group.Add(mesh3);
            group.Add(mesh2);
            group.Add(mesh);

            scene.Add(group);

            var group2 = new Group();

            group2.Add(mesh3);
            group2.Add(mesh2);
            group2.Add(mesh);

            scene.Add(group2);

            var sphereGeometry = new SphereGeometry
            {
                Radius         = 10,
                WidthSegments  = 10,
                HeightSegments = 5,
                PhiStart       = 0,
                PhiLength      = (float)Math.PI * 2,
                ThetaStart     = 0,
                ThetaLength    = (float)Math.PI * 2
            };

            var sphereMesh = new Mesh
            {
                Geometry = sphereGeometry,
                Material = material,
                Position = new Vector3(-45, 10, 45),
                Name     = "My Sphere"
            };

            scene.Add(sphereMesh);

            #region Lights

            var pointLight = new PointLight
            {
                Color     = new Color(100, 100, 100).ToInt(),
                Decay     = 1,
                Intensity = 3,
                Name      = "My PointLight",
                Position  = new Vector3(10, 10, 10)
            };

            scene.Add(pointLight);

            var ambientLight = new AmbientLight
            {
                Color     = new Color(255, 0, 255).ToInt(),
                Intensity = 5,
                Name      = "My AmbientLight"
            };

            scene.Add(ambientLight);

            var directionalLight = new DirectionalLight
            {
                Target = new Object3D {
                    Position = new Vector3(3, 0, 0)
                },
                Position = new Vector3(-10, 10, 5),
                Name     = "My DirectionalLight"
            };

            scene.Add(directionalLight);

            var spotLight = new SpotLight
            {
                Target = new Object3D {
                    Position = new Vector3(3, 0, 3)
                },
                Position = new Vector3(20, 20, 0),
                Name     = "My SpotLight"
            };

            scene.Add(spotLight);

            var hemiLight = new HemisphereLight
            {
                SkyColor    = new Color(0, 30, 255).ToInt(),
                GroundColor = new Color(30, 30, 30).ToInt(),
                Name        = "My HemisphereLight"
            };

            scene.Add(hemiLight);

            #endregion

            //Console.WriteLine(geometry.ToJSON(true));

            Console.WriteLine(scene.ToJSON(false));

            Console.ReadLine();
        }