示例#1
0
        public void Validate()
        {
            if (!IsValid)
            {
                return;
            }

            if (brushOutline.polygons == null)
            {
                return;
            }

            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            surfaceDefinition.EnsureSize(brushOutline.polygons.Length);

            // Temporary fix for misformed brushes
            for (int i = 0; i < brushOutline.polygons.Length; i++)
            {
                brushOutline.polygons[i].surfaceID = i;
            }
            brushOutline.CalculatePlanes();
        }
示例#2
0
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            stepHeight = Mathf.Max(kMinStepHeight, stepHeight);

            innerDiameter = Mathf.Min(outerDiameter - kMinStairsDepth, innerDiameter);
            innerDiameter = Mathf.Max(kMinInnerDiameter, innerDiameter);
            outerDiameter = Mathf.Max(innerDiameter + kMinStairsDepth, outerDiameter);
            outerDiameter = Mathf.Max(kMinOuterDiameter, outerDiameter);
            height        = Mathf.Max(stepHeight, Mathf.Abs(height)) * (height < 0 ? -1 : 1);
            treadHeight   = Mathf.Max(0, treadHeight);
            nosingDepth   = Mathf.Max(0, nosingDepth);
            nosingWidth   = Mathf.Max(0, nosingWidth);

            riserDepth = Mathf.Max(kMinRiserDepth, riserDepth);

            rotation = Mathf.Max(kMinRotation, Mathf.Abs(rotation)) * (rotation < 0 ? -1 : 1);

            innerSegments = Mathf.Max(kMinSegments, innerSegments);
            outerSegments = Mathf.Max(kMinSegments, outerSegments);

            surfaceDefinition.EnsureSize(8);
        }
示例#3
0
 public void Validate()
 {
     if (surfaceDefinition == null)
     {
         surfaceDefinition = new ChiselSurfaceDefinition();
     }
     surfaceDefinition.EnsureSize(6);
 }
示例#4
0
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            if (surfaceDefinition.EnsureSize((int)SurfaceSides.TotalSides))
            {
                var defaultRenderMaterial  = ChiselMaterialManager.DefaultWallMaterial;
                var defaultPhysicsMaterial = ChiselMaterialManager.DefaultPhysicsMaterial;

                surfaceDefinition.surfaces[(int)SurfaceSides.Top].brushMaterial    = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultFloorMaterial, defaultPhysicsMaterial);
                surfaceDefinition.surfaces[(int)SurfaceSides.Bottom].brushMaterial = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultFloorMaterial, defaultPhysicsMaterial);
                surfaceDefinition.surfaces[(int)SurfaceSides.Left].brushMaterial   = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial);
                surfaceDefinition.surfaces[(int)SurfaceSides.Right].brushMaterial  = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial);
                surfaceDefinition.surfaces[(int)SurfaceSides.Front].brushMaterial  = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial);
                surfaceDefinition.surfaces[(int)SurfaceSides.Back].brushMaterial   = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial);
                surfaceDefinition.surfaces[(int)SurfaceSides.Tread].brushMaterial  = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultTreadMaterial, defaultPhysicsMaterial);
                surfaceDefinition.surfaces[(int)SurfaceSides.Step].brushMaterial   = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultStepMaterial, defaultPhysicsMaterial);

                for (int i = 0; i < surfaceDefinition.surfaces.Length; i++)
                {
                    if (surfaceDefinition.surfaces[i].brushMaterial == null)
                    {
                        surfaceDefinition.surfaces[i].brushMaterial = ChiselBrushMaterial.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial);
                    }
                }
            }


            stepHeight  = Mathf.Max(kMinStepHeight, stepHeight);
            stepDepth   = Mathf.Clamp(stepDepth, kMinStepDepth, absDepth);
            treadHeight = Mathf.Max(0, treadHeight);
            nosingDepth = Mathf.Max(0, nosingDepth);
            nosingWidth = Mathf.Max(0, nosingWidth);

            width = Mathf.Max(kMinWidth, absWidth) * (width < 0 ? -1 : 1);
            depth = Mathf.Max(stepDepth, absDepth) * (depth < 0 ? -1 : 1);

            riserDepth = Mathf.Max(kMinRiserDepth, riserDepth);
            sideDepth  = Mathf.Max(0, sideDepth);
            sideWidth  = Mathf.Max(kMinSideWidth, sideWidth);
            sideHeight = Mathf.Max(0, sideHeight);

            var realHeight       = Mathf.Max(stepHeight, absHeight);
            var maxPlateauHeight = realHeight - stepHeight;

            plateauHeight = Mathf.Clamp(plateauHeight, 0, maxPlateauHeight);

            var totalSteps      = Mathf.Max(1, Mathf.FloorToInt((realHeight - plateauHeight + kStepSmudgeValue) / stepHeight));
            var totalStepHeight = totalSteps * stepHeight;

            plateauHeight = Mathf.Max(0, realHeight - totalStepHeight);
            stepDepth     = Mathf.Clamp(stepDepth, kMinStepDepth, absDepth / totalSteps);
        }
        public void Validate()
        {
            if (!IsValid)
            {
                return;
            }

            if (version != kLatestVersion)
            {
                version           = kLatestVersion;
                surfaceDefinition = null;
            }

            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
                surfaceDefinition.EnsureSize(brushOutline.polygons.Length);
                if (brushOutline.polygons.Length > 0)
                {
                    for (int p = 0; p < brushOutline.polygons.Length; p++)
                    {
                        surfaceDefinition.surfaces[p].surfaceDescription = brushOutline.polygons[p].surface.surfaceDescription;
                        surfaceDefinition.surfaces[p].brushMaterial      = brushOutline.polygons[p].surface.brushMaterial;
                    }
                }
            }
            else
            {
                surfaceDefinition.EnsureSize(brushOutline.polygons.Length);
            }

            // Temporary fix for misformed brushes
            for (int i = 0; i < brushOutline.polygons.Length; i++)
            {
                brushOutline.polygons[i].surfaceID = i;
            }

            brushOutline.CalculatePlanes();

            // If the brush is concave, we set the generator to not be valid, so that when we commit, it will be reverted
            validState = brushOutline.HasVolume() &&            // TODO: implement this, so we know if a brush is a 0D/1D/2D shape
                         !brushOutline.IsConcave() &&           // TODO: eventually allow concave shapes
                         !brushOutline.IsSelfIntersecting();    // TODO: in which case this needs to be implemented

            // TODO: shouldn't do this all the time:
            {
                // Detect if outline is inside-out and if so, just invert all polygons.
                isInsideOut = brushOutline.IsInsideOut();
                if (isInsideOut)
                {
                    brushOutline.Invert();
                    isInsideOut = false;
                }
            }
        }
示例#6
0
        public void UpdateSurfaces(ref ChiselSurfaceDefinition surfaceDefinition)
        {
            if (surfaceDefinition.surfaces == null ||
                surfaceDefinition.surfaces.Length == 0)
            {
                return;
            }

            for (int p = 0; p < brushOutline.polygons.Length; p++)
            {
                brushOutline.polygons[p].descriptionIndex = p;
            }
        }
示例#7
0
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            curveSegments   = Mathf.Max(curveSegments, 2);
            revolveSegments = Mathf.Max(revolveSegments, 1);

            totalAngle = Mathf.Clamp(totalAngle, 1, 360);                  // TODO: constants

            surfaceDefinition.EnsureSize(6);
        }
示例#8
0
        public Vector3 CenterAndSnapPlanes(ref ChiselSurfaceDefinition surfaceDefinition)
        {
            Profiler.BeginSample("CenterAndSnapPlanes");

            /*
             * for (int p = 0; p < polygons.Length; p++)
             * {
             *  var plane       = planes[p];
             *  var edgeFirst   = polygons[p].firstEdge;
             *  var edgeLast    = edgeFirst + polygons[p].edgeCount;
             *  for (int e = edgeFirst; e < edgeLast; e++)
             *  {
             *      var vertexIndex = halfEdges[e].vertexIndex;
             *      vertices[vertexIndex] = (float3)MathExtensions.ProjectPointPlane(vertices[vertexIndex], plane);
             *  }
             * }
             */

            var dmin = (double3)vertices[0];
            var dmax = dmin;

            for (int i = 1; i < vertices.Length; i++)
            {
                dmin = math.min(dmin, vertices[i]);
                dmax = math.max(dmax, vertices[i]);
            }

            var center = (float3)((dmin + dmax) * 0.5);

            var translate = float4x4.Translate(center);

            for (int i = 0; i < polygons.Length; i++)
            {
                ref var surface = ref surfaceDefinition.surfaces[i];

                var localSpaceToPlaneSpace = MathExtensions.GenerateLocalToPlaneSpaceMatrix(planes[i]);
                var originalUVMatrix       = surface.surfaceDescription.UV0.ToFloat4x4();

                planes[i].w += math.dot(planes[i].xyz, center);

                var translatedPlaneSpaceToLocalSpace = math.inverse(MathExtensions.GenerateLocalToPlaneSpaceMatrix(planes[i]));
                var newUVMatrix = math.mul(math.mul(math.mul(
                                                        originalUVMatrix,
                                                        localSpaceToPlaneSpace),
                                                    translate),
                                           translatedPlaneSpaceToLocalSpace);

                surface.surfaceDescription.UV0 = new UVMatrix(newUVMatrix);
            }
示例#9
0
        public void UpdateSurfaces(ref ChiselSurfaceDefinition surfaceDefinition)
        {
            UnityEngine.Material       defaultFloorMaterial   = null;
            UnityEngine.Material       defaultWallMaterial    = null;
            UnityEngine.PhysicMaterial defaultPhysicsMaterial = null;

            var surfaces = surfaceDefinition.surfaces;

            if (surfaces[(int)SurfaceSides.Top].brushMaterial == null)
            {
                surfaces[(int)SurfaceSides.Top].brushMaterial = ChiselBrushMaterial.CreateInstance(defaultFloorMaterial ??= ChiselMaterialManager.DefaultFloorMaterial, defaultPhysicsMaterial ??= ChiselMaterialManager.DefaultPhysicsMaterial);
            }
            if (surfaces[(int)SurfaceSides.Bottom].brushMaterial == null)
            {
                surfaces[(int)SurfaceSides.Bottom].brushMaterial = ChiselBrushMaterial.CreateInstance(defaultFloorMaterial ??= ChiselMaterialManager.DefaultFloorMaterial, defaultPhysicsMaterial ??= ChiselMaterialManager.DefaultPhysicsMaterial);
            }
            if (surfaces[(int)SurfaceSides.Left].brushMaterial == null)
            {
                surfaces[(int)SurfaceSides.Left].brushMaterial = ChiselBrushMaterial.CreateInstance(defaultWallMaterial ??= ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial ??= ChiselMaterialManager.DefaultPhysicsMaterial);
            }
            if (surfaces[(int)SurfaceSides.Right].brushMaterial == null)
            {
                surfaces[(int)SurfaceSides.Right].brushMaterial = ChiselBrushMaterial.CreateInstance(defaultWallMaterial ??= ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial ??= ChiselMaterialManager.DefaultPhysicsMaterial);
            }
            if (surfaces[(int)SurfaceSides.Front].brushMaterial == null)
            {
                surfaces[(int)SurfaceSides.Front].brushMaterial = ChiselBrushMaterial.CreateInstance(defaultWallMaterial ??= ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial ??= ChiselMaterialManager.DefaultPhysicsMaterial);
            }
            if (surfaces[(int)SurfaceSides.Back].brushMaterial == null)
            {
                surfaces[(int)SurfaceSides.Back].brushMaterial = ChiselBrushMaterial.CreateInstance(defaultWallMaterial ??= ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial ??= ChiselMaterialManager.DefaultPhysicsMaterial);
            }
            if (surfaces[(int)SurfaceSides.Tread].brushMaterial == null)
            {
                surfaces[(int)SurfaceSides.Tread].brushMaterial = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultTreadMaterial, defaultPhysicsMaterial);
            }
            if (surfaces[(int)SurfaceSides.Step].brushMaterial == null)
            {
                surfaces[(int)SurfaceSides.Step].brushMaterial = ChiselBrushMaterial.CreateInstance(ChiselMaterialManager.DefaultStepMaterial, defaultPhysicsMaterial);
            }

            for (int i = 0; i < surfaceDefinition.surfaces.Length; i++)
            {
                if (surfaceDefinition.surfaces[i].brushMaterial == null)
                {
                    surfaceDefinition.surfaces[i].brushMaterial = ChiselBrushMaterial.CreateInstance(defaultWallMaterial ??= ChiselMaterialManager.DefaultWallMaterial, defaultPhysicsMaterial ??= ChiselMaterialManager.DefaultPhysicsMaterial);
                }
            }
        }
示例#10
0
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            if (shape == null)
            {
                shape = new Curve2D(kDefaultShape);
            }

            int sides = shape.controlPoints.Length;

            surfaceDefinition.EnsureSize(2 + sides);
        }
示例#11
0
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            diameterXYZ.x = Mathf.Max(kMinDiameter, Mathf.Abs(diameterXYZ.x));
            diameterXYZ.y = Mathf.Max(0, Mathf.Abs(diameterXYZ.y)) * (diameterXYZ.y < 0 ? -1 : 1);
            diameterXYZ.z = Mathf.Max(kMinDiameter, Mathf.Abs(diameterXYZ.z));

            horizontalSegments = Mathf.Max(horizontalSegments, 3);
            verticalSegments   = Mathf.Max(verticalSegments, 1);

            surfaceDefinition.EnsureSize(6);
        }
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            tubeWidth     = Mathf.Max(tubeWidth, kMinTubeDiameter);
            tubeHeight    = Mathf.Max(tubeHeight, kMinTubeDiameter);
            outerDiameter = Mathf.Max(outerDiameter, tubeWidth * 2);

            horizontalSegments = Mathf.Max(horizontalSegments, 3);
            verticalSegments   = Mathf.Max(verticalSegments, 3);

            totalAngle = Mathf.Clamp(totalAngle, 1, 360);                  // TODO: constants

            surfaceDefinition.EnsureSize(6);
        }
        public void Validate()
        {
            if (!IsValid)
            {
                return;
            }

            if (brushOutline.polygons == null)
            {
                return;
            }

            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            surfaceDefinition.EnsureSize(brushOutline.polygons.Length);
        }
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            topHeight    = Mathf.Max(topHeight, 0);
            bottomHeight = Mathf.Max(bottomHeight, 0);
            height       = Mathf.Max(topHeight + bottomHeight, Mathf.Abs(height)) * (height < 0 ? -1 : 1);

            diameterX = Mathf.Max(Mathf.Abs(diameterX), kMinDiameter);
            diameterZ = Mathf.Max(Mathf.Abs(diameterZ), kMinDiameter);

            topSegments    = Mathf.Max(topSegments, 0);
            bottomSegments = Mathf.Max(bottomSegments, 0);
            sides          = Mathf.Max(sides, 3);

            surfaceDefinition.EnsureSize(2 + sides);
        }
示例#15
0
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            topLength    = Mathf.Max(topLength, 0);
            bottomLength = Mathf.Max(bottomLength, 0);
            length       = Mathf.Max(Mathf.Abs(length), (haveRoundedTop ? topLength : 0) + (haveRoundedBottom ? bottomLength : 0));
            length       = Mathf.Max(Mathf.Abs(length), kMinLength);

            height   = Mathf.Max(Mathf.Abs(height), kMinHeight);
            diameter = Mathf.Max(Mathf.Abs(diameter), kMinDiameter);

            topSides    = Mathf.Max(topSides, 1);
            bottomSides = Mathf.Max(bottomSides, 1);

            var sides = 2 + Mathf.Max(topSides, 1) + Mathf.Max(bottomSides, 1);

            surfaceDefinition.EnsureSize(2 + sides);
        }
示例#16
0
        public void Validate()
        {
            if (surfaceDefinition == null)
            {
                surfaceDefinition = new ChiselSurfaceDefinition();
            }

            topDiameterX    = Mathf.Abs(topDiameterX);
            topDiameterZ    = Mathf.Abs(topDiameterZ);
            bottomDiameterX = Mathf.Abs(bottomDiameterX);
            bottomDiameterZ = Mathf.Abs(bottomDiameterZ);

            sides = Mathf.Max(3, sides);

            if (surfaceDefinition.EnsureSize(2 + sides))
            {
                // Top plane
                surfaceDefinition.surfaces[0].surfaceDescription.UV0 = UVMatrix.centered;

                // Bottom plane
                surfaceDefinition.surfaces[1].surfaceDescription.UV0 = UVMatrix.centered;

                float radius     = topDiameterX * 0.5f;
                float angle      = (360.0f / sides);
                float sideLength = (2 * Mathf.Sin((angle / 2.0f) * Mathf.Deg2Rad)) * radius;

                // Side planes
                for (int i = 2; i < 2 + sides; i++)
                {
                    var uv0 = UVMatrix.identity;
                    uv0.U.w = ((i - 2) + 0.5f) * sideLength;
                    // TODO: align with bottom
                    //uv0.V.w = 0.5f;
                    surfaceDefinition.surfaces[i].surfaceDescription.UV0            = uv0;
                    surfaceDefinition.surfaces[i].surfaceDescription.smoothingGroup = smoothingGroup;
                }
            }
        }
示例#17
0
 public void UpdateSurfaces(ref ChiselSurfaceDefinition surfaceDefinition)
 {
 }
 public virtual void UpdateSurfaces(ref ChiselSurfaceDefinition surfaceDefinition)
 {
     settings.UpdateSurfaces(ref surfaceDefinition);
 }