public Quad SetupSubQuad(QuadPosition quadPosition) { var go = new GameObject(string.Format("Quad_{0}", quadPosition)); var mesh = GodManager.Instance.PrototypeMesh; mesh.bounds = new Bounds(Vector3.zero, new Vector3(PlanetRadius * 2, PlanetRadius * 2, PlanetRadius * 2)); var quadComponent = go.AddComponent <Quad>(); quadComponent.Planetoid = this; quadComponent.QuadMesh = mesh; quadComponent.SetupCorners(quadPosition); var gc = QuadGenerationConstants.Init(TerrainMaxHeight); gc.planetRadius = PlanetRadius; quadComponent.Position = quadPosition; quadComponent.generationConstants = gc; quadComponent.ShouldDraw = false; if (qdtccc == null) { qdtccc = new QuadDistanceToClosestCornerComparer(); } Quads.Add(quadComponent); Quads.Sort(qdtccc); return(quadComponent); }
public static Vector3 CubeCoord(QuadGenerationConstants constants, int VerticesPerSide, Vector3i id, int mod, float spacing) { double eastValue = (id.X - ((VerticesPerSide - mod) * 0.5)) * spacing; double northValue = (id.Y - ((VerticesPerSide - mod) * 0.5)) * spacing; Vector3 cubeCoordEast = constants.cubeFaceEastDirection * (float)eastValue; Vector3 cubeCoordNorth = constants.cubeFaceNorthDirection * (float)northValue; Vector3 cubeCoord = cubeCoordEast + cubeCoordNorth + constants.patchCubeCenter; return(cubeCoord); }
public static QuadGenerationConstants Init(float terrainMaxHeight) { QuadGenerationConstants temp = new QuadGenerationConstants(); temp.meshSettings = new Vector4(QuadSettings.VerticesPerSide, QuadSettings.VerticesPerSideWithBorder, QuadSettings.VerticesPerSideFull, QuadSettings.VerticesPerSideWithBorderFull); temp.borderMod = new Vector2(QuadSettings.BorderModMesh, QuadSettings.BorderModTexture); temp.spacing = QuadSettings.Spacing; temp.spacingFull = QuadSettings.SpacingFull; temp.terrainMaxHeight = terrainMaxHeight; return(temp); }
public void SetupMainQuad(QuadPosition quadPosition) { GameObject go = new GameObject(string.Format("Quad_{0}", quadPosition)); go.transform.parent = QuadsRoot.transform; go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; Mesh mesh = GetMesh(quadPosition); mesh.bounds = new Bounds(Vector3.zero, new Vector3(PlanetRadius * 2, PlanetRadius * 2, PlanetRadius * 2)); Material material = MaterialHelper.CreateTemp(ColorShader, "Quad"); Quad quadComponent = go.AddComponent <Quad>(); quadComponent.Planetoid = this; quadComponent.QuadMesh = mesh; quadComponent.QuadMaterial = material; if (Atmosphere != null) { Atmosphere.InitUniforms(null, quadComponent.QuadMaterial, false); } QuadGenerationConstants gc = QuadGenerationConstants.Init(TerrainMaxHeight); gc.planetRadius = PlanetRadius; gc.cubeFaceEastDirection = quadComponent.GetCubeFaceEastDirection(quadPosition); gc.cubeFaceNorthDirection = quadComponent.GetCubeFaceNorthDirection(quadPosition); gc.patchCubeCenter = quadComponent.GetPatchCubeCenter(quadPosition); quadComponent.Position = quadPosition; quadComponent.ID = QuadID.One; quadComponent.generationConstants = gc; quadComponent.SetupCorners(quadPosition); quadComponent.ShouldDraw = true; quadComponent.ReadyForDispatch = true; Quads.Add(quadComponent); MainQuads.Add(quadComponent); }
public Quad SetupSubQuad(QuadPosition quadPosition) { GameObject go = new GameObject(string.Format("Quad_{0}", quadPosition)); Mesh mesh = GetMesh(quadPosition); mesh.bounds = new Bounds(Vector3.zero, new Vector3(PlanetRadius * 2, PlanetRadius * 2, PlanetRadius * 2)); Material material = MaterialHelper.CreateTemp(ColorShader, "Quad"); Quad quadComponent = go.AddComponent <Quad>(); quadComponent.Planetoid = this; quadComponent.QuadMesh = mesh; quadComponent.QuadMaterial = material; quadComponent.SetupCorners(quadPosition); if (Atmosphere != null) { Atmosphere.InitUniforms(null, quadComponent.QuadMaterial, false); } QuadGenerationConstants gc = QuadGenerationConstants.Init(TerrainMaxHeight); gc.planetRadius = PlanetRadius; quadComponent.Position = quadPosition; quadComponent.generationConstants = gc; quadComponent.ShouldDraw = false; if (qdtccc == null) { qdtccc = new QuadDistanceToClosestCornerComparer(); } Quads.Add(quadComponent); Quads.Sort(qdtccc); return(quadComponent); }
public static void HeightMain(QuadGenerationConstants constants, int nVerticesPerSideWithBorder, out OutputStruct[] patchPreOutput) { patchPreOutput = new OutputStruct[nVerticesPerSideWithBorder * nVerticesPerSideWithBorder]; Vector3i id = Vector3i.Zero; for (int x = id.X; x < nVerticesPerSideWithBorder; x++) { for (int y = id.Y; y < nVerticesPerSideWithBorder; y++) { int outBuffOffset = id.X + id.Y * nVerticesPerSideWithBorder; Vector3 cubeCoord = CubeCoord(constants, nVerticesPerSideWithBorder, id, (int)constants.borderMod.x, constants.spacing); Vector3 patchCenter = constants.patchCubeCenter.normalized * constants.planetRadius; Vector3 patchNormalizedCoord = cubeCoord.normalized; Vector3 patchCoord = constants.planetRadius * patchNormalizedCoord; Vector3 patchCoordCentered = patchCoord - patchCenter; Vector3 patchCubeCoordCentered = patchNormalizedCoord; Vector3 patchCubeCoordCenteredFlat = patchNormalizedCoord; float noise = 1; float height = noise * constants.terrainMaxHeight; patchCoordCentered += patchNormalizedCoord * height; patchCubeCoordCentered += patchNormalizedCoord * height; patchCubeCoordCenteredFlat += patchNormalizedCoord; Vector4 output = new Vector4(patchCoordCentered.x, patchCoordCentered.y, patchCoordCentered.z, 0.0f); Vector4 cubeOutput = new Vector4(patchCubeCoordCentered.x, patchCubeCoordCentered.y, patchCubeCoordCentered.z, 0.0f); patchPreOutput[outBuffOffset].noise = noise; patchPreOutput[outBuffOffset].patchCenter = patchCenter; patchPreOutput[outBuffOffset].position = output; patchPreOutput[outBuffOffset].cubePosition = cubeOutput; } } }
private void SetupMainQuad(QuadPosition quadPosition) { var go = new GameObject(string.Format("Quad_{0}", quadPosition)); go.transform.parent = QuadsRoot.transform; go.transform.position = Vector3.zero; go.transform.rotation = Quaternion.identity; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; var mesh = GodManager.Instance.PrototypeMesh; mesh.bounds = new Bounds(Vector3.zero, new Vector3(PlanetRadius * 2, PlanetRadius * 2, PlanetRadius * 2)); var quadComponent = go.AddComponent <Quad>(); quadComponent.Planetoid = this; quadComponent.QuadMesh = mesh; var gc = QuadGenerationConstants.Init(TerrainMaxHeight); gc.planetRadius = PlanetRadius; gc.cubeFaceEastDirection = quadComponent.GetCubeFaceEastDirection(quadPosition); gc.cubeFaceNorthDirection = quadComponent.GetCubeFaceNorthDirection(quadPosition); gc.patchCubeCenter = quadComponent.GetPatchCubeCenter(quadPosition); quadComponent.Position = quadPosition; quadComponent.ID = QuadID.One; quadComponent.generationConstants = gc; quadComponent.SetupCorners(quadPosition); quadComponent.ShouldDraw = true; quadComponent.ReadyForDispatch = true; Quads.Add(quadComponent); MainQuads.Add(quadComponent); }