コード例 #1
0
        public static bool DoBoundsHandle(this IChiselHandles handles, ref ChiselAABB box, Vector3?snappingSteps = null, string undoMessage = null)
        {
            var bounds = new Bounds();

            bounds.SetMinMax(box.Min, box.Max);
            var result = handles.DoBoundsHandle(ref bounds, snappingSteps, undoMessage);

            box.Min = bounds.min;
            box.Max = bounds.max;
            return(result);
        }
コード例 #2
0
 public void OnEdit(IChiselHandles handles)
 {
     handles.DoBoundsHandle(ref bounds);
     handles.RenderBoxMeasurements(bounds);
 }
コード例 #3
0
        //
        // TODO: code below needs to be cleaned up & simplified
        //


        public void OnEdit(IChiselHandles handles)
        {
            var newDefinition = this;

            {
                var stepDepthOffset = this.StepDepthOffset;
                var stepHeight      = this.stepHeight;
                var stepCount       = this.StepCount;
                var bounds          = this.bounds;

                var steps = handles.moveSnappingSteps;
                steps.y = stepHeight;

                if (handles.DoBoundsHandle(ref bounds, snappingSteps: steps))
                {
                    newDefinition.bounds = bounds;
                }

                var min = new Vector3(Mathf.Min(bounds.min.x, bounds.max.x), Mathf.Min(bounds.min.y, bounds.max.y), Mathf.Min(bounds.min.z, bounds.max.z));
                var max = new Vector3(Mathf.Max(bounds.min.x, bounds.max.x), Mathf.Max(bounds.min.y, bounds.max.y), Mathf.Max(bounds.min.z, bounds.max.z));

                var size = (max - min);

                var heightStart = bounds.max.y + (bounds.size.y < 0 ? size.y : 0);

                var edgeHeight = heightStart - stepHeight * stepCount;
                var pHeight0   = new Vector3(min.x, edgeHeight, max.z);
                var pHeight1   = new Vector3(max.x, edgeHeight, max.z);

                var depthStart = bounds.min.z - (bounds.size.z < 0 ? size.z : 0);

                var pDepth0 = new Vector3(min.x, max.y, depthStart + stepDepthOffset);
                var pDepth1 = new Vector3(max.x, max.y, depthStart + stepDepthOffset);

                if (handles.DoTurnHandle(ref bounds))
                {
                    newDefinition.bounds = bounds;
                }

                if (handles.DoEdgeHandle1D(out edgeHeight, Axis.Y, pHeight0, pHeight1, snappingStep: stepHeight))
                {
                    var         totalStepHeight = Mathf.Clamp((heightStart - edgeHeight), size.y % stepHeight, size.y);
                    const float kSmudgeValue    = 0.0001f;
                    var         oldStepCount    = newDefinition.StepCount;
                    var         newStepCount    = Mathf.Max(1, Mathf.FloorToInt((Mathf.Abs(totalStepHeight) + kSmudgeValue) / stepHeight));

                    newDefinition.stepDepth     = (oldStepCount * newDefinition.stepDepth) / newStepCount;
                    newDefinition.plateauHeight = size.y - (stepHeight * newStepCount);
                }

                if (handles.DoEdgeHandle1D(out stepDepthOffset, Axis.Z, pDepth0, pDepth1, snappingStep: ChiselLinearStairsDefinition.kMinStepDepth))
                {
                    stepDepthOffset        -= depthStart;
                    stepDepthOffset         = Mathf.Clamp(stepDepthOffset, 0, this.absDepth - ChiselLinearStairsDefinition.kMinStepDepth);
                    newDefinition.stepDepth = ((this.absDepth - stepDepthOffset) / this.StepCount);
                }

                float heightOffset;
                var   prevModified = handles.modified;
                {
                    var direction = Vector3.Cross(Vector3.forward, pHeight0 - pDepth0).normalized;
                    handles.DoEdgeHandle1DOffset(out var height0vec, Axis.Y, pHeight0, pDepth0, direction, snappingStep: stepHeight);
                    handles.DoEdgeHandle1DOffset(out var height1vec, Axis.Y, pHeight1, pDepth1, direction, snappingStep: stepHeight);
                    var height0 = Vector3.Dot(direction, height0vec);
                    var height1 = Vector3.Dot(direction, height1vec);
                    if (Mathf.Abs(height0) > Mathf.Abs(height1))
                    {
                        heightOffset = height0;
                    }
                    else
                    {
                        heightOffset = height1;
                    }
                }
                if (prevModified != handles.modified)
                {
                    newDefinition.plateauHeight += heightOffset;
                }
            }
            if (handles.modified)
            {
                this = newDefinition;
            }
        }
コード例 #4
0
        //[NamedItems("Top", "Bottom", "Left", "Right", "Front", "Back", "Tread", "Step", overflow = "Side {0}", fixedSize = 8)]
        //public ChiselSurfaceDefinition  surfaceDefinition;

        #region OnEdit
        //
        // TODO: code below needs to be cleaned up & simplified
        //

        public override void OnEdit(IChiselHandles handles)
        {
            {
                var stepDepthOffset = settings.StepDepthOffset;
                var stepHeight      = settings.stepHeight;
                var stepCount       = settings.StepCount;
                var bounds          = settings.bounds;

                var steps = handles.moveSnappingSteps;
                steps.y = stepHeight;

                if (handles.DoBoundsHandle(ref bounds, snappingSteps: steps))
                {
                    settings.bounds = bounds;
                }

                var min = math.min(bounds.Min, bounds.Max);
                var max = math.min(bounds.Min, bounds.Max);

                var size = (max - min);

                var heightStart = bounds.Max.y + (size.y < 0 ? size.y : 0);

                var edgeHeight = heightStart - stepHeight * stepCount;
                var pHeight0   = new Vector3(min.x, edgeHeight, max.z);
                var pHeight1   = new Vector3(max.x, edgeHeight, max.z);

                var depthStart = bounds.Min.z - (size.z < 0 ? size.z : 0);

                var pDepth0 = new Vector3(min.x, max.y, depthStart + stepDepthOffset);
                var pDepth1 = new Vector3(max.x, max.y, depthStart + stepDepthOffset);

                if (handles.DoTurnHandle(ref bounds))
                {
                    settings.bounds = bounds;
                }

                if (handles.DoEdgeHandle1D(out edgeHeight, Axis.Y, pHeight0, pHeight1, snappingStep: stepHeight))
                {
                    var         totalStepHeight = math.clamp((heightStart - edgeHeight), size.y % stepHeight, size.y);
                    const float kSmudgeValue    = 0.0001f;
                    var         oldStepCount    = settings.StepCount;
                    var         newStepCount    = math.max(1, (int)math.floor((math.abs(totalStepHeight) + kSmudgeValue) / stepHeight));

                    settings.stepDepth     = (oldStepCount * settings.stepDepth) / newStepCount;
                    settings.plateauHeight = size.y - (stepHeight * newStepCount);
                }

                if (handles.DoEdgeHandle1D(out stepDepthOffset, Axis.Z, pDepth0, pDepth1, snappingStep: ChiselLinearStairs.kMinStepDepth))
                {
                    stepDepthOffset   -= depthStart;
                    stepDepthOffset    = math.clamp(stepDepthOffset, 0, settings.AbsDepth - ChiselLinearStairs.kMinStepDepth);
                    settings.stepDepth = ((settings.AbsDepth - stepDepthOffset) / settings.StepCount);
                }

                float heightOffset;
                var   prevModified = handles.modified;
                {
                    var direction = Vector3.Cross(Vector3.forward, pHeight0 - pDepth0).normalized;
                    handles.DoEdgeHandle1DOffset(out var height0vec, Axis.Y, pHeight0, pDepth0, direction, snappingStep: stepHeight);
                    handles.DoEdgeHandle1DOffset(out var height1vec, Axis.Y, pHeight1, pDepth1, direction, snappingStep: stepHeight);
                    var height0 = Vector3.Dot(direction, height0vec);
                    var height1 = Vector3.Dot(direction, height1vec);
                    if (math.abs(height0) > math.abs(height1))
                    {
                        heightOffset = height0;
                    }
                    else
                    {
                        heightOffset = height1;
                    }
                }
                if (prevModified != handles.modified)
                {
                    settings.plateauHeight += heightOffset;
                }
            }
        }