void Start()
        {
            Matrix4x4d T, R;

            double spacing = 0.125;
            double radius  = spacing;
            double mass    = 1.0;

            System.Random rnd = new System.Random(0);

            Vector3 min    = new Vector3(-1, -1, -1);
            Vector3 max    = new Vector3(1, 1, 1);
            Box3d   bounds = new Box3d(min, max);

            ParticlesFromBounds source = new ParticlesFromBounds(spacing, bounds);

            T = Matrix4x4d.Translate(new Vector3d(0.0, 4.0, 0.0));
            R = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 25.0));

            RidgidBody3d body = new RidgidBody3d(source, radius, mass, T * R);

            body.Dampning = 1.0;
            body.RandomizePositions(rnd, radius * 0.01);

            Solver = new Solver3d();
            Solver.AddBody(body);
            Solver.AddForce(new GravitationalForce3d());
            Solver.AddCollision(new PlanarCollision3d(Vector3.up, 0));
            Solver.SolverIterations    = 2;
            Solver.CollisionIterations = 2;
            Solver.SleepThreshold      = 1;

            CreateSpheres();
        }
示例#2
0
        protected override void InitNode()
        {
            Body = GetComponentInParent <CelestialBody>();
            Body.TerrainNodes.Add(this);

            TerrainMaterial = MaterialHelper.CreateTemp(Body.ColorShader, "TerrainNode");

            //Manager.GetSkyNode().InitUniforms(TerrainMaterial);

            var faces = new Vector3d[] { new Vector3d(0, 0, 0), new Vector3d(90, 0, 0), new Vector3d(90, 90, 0), new Vector3d(90, 180, 0), new Vector3d(90, 270, 0), new Vector3d(0, 180, 180) };

            FaceToLocal = Matrix4x4d.Identity();

            // If this terrain is deformed into a sphere the face matrix is the rotation of the
            // terrain needed to make up the spherical planet. In this case there should be 6 terrains, each with a unique face number
            if (Face - 1 >= 0 && Face - 1 < 6)
            {
                FaceToLocal = Matrix4x4d.Rotate(faces[Face - 1]);
            }

            //LocalToWorld = Matrix4x4d.ToMatrix4x4d(transform.localToWorldMatrix) * FaceToLocal;
            LocalToWorld = FaceToLocal;

            Deformation = new DeformationSpherical(Body.Radius);

            TerrainQuadRoot = new TerrainQuad(this, null, 0, 0, -Body.Radius, -Body.Radius, 2.0 * Body.Radius, ZMin, ZMax);
        }
示例#3
0
        public override void InitNode()
        {
            ParentBody = GetComponentInParent <Body>();

            TerrainMaterial = MaterialHelper.CreateTemp(ParentBody.ColorShader, "TerrainNode");

            FaceToLocal = Matrix4x4d.identity;

            // NOTE : Body shape dependent...
            var celestialBody = ParentBody as CelestialBody;
            var faces         = new Vector3d[] { new Vector3d(0, 0, 0), new Vector3d(90, 0, 0), new Vector3d(90, 90, 0), new Vector3d(90, 180, 0), new Vector3d(90, 270, 0), new Vector3d(0, 180, 180) };

            // If this terrain is deformed into a sphere the face matrix is the rotation of the
            // terrain needed to make up the spherical planet. In this case there should be 6 terrains, each with a unique face number
            if (Face - 1 >= 0 && Face - 1 < 6)
            {
                FaceToLocal = Matrix4x4d.Rotate(faces[Face - 1]);
            }
            if (celestialBody == null)
            {
                throw new Exception("Wow! Celestial body isn't Celestial?!");
            }

            LocalToWorld = Matrix4x4d.ToMatrix4x4d(celestialBody.transform.localToWorldMatrix) * FaceToLocal;
            Deformation  = new DeformationSpherical(celestialBody.Size);

            TangentFrameToWorld = new Matrix3x3d(LocalToWorld.m[0, 0], LocalToWorld.m[0, 1], LocalToWorld.m[0, 2],
                                                 LocalToWorld.m[1, 0], LocalToWorld.m[1, 1], LocalToWorld.m[1, 2],
                                                 LocalToWorld.m[2, 0], LocalToWorld.m[2, 1], LocalToWorld.m[2, 2]);

            InitUniforms(TerrainMaterial);

            CreateTerrainQuadRoot(ParentBody.Size);

            CollectSamplers();
            CollectSamplersSuitable();

            SamplersOrder = new TileSamplerOrder(Samplers);

            var producers    = GetComponentsInChildren <TileProducer>();
            var lastProducer = producers[producers.Length - 1];

            if (lastProducer.IsLastInSequence == false)
            {
                lastProducer.IsLastInSequence = true;

                Debug.Log(string.Format("TerrainNode: {0} probably last in generation sequence, but maybe accidentally not marked as. Fixed!", lastProducer.name));
            }
        }
示例#4
0
        void Start()
        {
            TrianglesFromGrid source = new TrianglesFromGrid(radius, width, depth);

            Matrix4x4d T  = Matrix4x4d.Translate(new Vector3d(0.0, height, 0.0));
            Matrix4x4d R  = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 0.0));
            Matrix4x4d RT = T * R;

            Body          = new ClothBody3d(source, radius, mass, stretchStiffness, bendStiffness, RT);
            Body.Dampning = 1.0;

            Vector3 min = new Vector3((float)(-width / 2 - 0.1),
                                      (float)(height - 0.1),
                                      (float)(-depth / 2 - 0.1));
            Vector3 max = new Vector3((float)(width / 2 + 0.1),
                                      (float)(height + 0.1),
                                      (float)(-depth / 2 + 0.1));

            StaticBounds = new Box3d(min, max);

            Body.MarkAsStatic(StaticBounds);

            Solver = new Solver3d();
            Solver.AddBody(Body);
            Solver.AddForce(new GravitationalForce3d());
            //Solver.AddCollision(new PlanarCollision3d(Vector3.up, 0));
            Solver.SolverIterations    = 2;
            Solver.CollisionIterations = 2;
            Solver.SleepThreshold      = 1;
            //setting compute shader of solver
            Solver.ApplyExternalForcesShader  = ApplyExternalForces;
            Solver.EstimatePositionsShader    = EstimatePositions;
            Solver.ResolveCollisionsShader    = ResolveCollisions;
            Solver.ConstraintPositionsShader  = ConstraintPositions;
            Solver.UpdateVelocitiesShader     = UpdateVelocities;
            Solver.ConstraintVelocitiesShader = ConstraintVelocities;
            Solver.UpdatePositionsShader      = UpdatePositions;
            Solver.GPUmode = GPUmode;
            Solver.init();

            CreateSpheres();
        }
示例#5
0
        void Start()
        {
            Matrix4x4d T  = Matrix4x4d.Translate(new Vector3d(0.0, 6.0, 0.0));
            Matrix4x4d R  = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 0.0));
            Matrix4x4d TR = T * R;

            double radius    = 0.25;
            double stiffness = 0.2;
            double mass      = 1.0;

            System.Random rnd = new System.Random(0);

            Vector3d min    = new Vector3d(-5.0, -1.0, -0.5);
            Vector3d max    = new Vector3d(5.0, 1.0, 0.5);
            Box3d    bounds = new Box3d(min, max);
            TetrahedronsFromBounds source = new TetrahedronsFromBounds(radius, bounds);

            Body          = new DeformableBody3d(source, radius, mass, stiffness, TR);
            Body.Dampning = 1.0;
            Body.RandomizePositions(rnd, radius * 0.01);
            Body.RandomizeConstraintOrder(rnd);

            Vector3d smin = new Vector3d(min.x, min.y + 6.0, min.z - 0.1);
            Vector3d smax = new Vector3d(min.x + 0.5, max.y + 6.0, max.z + 0.1);

            StaticBounds = new Box3d(smin, smax);
            Body.MarkAsStatic(StaticBounds);

            Solver = new Solver3d();
            Solver.AddBody(Body);
            Solver.AddForce(new GravitationalForce3d());
            Solver.AddCollision(new PlanarCollision3d(Vector3d.UnitY, 0));
            Solver.SolverIterations    = 2;
            Solver.CollisionIterations = 2;
            Solver.SleepThreshold      = 1;

            RenderEvent.AddRenderEvent(Camera.main, DrawOutline);

            CreateSpheres();
        }
示例#6
0
        void Start()
        {
            double stretchStiffness = 0.25;
            double bendStiffness    = 0.5;
            double mass             = 1.0;
            double radius           = 0.125;

            double width  = 5.0;
            double height = 4.0;
            double depth  = 5.0;

            TrianglesFromGrid source = new TrianglesFromGrid(radius, width, depth);

            Matrix4x4d T  = Matrix4x4d.Translate(new Vector3d(0.0, height, 0.0));
            Matrix4x4d R  = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 0.0));
            Matrix4x4d RT = T * R;

            Body          = new ClothBody3d(source, radius, mass, stretchStiffness, bendStiffness, RT);
            Body.Dampning = 1.0;

            Vector3d min = new Vector3d(-width / 2 - 0.1, height - 0.1, -depth / 2 - 0.1);
            Vector3d max = new Vector3d(width / 2 + 0.1, height + 0.1, -depth / 2 + 0.1);

            StaticBounds = new Box3d(min, max);

            Body.MarkAsStatic(StaticBounds);

            Solver = new Solver3d();
            Solver.AddBody(Body);
            Solver.AddForce(new GravitationalForce3d());
            Solver.AddCollision(new PlanarCollision3d(Vector3d.UnitY, 0));
            Solver.SolverIterations    = 2;
            Solver.CollisionIterations = 2;
            Solver.SleepThreshold      = 1;

            RenderEvent.AddRenderEvent(Camera.main, DrawOutline);

            CreateSpheres();
        }