Exemplo n.º 1
0
    public void GenerateMesh(ShapeGenerator shapeGenerator, float chunkSize, float chunkDensity, float surfaceHeight, bool interpolate)
    {
        this.shapeGenerator = shapeGenerator;
        this.chunkSize      = chunkSize;
        this.chunkDensity   = chunkDensity;
        this.surfaceHeight  = surfaceHeight;
        this.interpolate    = interpolate;

        // Setup triangles and vertices lists with undefined sizes
        List <Vector3> verticesList  = new List <Vector3>();
        List <int>     trianglesList = new List <int>();
        int            triIndex      = 0;
        int            vertIndex     = 0;


        // For each cube
        for (int x = 0; x < chunkDensity; x++)
        {
            for (int y = 0; y < chunkDensity; y++)
            {
                for (int z = 0; z < chunkDensity; z++)
                {
                    // Determin cube type from binary
                    int cubeNumber = 0;
                    if (NoiseAtIndex(x + 0, y + 0, z + 0) < surfaceHeight)
                    {
                        cubeNumber += 1;
                    }
                    if (NoiseAtIndex(x + 0, y + 0, z + 1) < surfaceHeight)
                    {
                        cubeNumber += 2;
                    }
                    if (NoiseAtIndex(x + 1, y + 0, z + 1) < surfaceHeight)
                    {
                        cubeNumber += 4;
                    }
                    if (NoiseAtIndex(x + 1, y + 0, z + 0) < surfaceHeight)
                    {
                        cubeNumber += 8;
                    }
                    if (NoiseAtIndex(x + 0, y + 1, z + 0) < surfaceHeight)
                    {
                        cubeNumber += 16;
                    }
                    if (NoiseAtIndex(x + 0, y + 1, z + 1) < surfaceHeight)
                    {
                        cubeNumber += 32;
                    }
                    if (NoiseAtIndex(x + 1, y + 1, z + 1) < surfaceHeight)
                    {
                        cubeNumber += 64;
                    }
                    if (NoiseAtIndex(x + 1, y + 1, z + 0) < surfaceHeight)
                    {
                        cubeNumber += 128;
                    }

                    // Loop through each triangle in the tiangulation table
                    for (int i = 0; triTable[cubeNumber, i] != -1; i += 3)
                    {
                        int[] thisTriangle = { triTable[cubeNumber, i], triTable[cubeNumber, i + 1], triTable[cubeNumber, i + 2] };
                        foreach (int edgeVal in thisTriangle)
                        {
                            // Calculate surface point along edge
                            Vector3[] localPoints = new Vector3[2];
                            if (edgeVal == 0)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(0, 0, 0), new Vector3(0, 0, 1)
                                }
                            }
                            ;
                            if (edgeVal == 1)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(0, 0, 1), new Vector3(1, 0, 1)
                                }
                            }
                            ;
                            if (edgeVal == 2)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(1, 0, 1), new Vector3(1, 0, 0)
                                }
                            }
                            ;
                            if (edgeVal == 3)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(1, 0, 0), new Vector3(0, 0, 0)
                                }
                            }
                            ;
                            if (edgeVal == 4)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(0, 1, 0), new Vector3(0, 1, 1)
                                }
                            }
                            ;
                            if (edgeVal == 5)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(0, 1, 1), new Vector3(1, 1, 1)
                                }
                            }
                            ;
                            if (edgeVal == 6)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(1, 1, 1), new Vector3(1, 1, 0)
                                }
                            }
                            ;
                            if (edgeVal == 7)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(1, 1, 0), new Vector3(0, 1, 0)
                                }
                            }
                            ;
                            if (edgeVal == 8)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(0, 0, 0), new Vector3(0, 1, 0)
                                }
                            }
                            ;
                            if (edgeVal == 9)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(0, 0, 1), new Vector3(0, 1, 1)
                                }
                            }
                            ;
                            if (edgeVal == 10)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(1, 0, 1), new Vector3(1, 1, 1)
                                }
                            }
                            ;
                            if (edgeVal == 11)
                            {
                                localPoints = new Vector3[2] {
                                    new Vector3(1, 0, 0), new Vector3(1, 1, 0)
                                }
                            }
                            ;
                            if (!interpolate)
                            {
                                Vector3 localPoint = (Vector3.Lerp(localPoints[0], localPoints[1], 0.5f) + new Vector3(x, y, z)) * chunkSize / chunkDensity - Vector3.one * chunkSize / 2f;
                                verticesList.Add(localPoint);
                            }
                            else
                            {
                                float   noise1     = NoiseAtIndex(x + localPoints[0].x, y + localPoints[0].y, z + localPoints[0].z);
                                float   noise2     = NoiseAtIndex(x + localPoints[1].x, y + localPoints[1].y, z + localPoints[1].z);
                                float   t          = (surfaceHeight - noise1) / (noise2 - noise1);
                                Vector3 localPoint = (Vector3.Lerp(localPoints[0], localPoints[1], t) + new Vector3(x, y, z)) * chunkSize / chunkDensity - Vector3.one * chunkSize / 2f;
                                verticesList.Add(localPoint);
                                if (localPoint.y < minHeight)
                                {
                                    minHeight = localPoint.y;
                                }
                                if (localPoint.y > maxHeight)
                                {
                                    maxHeight = localPoint.y;
                                }
                            }

                            // Add Triangle Point
                            trianglesList.Add(verticesList.Count - 1);
                        }
                    }
                }
            }
        }

        // Create Mesh
        mesh           = new Mesh();
        mesh.vertices  = verticesList.ToArray();
        mesh.triangles = trianglesList.ToArray();
        mesh.RecalculateNormals();
        GetComponent <MeshFilter>().mesh = mesh;
    }
Exemplo n.º 2
0
 public static void Load(ContentManager content)
 {
     _fontEditor     = content.Load <SpriteFont>("EditorFont");
     _textBackground = ShapeGenerator.GenerateRectangle(200, 200, Color.Black);
     _fontHeight     = (int)_fontEditor.MeasureString("Aq").X;
 }
 /// <summary>
 /// Build a starting point (in this case, a quad)
 /// </summary>
 void Start()
 {
     m_Mesh = ShapeGenerator.GeneratePlane(PivotLocation.Center, 1, 1, 0, 0, Axis.Up);
     m_Mesh.GetComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.defaultMaterial;
     m_LastExtrudedFace = m_Mesh.faces[0];
 }
 public void StartTrain(ShapeGenerator generator)
 {
     this.generator   = generator;
     currentIteration = new Iteration(this, generator.GetShape(0), 0);
 }
Exemplo n.º 5
0
 public override ProBuilderMesh Build(bool preview = false)
 {
     return(ShapeGenerator.GeneratePlane(EditorUtility.newShapePivotLocation, 1, 1, 0, 0, s_Axis));
 }
Exemplo n.º 6
0
 private void Start()
 {
     shapeGenerator = FindObjectOfType <ShapeGenerator>();
     shapeDisplayer = FindObjectOfType <ShapeDisplayer>();
 }
Exemplo n.º 7
0
        private static void Window_Load(object sender, EventArgs e)
        {
            SolidColorMeshShader.Load();
            SolidColorMeshShader.SharedInstance.Use();

            camera.Projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(40.0f), (float)window.Width / (float)window.Height, 1.0f, 10000.0f);
            //camera.Projection = Matrix4.CreateOrthographic(10.0f * (float)window.Width / (float)window.Height, 10.0f, 1.0f, 10000.0f);

            cameraUp    = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
            cameraRight = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
            cameraPos   = new Vector4(0.0f, 10.0f, 40.0f, 1.0f);
            camera.View = Matrix4.LookAt(cameraPos.Xyz, Vector3.Zero, cameraUp.Xyz);
            //camera.View = Matrix4.Identity;

            /*
             * sphere = new ModelMesh() {
             *  Transform = new World3DShaderTransform(Matrix4.CreateScale(8.0f)),
             *  DefaultShader = SolidColorMeshShader.SharedInstance,
             *  DefaultVertexBuffer = new VertexBuffer() { DisposalLevel = ItemDisposalLevel.ModelMesh },
             *  DefaultMaterial = new SolidColorShaderMaterial(new Vector4(0.0f, 1.0f, 1.0f, 1.0f)),
             *  IndexBuffer = new IndexBuffer() { DisposalLevel = ItemDisposalLevel.ModelMesh }
             * };
             */
            sphere = ShapeGenerator.MakeSphere <FirimenticEngine.CustomComponents.Graphics.Vertices.VertexPositioned>(
                10, 20, FirimenticEngine.Graphics.Axii.Y, PrimitiveType.Lines, SolidColorMeshShader.SharedInstance,
                FirimenticEngine.Graphics.VertexFormat.Position
                );
            sphere.Transform       = new World3DShaderTransform(Matrix4.CreateScale(8.0f));
            sphere.DefaultMaterial = sphere.Parts[0].Material = new SolidColorShaderMaterial(new Vector4(0.0f, 1.0f, 1.0f, 1.0f));

            /*
             * VertexPositioned[] verts = new VertexPositioned[] {
             *  new VertexPositioned( 0.0f, 0.0f, 0.0f),
             *  new VertexPositioned( 1.0f, 0.0f, 0.0f),
             *  new VertexPositioned(-1.0f, 0.0f, 0.0f),
             *  new VertexPositioned( 0.0f, 1.0f, 0.0f),
             *  new VertexPositioned( 0.0f,-1.0f, 0.0f),
             *  new VertexPositioned( 0.0f, 0.0f, 1.0f),
             *  new VertexPositioned( 0.0f, 0.0f,-1.0f)
             * };
             *
             * ushort[] indcs = new ushort[] {
             *  2, 0, 4
             * };
             */


            /*
             * VertexPositioned[] verts = new VertexPositioned[] {
             *  new VertexPositioned(-1.0f, 1.0f, 1.0f),
             *  new VertexPositioned( 1.0f, 1.0f, 1.0f),
             *  new VertexPositioned( 1.0f,-1.0f, 1.0f),
             *  new VertexPositioned(-1.0f,-1.0f, 1.0f),
             *  new VertexPositioned(-1.0f, 1.0f,-1.0f),
             *  new VertexPositioned( 1.0f, 1.0f,-1.0f),
             *  new VertexPositioned( 1.0f,-1.0f,-1.0f),
             *  new VertexPositioned(-1.0f,-1.0f,-1.0f)
             * };
             *
             * ushort[] indcs = new ushort[] {
             *  0, 1, 2, 3, 0,
             *  4, 7, 3, 2,
             *  6, 7, 6,
             *  5, 4, 5,
             *  1,
             *  3, 2, 0,
             *  7, 4, 3,
             *  6, 2, 7,
             *  5, 6, 4,
             *  1, 0, 5,
             *  2, 1, 6
             * };
             */


            /*
             * VertexPositioned[] verts = new VertexPositioned[19 * 40 + 2];
             *
             * float inc = 9.0f * MathHelper.Pi / 180.0f;
             * float fullCirc = 2 * MathHelper.Pi - float.Epsilon;
             * float halfCirc = MathHelper.Pi - float.Epsilon;
             * float scale = 1.0f;
             * int ind = 0;
             *
             * verts[ind++] = new VertexPositioned(Vector3.UnitY * scale);
             * verts[ind++] = new VertexPositioned(Vector3.UnitY * -scale);
             * for (float lng = 0; lng < fullCirc; lng += inc) {
             *  for (float lat = inc; lat < halfCirc; lat += inc) {
             *      Matrix4 rot = Matrix4.CreateRotationZ(lng) * Matrix4.CreateRotationX(lat);
             *      Vector3 pos = (Vector3.UnitY * scale).Transform(ref rot);
             *      verts[ind++] = new VertexPositioned(pos);
             *  }
             * }
             *
             *
             * ushort[] indcs = new ushort[20 * (2 + 19 + 19) + 1 + 19 * (40 + 1)];
             *
             * ind = 0;
             * for (ushort lngInd = 0; lngInd < 20; lngInd++) {
             *  indcs[ind++] = 0;
             *  for (ushort latInd = 2; latInd < 21; latInd++) {
             *      indcs[ind++] = (ushort)(lngInd * 19 + latInd);
             *  }
             *  indcs[ind++] = 1;
             *  for (ushort latInd = 20; latInd > 1; latInd--) {
             *      indcs[ind++] = (ushort)((lngInd + 20) * 19 + latInd);
             *  }
             * }
             * indcs[ind++] = 0;
             * for (ushort latInd = 2; latInd < 21; latInd++) {
             *  for (ushort lngInd = 0; lngInd < 40; lngInd++) {
             *      indcs[ind++] = (ushort)(lngInd * 19 + latInd);
             *  }
             *  indcs[ind++] = latInd;
             * }
             */


            //sphere.DefaultVertexBuffer.SetData(VertexFormat.Position, verts);
            //sphere.IndexBuffer.SetData(indcs);

            //new ModelMeshPart(sphere, null, null, null, PrimitiveType.LineStrip, indcs.Length, 0);
        }
Exemplo n.º 8
0
    public static IEnumerator ExtrudeOrthogonally_OneElementManyTimes_NoYOffsetAccumulates()
    {
        // Generate single face plane
        var pb = ShapeGenerator.GeneratePlane(PivotLocation.Center, 1f, 1f, 0, 0, Axis.Up);

        try
        {
            pb.transform.position = Vector3.zero;
            pb.transform.rotation = Quaternion.identity;

            ProBuilderEditor.MenuOpenWindow();
            EditorApplication.ExecuteMenuItem("Window/General/Scene");

            var sceneView = UnityEngine.Resources.FindObjectsOfTypeAll <UnityEditor.SceneView>()[0];
            sceneView.orthographic = true;
            sceneView.drawGizmos   = false;
            sceneView.pivot        = new Vector3(0, 0, 0);
            sceneView.rotation     = Quaternion.AngleAxis(90f, Vector3.right);
            sceneView.size         = 2.0f;
            sceneView.Focus();

            var e = new Event();
            e.type = EventType.MouseEnterWindow;
            sceneView.SendEvent(e);

            Assume.That(pb.facesInternal.Length, Is.EqualTo(1));
            var face = pb.facesInternal[0];

            // Select face
            var selectedFaces = new List <Face>();
            selectedFaces.Add(face);
            Tools.current = Tool.Move;
            ProBuilderEditor.toolManager.SetSelectMode(SelectMode.Face);
            pb.SetSelectedFaces(selectedFaces);
            MeshSelection.SetSelection(pb.gameObject);

            // Center mouse position
            var bounds   = SceneView.focusedWindow.rootVisualElement.worldBound;
            var mousePos = (bounds.size * 0.5f + bounds.position) + new Vector2Int(1, 1);

            e = new UnityEngine.Event()
            {
                type          = EventType.MouseDown,
                mousePosition = mousePos,
                modifiers     = EventModifiers.None,
                clickCount    = 1,
                delta         = Vector2.zero,
            };
            sceneView.SendEvent(e);

            e = new UnityEngine.Event()
            {
                type          = EventType.MouseUp,
                mousePosition = mousePos,
                modifiers     = EventModifiers.None,
                clickCount    = 0,
                delta         = Vector2.zero,
            };
            sceneView.SendEvent(e);

            yield return(null);

            const int k_ExtrudeCount = 100;
            for (int i = 0; i < k_ExtrudeCount; i++)
            {
                // Press down at the center of the face
                e = new UnityEngine.Event()
                {
                    type          = EventType.MouseDown,
                    mousePosition = mousePos,
                    modifiers     = EventModifiers.None,
                    clickCount    = 1,
                    delta         = Vector2.zero,
                };
                sceneView.SendEvent(e);

                // Do lateral 1px drag and release
                var mouseDelta = new Vector2(i % 2 == 0 ? 1f : -1f, 0f);
                mousePos += mouseDelta;

                e.type          = EventType.MouseDrag;
                e.mousePosition = mousePos;
                e.modifiers     = EventModifiers.Shift;
                e.clickCount    = 0;
                e.delta         = mouseDelta;
                sceneView.SendEvent(e);

                e.type          = EventType.MouseUp;
                e.mousePosition = mousePos;
                e.delta         = Vector2.zero;
                sceneView.SendEvent(e);

                yield return(null);
            }

            // Check that our face count is correct after all extrusions
            Assume.That(pb.facesInternal.Length, Is.EqualTo(k_ExtrudeCount * 4 + 1));

            // We should have the last extruded face in selection
            var postExtrudeSelectedFaces = pb.GetSelectedFaces();
            Assume.That(postExtrudeSelectedFaces.Length, Is.EqualTo(1));
            var lastExtrudedFace = postExtrudeSelectedFaces[0];
            var faceVertices     = pb.GetVertices(lastExtrudedFace.indexes);

            // After many orthogonal extrusions, the last face should still be at y=0 coordinate
            for (int i = 0; i < faceVertices.Length; i++)
            {
                Assert.That(faceVertices[i].position.y, Is.EqualTo(0f));
            }
        }
        finally
        {
            UObject.DestroyImmediate(pb.gameObject);
        }
    }
Exemplo n.º 9
0
 public void AddToPool(ShapeGenerator mesh)
 {
     mesh.gameObject.SetActive(false);
     availableMesh.Add(mesh);
 }
Exemplo n.º 10
0
 public FaceMeshGenerator(FaceMeshData data, ShapeGenerator shapeGenerator)
 {
     this.data           = data;
     this.shapeGenerator = shapeGenerator;
 }
Exemplo n.º 11
0
    public Face Init(Transform parent, PlanetSettings settings, Directions direction, ShapeGenerator shapeGenerator)
    {
        planetSettings      = settings;
        Direction           = direction;
        this.shapeGenerator = shapeGenerator;

        if (parent != null)
        {
            transform.parent = parent;
        }

        if (meshFilter == null)
        {
            meshFilter      = gameObject.AddComponent <MeshFilter>();
            meshFilter.mesh = Mesh = new Mesh {
                name = "Procedural Face"
            };
        }

        if (meshRenderer == null)
        {
            meshRenderer = gameObject.AddComponent <MeshRenderer>();
        }

        meshGenerator = null;

        gameObject.name = direction.ToString();

        return(this);
    }
Exemplo n.º 12
0
 public void activateNext()
 {
     this.activeShape = this.nextShape;
     activeShape.MoveShapeToSpawn();
     this.nextShape = ShapeGenerator.GenerateShape(this.currentLevel);
 }
Exemplo n.º 13
0
 void Start()
 {
     shapeObjects   = new Dictionary <string, ShapeObject>();
     shapeGenerator = new ShapeGenerator(this);
 }
Exemplo n.º 14
0
        public void GenerateShapeFileTest()
        {
            var identification = new Identification
            {
                LocalId   = Guid.NewGuid(),
                NameSpace = "DataAccessTest",
                VersionId = "1.0"
            };

            var descriptionVariable1 = new DescriptionVariable
            {
                Code        = "descCode1",
                Description = "descDescription1",
                Surveyed    = new DateTime(2015, 9, 18, 19, 00, 00),
                Surveyer    = new Contact
                {
                    Company       = "Norconsult informasjonssystemer AS",
                    ContactPerson = "Magne Tøndel",
                    Email         = "*****@*****.**",
                    Phone         = "+4748164614",
                    Homesite      = "www.nois.no"
                },
                Value = "descValue1"
            };

            var descriptionVariable2 = new DescriptionVariable
            {
                Code        = "descCode2",
                Description = "descDescription2",
                Surveyed    = new DateTime(2015, 9, 18, 19, 00, 00),
                Surveyer    = new Contact
                {
                    Company       = "Norconsult informasjonssystemer AS",
                    ContactPerson = "Magne Tøndel",
                    Email         = "*****@*****.**",
                    Phone         = "+4748164614",
                    Homesite      = "www.nois.no"
                },
                Value = "descValue2"
            };

            var customVariable = new CustomVariable
            {
                Specification = "customSpecification",
                Value         = "customValue"
            };

            var natureAreaType = new NatureAreaType
            {
                Code = "naCode2",
                AdditionalVariables = new Collection <DescriptionVariable> {
                    descriptionVariable1, descriptionVariable2
                },
                CustomVariables = new Collection <CustomVariable>(),
                Share           = 0.5,
            };

            natureAreaType.AdditionalVariables.Add(descriptionVariable2);
            natureAreaType.CustomVariables.Add(customVariable);

            var natureArea = new NatureArea
            {
                UniqueId = identification,
                Version  = "2.0",
                Nivå     = NatureLevel.Natursystem,
                Area     = SqlGeometry.STGeomFromText(new SqlChars("POLYGON ((-11 55, -10 35, -5.5 36, -1 36, 1 38, 5 38, 11 38, 14 36, 26 33, 29 36, 26 39, 29 46, 39 47, 40 49, 27 56, 27 60, 25 60, 20 58, 21 56, 19 55, 11 55, 10 57, 7 57, 8 54, 3 53, -2 60, -8 58, -11 55))"), 25832),
                Surveyer = new Contact
                {
                    Company       = "Norconsult informasjonssystemer AS",
                    ContactPerson = "Magne Tøndel",
                    Email         = "*****@*****.**",
                    Phone         = "+4748164614",
                    Homesite      = "www.nois.no"
                },
                Surveyed    = new DateTime(2015, 9, 18, 19, 00, 00),
                Description = "Description",
                Parameters  = new List <Parameter>()
            };

            natureArea.Parameters.Add(descriptionVariable1);
            natureArea.Parameters.Add(natureAreaType);

            natureArea.Documents.Add(new Document
            {
                Title       = "NatureAreaDocumentOne",
                Description = "Description",
                Author      = new Contact
                {
                    Company       = "Norconsult informasjonssystemer AS",
                    ContactPerson = "Magne Tøndel",
                    Email         = "*****@*****.**",
                    Phone         = "+4748164614",
                    Homesite      = "www.nois.no"
                },
                FileName = "C:\\Document\\TestNatureAreaOne"
            });
            natureArea.Documents.Add(new Document
            {
                Title       = "NatureAreaDocumentTwo",
                Description = "Description",
                Author      = new Contact
                {
                    Company       = "Norconsult informasjonssystemer AS",
                    ContactPerson = "Magne Tøndel",
                    Email         = "*****@*****.**",
                    Phone         = "+4748164614",
                    Homesite      = "www.nois.no"
                },
                FileName = "C:\\Document\\TestNatureAreaTwo"
            });

            var memoryStream = ShapeGenerator.GenerateShapeFile(new Collection <NatureArea> {
                natureArea
            }, 25832);

            Assert.True(memoryStream.CanRead);
        }
Exemplo n.º 15
0
 public void UpdateTerrainChunk(TerrainChunk chunk)
 {
     shapeGenerator = new ShapeGenerator(shapeSettings);
     chunk.GenerateMesh(shapeGenerator, chunkSize, chunkDensity, surfaceHeight, interpolate);
     chunk.GenerateColors(colorSettings);
 }
Exemplo n.º 16
0
 public TerrainFace(ShapeGenerator shapeGenerator, Mesh mesh, int resolution, Vector3 localUp, Vector3 axisA, Vector3 axisB)
     : this(shapeGenerator, mesh, resolution, localUp)
 {
     this.axisA = axisA;
     this.axisB = axisB;
 }
Exemplo n.º 17
0
 public static GameObject CreateShape(PBShapeType shapeType)
 {
     return(ShapeGenerator.CreateShape((ShapeType)shapeType, PivotLocation.Center).gameObject);
 }
Exemplo n.º 18
0
        public void GenerateShapeTest()
        {
            GameShape textShape = ShapeGenerator.GenerateShape(1);

            Assert.IsTrue(textShape is GameShape);
        }
Exemplo n.º 19
0
    void Initialize()
    {
        //Si es la primera vez y hay variables a null se instancian
        if (shapeGenerator == null)
        {
            shapeGenerator  = new ShapeGenerator();
            colourGenerator = new ColourGenerator();
            floraGenerator  = new FloraGenerator();

            faces = new GameObject[6];
        }

        //Actualizamos las opciones
        shapeGenerator.UpdateSettings(shapeSettings);
        colourGenerator.UpdateSettings(colourSettings);

        if (floraSettings.generateFlora)
        {
            floraGenerator.UpdateSettings(floraSettings, transform);
        }

        //Si no hay mallas para cada cara se crean
        if (meshFilters == null || meshFilters.Length == 0)
        {
            meshFilters = new MeshFilter[6];
        }
        terrainFaces = new TerrainFace[6];

        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

        //Por cada cara creamos una malla y la colocamos en su posicion
        for (int i = 0; i < 6; i++)
        {
            if (meshFilters[i] == null)
            {
                faces[i] = new GameObject("face");

                if (i != 0)
                {
                    if (i != 1)
                    {
                        faces[i].transform.Rotate(Vector3.Cross(Vector3.up, directions[i]), 90);
                    }
                    else
                    {
                        faces[i].transform.Rotate(Vector3.Cross(Vector3.up, Vector3.right), 180);
                    }
                }
                faces[i].transform.parent = transform;

                GameObject meshObj = new GameObject("mesh");
                meshObj.transform.parent = faces[i].transform;
                if (transform.gameObject.layer == 0)
                {
                    meshObj.layer = 8;
                }
                else
                {
                    meshObj.layer = transform.gameObject.layer;
                }

                meshObj.AddComponent <MeshRenderer>();
                meshFilters[i]            = meshObj.AddComponent <MeshFilter>();
                meshFilters[i].sharedMesh = new Mesh();
            }

            meshFilters[i].GetComponent <MeshRenderer>().sharedMaterial = colourSettings.planetMaterial;

            terrainFaces[i] = new TerrainFace(shapeGenerator, meshFilters[i].sharedMesh, resolution, directions[i]);
            bool renderFace = faceRenderMask == FaceRenderMask.All || (int)faceRenderMask - 1 == i;
            meshFilters[i].gameObject.SetActive(renderFace);
        }
    }
Exemplo n.º 20
0
 public override ProBuilderMesh Build(bool preview = false)
 {
     return(ShapeGenerator.GeneratePrism(EditorUtility.newShapePivotLocation, s_PrismSize));
 }
Exemplo n.º 21
0
        /// <summary>
        /// Creates the sphere and loads all the cache information.
        /// </summary>
        void Start()
        {
            m_AudioSource = GetComponent <AudioSource>();

            if (m_AudioSource.clip == null)
            {
                missingClipWarning.SetActive(true);
            }

            // Create a new sphere.
            m_ProBuilderMesh = ShapeGenerator.GenerateIcosahedron(PivotLocation.Center, icoRadius, icoSubdivisions);

            // Assign the default material
            m_ProBuilderMesh.GetComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.defaultMaterial;

            // Shell is all the faces on the new sphere.
            var shell = m_ProBuilderMesh.faces;

            // Extrude all faces on the sphere by a small amount. The third boolean parameter
            // specifies that extrusion should treat each face as an individual, not try to group
            // all faces together.
            m_ProBuilderMesh.Extrude(shell, ExtrudeMethod.IndividualFaces, startingExtrusion);

            // ToMesh builds the mesh positions, submesh, and triangle arrays. Call after adding
            // or deleting vertices, or changing face properties.
            m_ProBuilderMesh.ToMesh();

            // Refresh builds the normals, tangents, and UVs.
            m_ProBuilderMesh.Refresh();

            m_AnimatedSelections = new ExtrudedSelection[shell.Count];

            // Populate the outsides[] cache. This is a reference to the tops of each extruded column, including
            // copies of the sharedIndices.
            for (int i = 0; i < shell.Count; ++i)
            {
                m_AnimatedSelections[i] = new ExtrudedSelection(m_ProBuilderMesh, shell[i]);
            }

            // Store copy of positions array un-modified
            m_OriginalVertexPositions = m_ProBuilderMesh.positions.ToArray();

            // displaced_vertices should mirror sphere mesh vertices.
            m_DisplacedVertexPositions = new Vector3[m_ProBuilderMesh.vertexCount];

            m_UnityMesh = m_ProBuilderMesh.GetComponent <MeshFilter>().sharedMesh;
            m_Transform = m_ProBuilderMesh.transform;

            m_FaceLength = (float)m_AnimatedSelections.Length;

            // Build the waveform ring.
            m_StartingPosition = m_Transform.position;

            waveform.positionCount = k_WaveformSampleCount;

            if (bounceWaveform)
            {
                waveform.transform.parent = m_Transform;
            }

            m_AudioSource.Play();
        }