示例#1
0
        public static bool GenerateCapsule(ref BrushMesh brushMesh, ref ChiselCapsuleDefinition definition)
        {
            Vector3[] vertices = null;
            if (!BrushMeshFactory.GenerateCapsuleVertices(ref definition, ref vertices))
            {
                brushMesh.Clear();
                return(false);
            }

            // TODO: share this with GenerateCapsuleVertices
            var bottomCap    = !definition.haveRoundedBottom;
            var topCap       = !definition.haveRoundedTop;
            var sides        = definition.sides;
            var segments     = definition.segments;
            var bottomVertex = definition.bottomVertex;
            var topVertex    = definition.topVertex;

            if (!BrushMeshFactory.GenerateSegmentedSubMesh(ref brushMesh,
                                                           sides, segments,
                                                           vertices,
                                                           topCap, bottomCap,
                                                           topVertex, bottomVertex,
                                                           definition.surfaceDefinition))
            {
                brushMesh.Clear();
                return(false);
            }
            return(true);
        }
示例#2
0
        public static bool GenerateCapsule(ref ChiselBrushContainer brushContainer, ref ChiselCapsuleDefinition definition)
        {
            definition.Validate();
            Vector3[] vertices = null;
            if (!BrushMeshFactory.GenerateCapsuleVertices(ref definition, ref vertices))
            {
                return(false);
            }

            // TODO: share this with GenerateCapsuleVertices
            var bottomCap    = !definition.haveRoundedBottom;
            var topCap       = !definition.haveRoundedTop;
            var sides        = definition.sides;
            var segments     = definition.segments;
            var bottomVertex = definition.bottomVertex;
            var topVertex    = definition.topVertex;

            brushContainer.EnsureSize(1);

            return(BrushMeshFactory.GenerateSegmentedSubMesh(ref brushContainer.brushMeshes[0],
                                                             sides, segments,
                                                             vertices,
                                                             topCap, bottomCap,
                                                             topVertex, bottomVertex,
                                                             definition.surfaceDefinition));
        }
示例#3
0
        static                         Vector3[] vertices = null; // TODO: store this per instance? or just allocate every frame?

        public void OnEdit(IChiselHandles handles)
        {
            var baseColor = handles.color;
            var normal    = Vector3.up;

            if (BrushMeshFactory.GenerateCapsuleVertices(ref this, ref vertices))
            {
                handles.color = handles.GetStateColor(baseColor, false, false);
                DrawOutline(handles, this, vertices, lineMode: LineMode.ZTest);

                handles.color = handles.GetStateColor(baseColor, false, true);
                DrawOutline(handles, this, vertices, lineMode: LineMode.NoZTest);

                handles.color = baseColor;
            }

            var topPoint    = normal * (this.offsetY + this.height);
            var bottomPoint = normal * (this.offsetY);
            var middlePoint = normal * (this.offsetY + (this.height * 0.5f));
            var radius2D    = new Vector2(this.diameterX, this.diameterZ) * 0.5f;

            var topHeight    = this.topHeight;
            var bottomHeight = this.bottomHeight;

            var maxTopHeight    = this.height - bottomHeight;
            var maxBottomHeight = this.height - topHeight;

            if (this.height < 0)
            {
                normal = -normal;
            }

            var prevModified = handles.modified;

            {
                handles.color = baseColor;
                // TODO: make it possible to (optionally) size differently in x & z
                var radius2Dx = radius2D.x;
                handles.DoRadiusHandle(ref radius2Dx, normal, middlePoint);
                radius2D.x = radius2Dx;

                {
                    var isTopBackfaced  = handles.IsSufaceBackFaced(topPoint, normal);
                    var topLoopHasFocus = false;
                    handles.backfaced = isTopBackfaced;
                    for (int j = this.sides - 1, i = 0; i < this.sides; j = i, i++)
                    {
                        var from = vertices[j + this.topVertexOffset];
                        var to   = vertices[i + this.topVertexOffset];

                        if (handles.DoEdgeHandle1DOffset(out var edgeOffset, UnitySceneExtensions.Axis.Y, from, to, renderLine: false))
                        {
                            topHeight = Mathf.Clamp(topHeight - edgeOffset, 0, maxTopHeight);
                        }
                        topLoopHasFocus = topLoopHasFocus || handles.lastHandleHadFocus;
                    }


                    handles.color = baseColor;
                    handles.DoDirectionHandle(ref topPoint, normal);
                    var topHasFocus = handles.lastHandleHadFocus;
                    handles.backfaced = false;

                    topLoopHasFocus = topLoopHasFocus || (topHasFocus && !this.haveRoundedTop);

                    var thickness = topLoopHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                    handles.color = handles.GetStateColor(baseColor, topLoopHasFocus, true);
                    handles.DrawLineLoop(vertices, this.topVertexOffset, this.sides, lineMode: LineMode.NoZTest, thickness: thickness);

                    handles.color = handles.GetStateColor(baseColor, topLoopHasFocus, false);
                    handles.DrawLineLoop(vertices, this.topVertexOffset, this.sides, lineMode: LineMode.ZTest, thickness: thickness);
                }

                {
                    var isBottomBackfaced  = handles.IsSufaceBackFaced(bottomPoint, -normal);
                    var bottomLoopHasFocus = false;
                    handles.backfaced = isBottomBackfaced;
                    for (int j = this.sides - 1, i = 0; i < this.sides; j = i, i++)
                    {
                        var from = vertices[j + this.bottomVertexOffset];
                        var to   = vertices[i + this.bottomVertexOffset];

                        if (handles.DoEdgeHandle1DOffset(out var edgeOffset, UnitySceneExtensions.Axis.Y, from, to, renderLine: false))
                        {
                            bottomHeight = Mathf.Clamp(bottomHeight + edgeOffset, 0, maxBottomHeight);
                        }
                        bottomLoopHasFocus = bottomLoopHasFocus || handles.lastHandleHadFocus;
                    }

                    handles.color = baseColor;
                    handles.DoDirectionHandle(ref bottomPoint, -normal);
                    var bottomHasFocus = handles.lastHandleHadFocus;
                    handles.backfaced = false;

                    bottomLoopHasFocus = bottomLoopHasFocus || (bottomHasFocus && !this.haveRoundedBottom);

                    var thickness = bottomLoopHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                    handles.color = handles.GetStateColor(baseColor, bottomLoopHasFocus, true);
                    handles.DrawLineLoop(vertices, this.bottomVertexOffset, this.sides, lineMode: LineMode.NoZTest, thickness: thickness);

                    handles.color = handles.GetStateColor(baseColor, bottomLoopHasFocus, false);
                    handles.DrawLineLoop(vertices, this.bottomVertexOffset, this.sides, lineMode: LineMode.ZTest, thickness: thickness);
                }
            }
            if (prevModified != handles.modified)
            {
                this.diameterX    = radius2D.x * 2.0f;
                this.height       = topPoint.y - bottomPoint.y;
                this.diameterZ    = radius2D.x * 2.0f;
                this.offsetY      = bottomPoint.y;
                this.topHeight    = topHeight;
                this.bottomHeight = bottomHeight;
                // TODO: handle sizing down (needs to modify transformation?)
            }
        }