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