예제 #1
0
        public HeightPyramidSegmentShapeGroup CreateGroup(HeightPyramidLevelTemplate pyramidLevelTemplate, HeightPyramidLevel level, GameObject pyramidRootGo)
        {
            var parentGO = new GameObject("ETerrainParent " + level);
            var center   = pyramidLevelTemplate.Center;

            parentGO.transform.localPosition = new Vector3(center.x, 0, center.y);

            var ringTemplateElementMesh = _meshGenerator.AddOrder(() =>
                                                                  PlaneGenerator.CreateETerrainSegmentMesh(_perLevelConfiguration.RingObjectMeshVertexLength.X, _perLevelConfiguration.RingObjectMeshVertexLength.Y))
                                          .Result; //todo
            var centerMesh = _meshGenerator.AddOrder(() =>
                                                     PlaneGenerator.CreateETerrainSegmentMesh(_perLevelConfiguration.CenterObjectMeshVertexLength.X, _perLevelConfiguration.CenterObjectMeshVertexLength.Y))
                             .Result; //todo

            var shapeMeshesToCombine = new List <CombineInstance>();

            foreach (var shapeTemplate in pyramidLevelTemplate.ShapeTemplates)
            {
                Mesh thisSegmentMesh = null;
                if (shapeTemplate.RingIndex == 0) //center
                {
                    thisSegmentMesh = centerMesh;
                }
                else
                {
                    thisSegmentMesh = ringTemplateElementMesh;
                }

                var trs = CreateTrsMatrixForShape(shapeTemplate);
                shapeMeshesToCombine.Add(new CombineInstance()
                {
                    transform = trs,
                    mesh      = thisSegmentMesh
                });
            }

            var finalMesh = _meshGenerator.AddOrder(() =>
            {
                var m = MeshGenerationUtils.CreateMeshAsSum(shapeMeshesToCombine);
                MeshGenerationUtils.RecalculateUvAsInPlane(m);
                return(m);
            }).Result; //TODO

            MeshGenerationUtils.SetYBoundsToInfinity(finalMesh);

            var mainObject = CreateShapeObject(finalMesh, "MainObject", center, pyramidLevelTemplate.FlatSize);

            mainObject.transform.SetParent(parentGO.transform);

            parentGO.transform.localScale = new Vector3(1, _commonConfiguration.YScale, 1);
            parentGO.transform.SetParent(pyramidRootGo.transform);
            return(new HeightPyramidSegmentShapeGroup()
            {
                CentralShape = mainObject,
                ParentGameObject = parentGO,
            });
        }
예제 #2
0
        public HeightPyramidSegmentShapeGroup CreateGroup(HeightPyramidLevelTemplate pyramidLevelTemplate, HeightPyramidLevel level, GameObject pyramidRootGo)
        {
            var parentGO = new GameObject("ETerrainParent " + level);
            var center   = pyramidLevelTemplate.Center;

            parentGO.transform.localPosition = new Vector3(center.x, 0, center.y);

            var objectsPerRing = pyramidLevelTemplate.PerRingTemplates.Keys.ToDictionary(c => c, c => new List <GameObject>());

            GameObject centerObject = null;

            var ring1ElementMesh =
                _meshGenerator.AddOrder(() => PlaneGenerator.CreateETerrainSegmentMesh(
                                            _perLevelConfiguration.RingObjectMeshVertexLength.X, _perLevelConfiguration.RingObjectMeshVertexLength.Y)).Result; //todo

            ring1ElementMesh.RecalculateBounds();
            MeshGenerationUtils.SetYBounds(ring1ElementMesh, 0f, 1f);
            foreach (var shapeTemplate in pyramidLevelTemplate.ShapeTemplates)
            {
                if (shapeTemplate.RingIndex == 0) //center
                {
                    var centerMesh = _meshGenerator.AddOrder(() =>
                                                             PlaneGenerator.CreateETerrainSegmentMesh(_perLevelConfiguration.CenterObjectMeshVertexLength.X,
                                                                                                      _perLevelConfiguration.CenterObjectMeshVertexLength.Y))
                                     .Result; //todo
                    MeshGenerationUtils.SetYBounds(centerMesh, 0f, 1f);
                    centerObject = CreateShapeObject(centerMesh, shapeTemplate, "Center");

                    centerObject.transform.SetParent(parentGO.transform);
                }
                else
                {
                    var shape = CreateShapeObject(ring1ElementMesh, shapeTemplate, "Ring " + shapeTemplate.RingIndex);
                    shape.transform.SetParent(parentGO.transform);
                    objectsPerRing[shapeTemplate.RingIndex].Add(shape);
                }
            }

            parentGO.transform.localScale = new Vector3(1, _commonConfiguration.YScale, 1);
            parentGO.transform.SetParent(pyramidRootGo.transform);
            return(new HeightPyramidSegmentShapeGroup()
            {
                CentralShape = centerObject,
                ParentGameObject = parentGO,
                ShapesPerRing = objectsPerRing
            });
        }