Exemplo n.º 1
0
        public override void CalcBounds()
        {
            bounds.Center = Vector3.zero;
            bounds.Size   = Size;
            var minY   = -Size.y / 2;
            var maxY   = Size.y / 2;
            var minX   = float.MaxValue;
            var maxX   = float.MinValue;
            var minZ   = float.MaxValue;
            var maxZ   = float.MinValue;
            var points = new Vector3[]
            {
                new Vector3(Size.x / 2, 0, Size.z / 2),
                new Vector3(-Size.x / 2, 0, -Size.z / 2),
                new Vector3(-Size.x / 2, 0, Size.z / 2),
                new Vector3(Size.x / 2, 0, -Size.z / 2)
            };

            for (int i = 0; i < points.Length; i++)
            {
                points[i] = Quaternion * points[i];
                minX      = Mathf.Min(minX, points[i].x);
                maxX      = Mathf.Max(maxX, points[i].x);
                minZ      = Mathf.Min(minZ, points[i].z);
                maxZ      = Mathf.Max(maxZ, points[i].z);
            }
            bounds.Min    = new Vector3(minX, minY, minZ);
            bounds.Max    = new Vector3(maxX, maxY, maxZ);
            bounds.Center = Position;
        }
Exemplo n.º 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);
        }
        public void Validate()
        {
            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


            if (surfaceAssets == null ||
                surfaceAssets.Length != 6)
            {
                var defaultRenderMaterial  = CSGMaterialManager.DefaultWallMaterial;
                var defaultPhysicsMaterial = CSGMaterialManager.DefaultPhysicsMaterial;
                surfaceAssets = new CSGSurfaceAsset[6]
                {
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial)
                };
            }

            if (surfaceDescriptions == null ||
                surfaceDescriptions.Length != 6)
            {
                // TODO: make this independent on plane position somehow
                var surfaceFlags = CSGDefaults.SurfaceFlags;
                surfaceDescriptions = new SurfaceDescription[6]
                {
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }
                };
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
        public void Validate()
        {
            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);

            if (surfaceAssets == null ||
                surfaceAssets.Length != 6)
            {
                var defaultRenderMaterial  = CSGMaterialManager.DefaultWallMaterial;
                var defaultPhysicsMaterial = CSGMaterialManager.DefaultPhysicsMaterial;
                surfaceAssets = new CSGSurfaceAsset[6]
                {
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial)
                };
            }

            if (surfaceDescriptions == null ||
                surfaceDescriptions.Length != 6)
            {
                // TODO: make this independent on plane position somehow
                var surfaceFlags = CSGDefaults.SurfaceFlags;
                surfaceDescriptions = new SurfaceDescription[6]
                {
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }
                };
            }
        }
Exemplo n.º 6
0
        public void Validate()
        {
            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);

            if (surfaceAssets == null ||
                surfaceAssets.Length != 6)
            {
                var defaultRenderMaterial  = CSGMaterialManager.DefaultWallMaterial;
                var defaultPhysicsMaterial = CSGMaterialManager.DefaultPhysicsMaterial;
                surfaceAssets = new CSGSurfaceAsset[6];
                for (int i = 0; i < 6; i++) // Note: sides share same material
                {
                    surfaceAssets[i] = CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial);
                }
            }

            if (surfaceDescriptions == null ||
                surfaceDescriptions.Length != 6)
            {
                var surfaceFlags = CSGDefaults.SurfaceFlags;
                surfaceDescriptions = new SurfaceDescription[6];
                for (int i = 0; i < 6; i++)
                {
                    surfaceDescriptions[i] = new SurfaceDescription {
                        surfaceFlags = surfaceFlags, UV0 = UVMatrix.centered, smoothingGroup = bottomSmoothingGroup
                    };
                }
            }
            else
            {
                for (int i = 0; i < 6; i++)
                {
                    surfaceDescriptions[i].smoothingGroup = bottomSmoothingGroup;
                }
            }
        }
Exemplo n.º 7
0
        public void Validate()
        {
            curveSegments   = Mathf.Max(curveSegments, 2);
            revolveSegments = Mathf.Max(revolveSegments, 1);

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

            if (surfaceAssets == null ||
                surfaceAssets.Length != 6)
            {
                var defaultRenderMaterial  = CSGMaterialManager.DefaultWallMaterial;
                var defaultPhysicsMaterial = CSGMaterialManager.DefaultPhysicsMaterial;
                surfaceAssets = new CSGSurfaceAsset[6]
                {
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial)
                };
            }

            if (surfaceDescriptions == null ||
                surfaceDescriptions.Length != 6)
            {
                // TODO: make this independent on plane position somehow
                var surfaceFlags = CSGDefaults.SurfaceFlags;
                surfaceDescriptions = new SurfaceDescription[6]
                {
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }
                };
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="crowdAgentConfig">
        /// The default agent configuration for  all agents in the group.
        /// </param>
        /// <param name="maxPathSize">The default maximum path size. [Limit: >= 1]</param>
        /// <param name="maxStraightPathSize">
        /// The default maximum straight path size. [Limit: >= 1]
        /// </param>
        /// <param name="maxPoolCorridors">
        /// The maximum number of corridors to allowed in the corridor pool. [Limit: >= 0]
        /// </param>
        /// <param name="maxPoolPaths">
        /// The maximum number of paths to allow in the path pool. [Limit: >= 0]
        /// </param>
        public NavAgentGroup(CrowdAgentParams crowdAgentConfig
                             , int maxPathSize, int maxStraightPathSize, int maxPoolCorridors, int maxPoolPaths)
        {
            mMaxStraightPathSize = Mathf.Max(1, maxStraightPathSize);
            mMaxPathSize         = Mathf.Max(1, maxPathSize);

            this.crowdAgentConfig = crowdAgentConfig;
            this.pathBuffer       = new uint[maxPathSize];

            mMaxCorridors = Mathf.Max(0, maxPoolCorridors);
            mCorridors    = new Stack <PathCorridor>(mMaxCorridors);

            mMaxPaths = Mathf.Max(0, maxPoolPaths);
            mPaths    = new Stack <NavPath>(mMaxPaths);
        }
Exemplo n.º 10
0
        public static float Clamp(float x, float limit1, float limit2)
        {
            float max = Mathf.Max(limit1, limit2);
            float min = Mathf.Min(limit1, limit2);

            if (x < min)
            {
                return(min);
            }
            if (x > max)
            {
                return(max);
            }
            return(x);
        }
Exemplo n.º 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);
        }
Exemplo n.º 12
0
        private void PositionalCorrection(XContact contact)
        {
            var a  = contact.src;
            var b  = contact.dst;
            var tm = a.rigidbody.InverseMass + b.rigidbody.InverseMass;

            if (tm == 0)
            {
                return;
            }
            float   percent    = 0.2f;
            float   slop       = 0.01f;
            Vector3 correction = Mathf.Max(contact.penetration - slop, 0) / tm * percent * contact.normal;

            a.Position = a.rigidbody.position -= a.rigidbody.InverseMass * correction;
            b.Position = b.rigidbody.position += b.rigidbody.InverseMass * correction;
        }
        // TODO: remove all stairs specific parameters
        static void GenerateTopRamp(CSGBrushSubMesh[] subMeshes, int startIndex, int stepCount, Vector3 min, Vector3 max, Vector3 extrusion, float sideHeight, float extraDepth, float maxDepth, StairsRiserType riserType, CSGLinearStairsDefinition definition, CSGSurfaceAsset[] surfaceAssets, SurfaceDescription[] surfaceDescriptions)
        {
            //var diffY			= (max.y - min.y);
            //var diffZ			= (max.z - min.z);
            //var aspect		= diffY / diffZ;
            var diagonalHeight = sideHeight + definition.treadHeight; //Mathf.Max(sideHeight + definition.treadHeight, (aspect * (riserDepth)));// + definition.nosingDepth)) + definition.treadHeight;

            for (int i = 0, j = startIndex; i < stepCount; i++, j++)
            {
                var topY    = max.y + diagonalHeight;
                var bottomY = min.y;
                var middleY = (bottomY + diagonalHeight);            // - (lastStep ? (riserDepth * aspect) : 0);
                var rightZ  = Mathf.Max(maxDepth, max.z);            // + (lastStep ? riserDepth : 0);
                var leftZ   = Mathf.Max(maxDepth, min.z);

                //            topY leftZ
                //          0    4
                //           *--*
                //           |   \
                //           |    \
                //  lefterZ  |     \ 3
                //           |      *
                //           |      |   rightZ
                //           *------*
                //          1        2
                //            bottomY
                var lefterZ  = (i == 0 || (riserType == StairsRiserType.FillDown)) ? maxDepth : Mathf.Max(maxDepth, leftZ - extraDepth);
                var vertices = new[] {
                    new Vector3(min.x, topY, lefterZ),                     // 0
                    new Vector3(min.x, bottomY, lefterZ),                  // 1
                    new Vector3(min.x, bottomY, rightZ),                   // 2
                    new Vector3(min.x, middleY, rightZ),                   // 3
                    new Vector3(min.x, topY, leftZ),                       // 4
                };

                CreateExtrudedSubMesh(subMeshes[j + 0], vertices, extrusion,
                                      new int[] { 0, 1, 2, 3, 3, 3, 3 }, // TODO: fix this
                                      new int[] { 0, 1, 2, 2, 2, 2, 2 }, // TODO: fix this
                                      surfaceAssets, surfaceDescriptions);

                min.z += definition.stepDepth;
                max.z += definition.stepDepth;
                min.y -= definition.stepHeight;
                max.y -= definition.stepHeight;
            }
        }
Exemplo n.º 14
0
        public void Validate()
        {
            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);
            int kMinSurfaceAssets = 2 + sides;

            if (surfaceAssets == null ||
                surfaceAssets.Length != kMinSurfaceAssets)
            {
                var defaultRenderMaterial  = CSGMaterialManager.DefaultWallMaterial;
                var defaultPhysicsMaterial = CSGMaterialManager.DefaultPhysicsMaterial;
                surfaceAssets = new CSGSurfaceAsset[kMinSurfaceAssets];
                for (int a = 0; a < kMinSurfaceAssets; a++)
                {
                    surfaceAssets[a] = CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial);
                }
            }

            int kMinSurfaceDescriptions = 2 + sides;

            if (surfaceDescriptions == null ||
                surfaceDescriptions.Length != kMinSurfaceDescriptions)
            {
                // TODO: make this independent on plane position somehow
                var surfaceFlags = CSGDefaults.SurfaceFlags;
                surfaceDescriptions = new SurfaceDescription[kMinSurfaceDescriptions];
                for (int s = 0; s < kMinSurfaceDescriptions; s++)
                {
                    surfaceDescriptions[s] = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }
                }
                ;
            }
        }
    }
Exemplo n.º 15
0
        private static bool ProjectOverlapTest(Vector3 axis, Vector3[] srcPoints, Vector3[] dstPoints, out float overlap)
        {
            float srcMin = float.MaxValue;
            float dstMin = float.MaxValue;
            float srcMax = float.MinValue;
            float dstMax = float.MinValue;

            for (int i = 0; i < srcPoints.Length; i++)
            {
                var p = Vector3.Dot(axis, srcPoints[i]);
                if (p < srcMin)
                {
                    srcMin = p;
                }
                if (p > srcMax)
                {
                    srcMax = p;
                }
            }
            for (int i = 0; i < dstPoints.Length; i++)
            {
                var p = Vector3.Dot(axis, dstPoints[i]);
                if (p < dstMin)
                {
                    dstMin = p;
                }
                if (p > dstMax)
                {
                    dstMax = p;
                }
            }
            if (srcMax < dstMin || srcMin > dstMax)
            {
                overlap = 0;
                return(false);
            }
            overlap = Mathf.Min(srcMax, dstMax) - Mathf.Max(srcMin, dstMin);
            if ((srcMax > dstMax && srcMin < dstMin) || (srcMax < dstMax && srcMin > dstMin))
            {
                var min = Mathf.Abs(srcMin - dstMin);
                var max = Mathf.Abs(srcMax - dstMax);
                overlap += Mathf.Min(min, max);
            }
            return(true);
        }
        public void Validate()
        {
            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);

            var minSurfaceAssets = 2 + sides;

            if (surfaceAssets == null ||
                surfaceAssets.Length != minSurfaceAssets)
            {
                var defaultRenderMaterial  = CSGMaterialManager.DefaultWallMaterial;
                var defaultPhysicsMaterial = CSGMaterialManager.DefaultPhysicsMaterial;
                surfaceAssets = new CSGSurfaceAsset[minSurfaceAssets];
                for (int a = 0; a < minSurfaceAssets; a++)
                {
                    surfaceAssets[a] = CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial);
                }
            }

            var minSurfaceDescriptions = 2 + sides;

            if (surfaceDescriptions == null ||
                surfaceDescriptions.Length != minSurfaceDescriptions)
            {
                // TODO: make this independent on plane position somehow
                var surfaceFlags = CSGDefaults.SurfaceFlags;
                surfaceDescriptions = new SurfaceDescription[minSurfaceDescriptions];
                for (int s = 0; s < minSurfaceDescriptions; s++)
                {
                    surfaceDescriptions[s] = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }
                }
                ;
            }
        }
    }
        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);
        }
Exemplo n.º 18
0
        public static Frustum GetCameraSubFrustum(Camera camera, Rect rect)
        {
            var oldMatrix = UnityEditor.Handles.matrix;

            UnityEditor.Handles.matrix = Matrix4x4.identity;

            var min_x = Mathf.Min(rect.xMin, rect.xMax);
            var max_x = Mathf.Max(rect.xMin, rect.xMax);
            var min_y = Mathf.Min(rect.yMin, rect.yMax);
            var max_y = Mathf.Max(rect.yMin, rect.yMax);

            var o0 = new Vector2(min_x, min_y);
            var o1 = new Vector2(max_x, min_y);
            var o2 = new Vector2(max_x, max_y);
            var o3 = new Vector2(min_x, max_y);

            var r0 = HandleUtility.GUIPointToWorldRay(o0);
            var r1 = HandleUtility.GUIPointToWorldRay(o1);
            var r2 = HandleUtility.GUIPointToWorldRay(o2);
            var r3 = HandleUtility.GUIPointToWorldRay(o3);

            UnityEditor.Handles.matrix = oldMatrix;

            var n0 = r0.origin;
            var n1 = r1.origin;
            var n2 = r2.origin;
            var n3 = r3.origin;

            var far = camera.farClipPlane;
            var f0  = n0 + (r0.direction * far);
            var f1  = n1 + (r1.direction * far);
            var f2  = n2 + (r2.direction * far);
            var f3  = n3 + (r3.direction * far);

            var frustum = new Frustum();

            frustum.Planes[0] = new Plane(n2, n1, f1); // right  +
            frustum.Planes[1] = new Plane(f3, f0, n0); // left   -
            frustum.Planes[2] = new Plane(n1, n0, f0); // top    -
            frustum.Planes[3] = new Plane(n3, n2, f2); // bottom +
            frustum.Planes[4] = new Plane(n0, n1, n2); // near   -
            frustum.Planes[5] = new Plane(f2, f1, f0); // far    +
            return(frustum);
        }
        // TODO: remove all stairs specific parameters
        static void GenerateBottomRamp(CSGBrushSubMesh[] subMeshes, int startIndex, int stepCount, Vector3 min, Vector3 max, Vector3 extrusion, StairsRiserType riserType, float riserDepth, float extraDepth, float maxDepth, CSGLinearStairsDefinition definition, CSGSurfaceAsset[] surfaceAssets, SurfaceDescription[] surfaceDescriptions)
        {
            for (int i = 0, j = startIndex; i < stepCount; i++, j++)
            {
                Vector3[] vertices;
                var       z0 = Mathf.Max(maxDepth, min.z - extraDepth);
                var       z1 = Mathf.Max(maxDepth, max.z - extraDepth);
                var       z2 = Mathf.Max(maxDepth, min.z + riserDepth);/*
                                                                        * if (z2 < z1)
                                                                        * {
                                                                        * var t = z1; z1 = z2; z2 = t;
                                                                        * z1 = Mathf.Max(maxDepth, min.z - extraDepth + definition.stepDepth);
                                                                        * z2 = Mathf.Max(maxDepth, max.z);
                                                                        * }*/
                if (i != stepCount - 1)
                {
                    vertices = new[] {
                        new Vector3(min.x, max.y, z2),                  // 0
                        new Vector3(min.x, max.y, z0),                  // 1
                        new Vector3(min.x, min.y, z1),                  // 2
                        new Vector3(min.x, min.y, z2),                  // 3
                    };
                }
                else
                {
                    vertices = new[] {
                        new Vector3(min.x, max.y, z2),                          // 0
                        new Vector3(min.x, max.y, z0),                          // 1
                        new Vector3(min.x, min.y + definition.treadHeight, z1), // 2
                        new Vector3(min.x, min.y + definition.treadHeight, z2), // 3
                    };
                }

                CreateExtrudedSubMesh(subMeshes[j], vertices, extrusion,
                                      new int[] { 0, 1, 2, 3, 3, 3 }, // TODO: fix this
                                      new int[] { 0, 1, 2, 2, 2, 2 }, // TODO: fix this
                                      surfaceAssets, surfaceDescriptions);

                min.z += definition.stepDepth;
                max.z += definition.stepDepth;
                min.y -= definition.stepHeight;
                max.y -= definition.stepHeight;
            }
        }
        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);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Calculates a value from two given values based on the desired calculation method.
        /// </summary>
        /// <param name="lhs">The first value.</param>
        /// <param name="rhs">The second value.</param>
        /// <param name="calculation">How the final value should be calculated.</param>
        public static float Calculate(float lhs, float rhs, PhysicsMaterialCombine calculation)
        {
            switch (calculation)
            {
            case PhysicsMaterialCombine.Average:
                return((lhs + rhs) / 2f);

            case PhysicsMaterialCombine.Multiply:
                return(lhs * rhs);

            case PhysicsMaterialCombine.Maximum:
                return(Mathf.Max(lhs, rhs));

            case PhysicsMaterialCombine.Minimum:
                return(Mathf.Min(lhs, rhs));

            default:
                throw new System.NotImplementedException();
            }
        }
Exemplo n.º 22
0
        public static Rect PointsToRect(Vector2 start, Vector2 end)
        {
            start.x = Mathf.Max(start.x, 0);
            start.y = Mathf.Max(start.y, 0);
            end.x   = Mathf.Max(end.x, 0);
            end.y   = Mathf.Max(end.y, 0);
            Rect r = new Rect(start.x, start.y, end.x - start.x, end.y - start.y);

            if (r.width < 0)
            {
                r.x    += r.width;
                r.width = -r.width;
            }
            if (r.height < 0)
            {
                r.y     += r.height;
                r.height = -r.height;
            }
            return(r);
        }
Exemplo n.º 23
0
        public static bool Intersect(CubeXCollider src, CubeXCollider dst, out XContact?contact)
        {
            Vector3 normal;
            float   penetration;

            if (!SATTest(src, dst, out normal, out penetration))
            {
                contact = null;
                return(false);
            }
            var srcExtents = src.Size * 0.5f;
            var dstExtents = dst.Size * 0.5f;
            var srcMinY    = src.Position.y - srcExtents.y;
            var srcMaxY    = src.Position.y + srcExtents.y;
            var dstMinY    = dst.Position.y - dstExtents.y;
            var dstMaxY    = dst.Position.y + dstExtents.y;

            var overlapY = Mathf.Min(srcMaxY, dstMaxY) - Mathf.Max(srcMinY, dstMinY);

            if ((srcMaxY > dstMaxY && srcMinY < dstMinY) || (srcMaxY < dstMaxY && srcMinY > dstMinY))
            {
                var min = Mathf.Abs(srcMinY - dstMinY);
                var max = Mathf.Abs(srcMaxY - dstMaxY);
                overlapY += Mathf.Min(min, max);
            }

            if (overlapY < penetration)
            {
                penetration = overlapY;
                normal      = Vector3.up;
            }

            if (Vector3.Dot(normal, dst.Position - src.Position) < 0)
            {
                normal = -normal;
            }

            contact = new XContact(src, dst, normal, penetration);
            return(true);
        }
Exemplo n.º 24
0
        static void DrawOutline(IChiselHandleRenderer renderer, ChiselStadiumDefinition definition, Vector3[] vertices, LineMode lineMode)
        {
            var sides       = definition.sides;
            var topSides    = Mathf.Max(definition.topSides, 1) + 1;
            var bottomSides = Mathf.Max(definition.bottomSides, 1) + 1;

            var haveRoundedTop    = definition.haveRoundedTop;
            var haveRoundedBottom = definition.haveRoundedBottom;
            var haveCenter        = definition.haveCenter;
            //renderer.DrawLineLoop(vertices,     0, sides, lineMode: lineMode, thickness: kCapLineThickness);
            //renderer.DrawLineLoop(vertices, sides, sides, lineMode: lineMode, thickness: kCapLineThickness);

            var firstTopSide = definition.firstTopSide;
            var lastTopSide  = definition.lastTopSide;

            for (int k = firstTopSide; k <= lastTopSide; k++)
            {
                var sideLine  = !haveRoundedTop || (k == firstTopSide) || (k == lastTopSide);
                var thickness = (sideLine ? kSideLineThickness : kVertLineThickness);
                var dashSize  = (sideLine ? 0                  : kLineDash);
                renderer.DrawLine(vertices[k], vertices[sides + k], lineMode: lineMode, thickness: thickness, dashSize: dashSize);
            }

            var firstBottomSide = definition.firstBottomSide;
            var lastBottomSide  = definition.lastBottomSide;

            for (int k = firstBottomSide; k <= lastBottomSide; k++)
            {
                var sideLine  = haveCenter && (!haveRoundedBottom || (k == firstBottomSide) || (k == lastBottomSide));
                var thickness = (sideLine ? kSideLineThickness : kVertLineThickness);
                var dashSize  = (sideLine ? 0                  : kLineDash);
                renderer.DrawLine(vertices[k], vertices[sides + k], lineMode: lineMode, thickness: thickness, dashSize: dashSize);
            }

            //renderer.DrawLine(vertices[firstBottomSide], vertices[lastBottomSide], lineMode: lineMode, thickness: kVertLineThickness);
            //renderer.DrawLine(vertices[firstTopSide   ], vertices[lastTopSide   ], lineMode: lineMode, thickness: kVertLineThickness);

            //renderer.DrawLine(vertices[sides + firstBottomSide], vertices[sides + lastBottomSide], lineMode: lineMode, thickness: kVertLineThickness);
            //renderer.DrawLine(vertices[sides + firstTopSide   ], vertices[sides + lastTopSide   ], lineMode: lineMode, thickness: kVertLineThickness);
        }
Exemplo n.º 25
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);
        }
        static void DrawOutline(IChiselHandleRenderer renderer, ChiselHemisphereDefinition definition, Vector3[] vertices, LineMode lineMode)
        {
            var sides = definition.horizontalSegments;

            var topSegments   = Mathf.Max(definition.verticalSegments, 0);
            var bottomCap     = false;
            var topCap        = (topSegments != 0);
            var extraVertices = ((topCap) ? 1 : 0) + ((bottomCap) ? 1 : 0);
            var bottomVertex  = 0;
            //var topVertex		= (bottomCap) ? 1 : 0;

            var rings      = (vertices.Length - extraVertices) / sides;
            var bottomRing = 0;

            var prevColor = renderer.color;
            var color     = prevColor;

            color.a *= 0.6f;

            for (int i = 0, j = extraVertices; i < rings; i++, j += sides)
            {
                renderer.color = ((i == bottomRing) ? prevColor : color);
                renderer.DrawLineLoop(vertices, j, sides, lineMode: lineMode, thickness: ((i == bottomRing) ? kCapLineThickness : kHorzLineThickness), dashSize: ((i == bottomRing) ? 0 : kLineDash));
            }

            renderer.color = color;
            for (int k = 0; k < sides; k++)
            {
                for (int i = 0, j = extraVertices; i < rings - 1; i++, j += sides)
                {
                    renderer.DrawLine(vertices[j + k], vertices[j + k + sides], lineMode: lineMode, thickness: kVertLineThickness);
                }
                if (topCap)
                {
                    renderer.DrawLine(vertices[bottomVertex], vertices[extraVertices + k + ((rings - 1) * sides)], lineMode: lineMode, thickness: kVertLineThickness);
                }
            }
            renderer.color = prevColor;
        }
Exemplo n.º 27
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;
                }
            }
        }
Exemplo n.º 28
0
        // 너무 큰 이미지를 작은 이미지로 줄이면서 PNG 파일이 아니면 PNG로 바꾼다.
        static string ExecuteResizeAndSaveAsPng(string sourceFileName, int threshold)
        {
            Logger.WriteLine($"Running {nameof(ExecuteResizeAndSaveAsPng)}");

            using var image = Image.Load <Rgba32>(sourceFileName);

            // 정사각형이 아니라면 우선 큰 변 기준으로 정사각형으로 만든다. (여백 추가)
            if (image.Width != image.Height)
            {
                var maxSide = Math.Max(image.Width, image.Height);

                var options = new ResizeOptions
                {
                    Size    = new Size(maxSide, maxSide),
                    Mode    = ResizeMode.BoxPad,
                    Sampler = new NearestNeighborResampler()
                };
                image.Mutate(x => x.Resize(options));
            }

            if (image.Width > threshold)
            {
                var options = new ResizeOptions
                {
                    Size = new Size(threshold, threshold),
                    Mode = ResizeMode.BoxPad
                };
                image.Mutate(x => x.Resize(options));
            }

            var targetFileName = AppendToFileName(sourceFileName, "", ".png", outputNewFileName);

            image.Save(targetFileName, new PngEncoder());

            return(targetFileName);
        }
        public static float CalcInnerDiameter(float outerDiameter, float tubeWidth)
        {
            var innerDiameter = outerDiameter - (tubeWidth * 2);

            return(Mathf.Max(0, innerDiameter));
        }
        public static float CalcTubeWidth(float outerDiameter, float innerDiameter)
        {
            var tubeWidth = (outerDiameter - innerDiameter) * 0.5f;

            return(Mathf.Max(kMinTubeDiameter, tubeWidth));
        }