public virtual void InitUniforms(Material target) { if (target == null) { return; } ParentBody.InitUniforms(target); }
public Vector3d GetSurfaceNormalVector() { if (ParentBody == null) { return(Vector3d.zero); } ParentBody.GetLatLonAlt(position, out double lat, out double lon, out double _); return(ParentBody.GetSurfaceNVector(lat, lon)); }
public virtual void SetUniforms(Material target) { if (target == null) { return; } ParentBody.SetUniforms(target); Deformation.SetUniforms(this, target); }
public bool IsChildOfBody(ComponentBody componentBody) { if (ParentBody != componentBody) { if (ParentBody != null) { return(ParentBody.IsChildOfBody(componentBody)); } return(false); } return(true); }
public Egg(string adult, ComponentManager manager, Vector3 position, BoundingBox positionConstraint) : base(manager) { PositionConstrain = positionConstraint; Adult = adult; Birthday = Manager.World.Time.CurrentDate + new TimeSpan(0, 12, 0, 0); if (ResourceLibrary.GetResourceByName(adult + " Egg") == null || !EntityFactory.EnumerateEntityTypes().Contains(adult + " Egg Resource")) { Resource newEggResource = new Resource(ResourceLibrary.GetResourceByName(ResourceType.Egg)); newEggResource.Name = adult + " Egg"; ResourceLibrary.Add(newEggResource); } ParentBody = EntityFactory.CreateEntity <Body>(adult + " Egg Resource", position); ParentBody.AddChild(this); }
public void SetUniforms(Material target) { if (target == null) { return; } if (ParentBody.GetBodyDeformationType() == BodyDeformationType.Spherical) { var celestialBody = ParentBody as CelestialBody; if (celestialBody == null) { throw new Exception("Wow! Celestial body isn't Celestial?!"); } target.SetTexture("_Ground_Diffuse", celestialBody.GroundDiffuse); target.SetTexture("_Ground_Normal", celestialBody.GroundNormal); target.SetTexture("_DetailedNormal", celestialBody.DetailedNormal); } }
/// <summary> /// Organizes the string tokens into a list of IBodys. /// </summary> /// <returns> /// The hierarchical list of IBodys. /// </returns> public List <IBody> Organize() { List <IBody> bodies = new List <IBody>(); List <string> temp = tokens; for (int i = 0; i < temp.Count; i++) { if (OPEN_CLOSE_CHARS.ContainsKey(temp[i])) { ParentBody newParent = new ParentBody(); temp = newParent.Associate(temp[i], temp.GetRange(i + 1, temp.Count - (i + 1))); i = -1; bodies.Add(newParent); } else { bodies.Add(new StringBody(temp[i])); } } return(bodies); }
protected override void UpdateNode() { TerrainMaterial.renderQueue = (int)ParentBody.RenderQueue + ParentBody.RenderQueueOffset; if (ParentBody.GetBodyDeformationType() == BodyDeformationType.Spherical) { LocalToWorld = Matrix4x4d.ToMatrix4x4d(ParentBody.transform.localToWorldMatrix) * FaceToLocal; } else { LocalToWorld = FaceToLocal; } 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]); var localToCamera = GodManager.Instance.WorldToCamera * LocalToWorld; var invLocalToCamera = localToCamera.Inverse(); DeformedCameraPosition = invLocalToCamera * Vector3d.zero; DeformedFrustumPlanes = Frustum.GetFrustumPlanes(GodManager.Instance.CameraToScreen * localToCamera); // NOTE : Extract frustum planes from LocalToScreen matrix... LocalCameraPosition = Deformation.DeformedToLocal(DeformedCameraPosition); var m = Deformation.LocalToDeformedDifferential(LocalCameraPosition, true); var left = DeformedFrustumPlanes[0].XYZ().Normalized(); var right = DeformedFrustumPlanes[1].XYZ().Normalized(); var fov = (float)MathUtility.Safe_Acos(-left.Dot(right)); SplitDistance = SplitFactor * Screen.width / 1024.0f * Mathf.Tan(40.0f * Mathf.Deg2Rad) / Mathf.Tan(fov / 2.0f); DistanceFactor = (float)Math.Max((new Vector3d(m.m[0, 0], m.m[1, 0], m.m[2, 0])).Magnitude(), (new Vector3d(m.m[0, 1], m.m[1, 1], m.m[2, 1])).Magnitude()); if (SplitDistance < 1.1f || !MathUtility.IsFinite(SplitDistance)) { SplitDistance = 1.1f; } // initializes data structures for horizon occlusion culling if (UseHorizonCulling && LocalCameraPosition.z <= TerrainQuadRoot.ZMax) { var deformedDirection = invLocalToCamera * Vector3d.forward; var localDirection = (Deformation.DeformedToLocal(deformedDirection) - LocalCameraPosition).xy.Normalized(); LocalCameraDirection = new Matrix2x2d(localDirection.y, -localDirection.x, -localDirection.x, -localDirection.y); for (byte i = 0; i < HORIZON_SIZE; ++i) { Horizon[i] = float.NegativeInfinity; } } TerrainQuadRoot.UpdateLOD(); SetUniforms(TerrainMaterial); if (ParentBody.AtmosphereEnabled) { if (ParentBody.Atmosphere != null) { ParentBody.Atmosphere.SetUniforms(TerrainMaterial); } } if (ParentBody.OceanEnabled) { if (ParentBody.Ocean != null) { ParentBody.Ocean.SetUniforms(TerrainMaterial); } else { TerrainMaterial.SetFloat("_Ocean_DrawBRDF", 0.0f); } } else { TerrainMaterial.SetFloat("_Ocean_DrawBRDF", 0.0f); } Deformation.SetUniforms(this, TerrainMaterial); //if (Manager.GetPlantsNode() != null) // Manager.GetPlantsNode().SetUniforms(TerrainMaterial); }
protected override void InitNode() { ParentBody = GetComponentInParent <Body>(); ParentBody.TerrainNodes.Add(this); TerrainMaterial = MaterialHelper.CreateTemp(ParentBody.ColorShader, "TerrainNode"); FaceToLocal = Matrix4x4d.identity; if (ParentBody.GetBodyDeformationType() == BodyDeformationType.Spherical) { var celestialBody = ParentBody as CelestialBody; if (celestialBody == null) { throw new Exception("Wow! Celestial body isn't Celestial?!"); } 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]); } LocalToWorld = Matrix4x4d.ToMatrix4x4d(celestialBody.transform.localToWorldMatrix) * FaceToLocal; Deformation = new DeformationSpherical(celestialBody.Size); InitUniforms(TerrainMaterial); if (celestialBody.Atmosphere != null) { celestialBody.Atmosphere.InitUniforms(TerrainMaterial); } } else { LocalToWorld = FaceToLocal; Deformation = new DeformationBase(); } 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]); CreateTerrainQuadRoot(ParentBody.Size); CollectSamplers(); 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("{0} probably last in generation sequence, but maybe accidentally not marked as. Fixed!", lastProducer.name)); } }