Beispiel #1
0
        public static void SetPosition(Part part, Vector3 newPosition, Space space)
        {
            Vector3 offset;

            if (space == Space.Self)
            {
                Vector3 sourcePosition = part.transform.position;
                part.transform.localPosition = newPosition;
                offset = -part.transform.InverseTransformPoint(sourcePosition);
            }
            else
            {
                offset = part.transform.InverseTransformPoint(newPosition);
                part.transform.position = newPosition;
            }
            PartTransform.UpdateEditorGizmo(part);
            GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartOffset, part);

            if (part.symMethod == SymmetryMethod.Mirror)
            {
                PartTransform.UpdateMirrorSymmetryCounterpartsPosition(part);
            }
            else if (part.symMethod == SymmetryMethod.Radial)
            {
                PartTransform.UpdateRadialSymmetryCounterpartsPosition(part, offset);
            }

            EditorLogic.fetch.SetBackup();
        }
        private void Rotate(int vectorIndex, bool inverse, Space space)
        {
            Vector3 eulerAngles = new Vector3(0, 0, 0);

            eulerAngles[vectorIndex] = inverse ? -this.deltaRotation : this.deltaRotation;

            PartTransform.Rotate(this.part, eulerAngles, space);
        }
Beispiel #3
0
 private static void UpdateRadialSymmetryCounterpartsRotation(Part part, Quaternion rotation)
 {
     foreach (Part symmetryCounterpart in part.symmetryCounterparts)
     {
         symmetryCounterpart.transform.rotation *= rotation;
         PartTransform.UpdateEditorGizmo(symmetryCounterpart);
         GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartRotated, symmetryCounterpart);
     }
 }
Beispiel #4
0
 private static void UpdateRadialSymmetryCounterpartsPosition(Part part, Vector3 offset)
 {
     foreach (Part symmetryCounterpart in part.symmetryCounterparts)
     {
         symmetryCounterpart.transform.Translate(offset);
         PartTransform.UpdateEditorGizmo(symmetryCounterpart);
         GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartOffset, symmetryCounterpart);
     }
 }
        private string SetPosition(int vectorIndex, string value, Space space)
        {
            float   fValue   = float.Parse(value, CultureInfo.InvariantCulture.NumberFormat);
            Vector3 position = space == Space.Self ? this.part.transform.localPosition : this.part.transform.position;

            position[vectorIndex] = fValue;
            PartTransform.SetPosition(this.part, position, space);
            return(value);
        }
        private string SetRotation(int vectorIndex, string value, Space space)
        {
            float   fValue          = float.Parse(value, CultureInfo.InvariantCulture.NumberFormat);
            Vector3 partEulerAngles = (space == Space.Self) ? this.part.transform.localRotation.eulerAngles : this.part.transform.rotation.eulerAngles;
            Vector3 eulerAngles     = new Vector3(0, 0, 0);

            eulerAngles[vectorIndex] = fValue - partEulerAngles[vectorIndex];
            PartTransform.Rotate(this.part, eulerAngles, space);
            return(value);
        }
Beispiel #7
0
        private static void UpdateMirrorSymmetryCounterpartsRotation(Part part)
        {
            foreach (Part symmetryCounterpart in part.symmetryCounterparts)
            {
                symmetryCounterpart.transform.rotation = EditorGeometryUtil.MirrorRotation(part.transform.rotation, part.transform, EditorLogic.RootPart.transform);

                if (part.attRotation0 == symmetryCounterpart.attRotation0)
                {
                    symmetryCounterpart.transform.Rotate(new Vector3(0, 180, 0), Space.Self);
                }
                PartTransform.UpdateEditorGizmo(symmetryCounterpart);
                GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartRotated, symmetryCounterpart);
            }
        }
Beispiel #8
0
        private static void UpdateMirrorSymmetryCounterpartsPosition(Part part)
        {
            Vector3 localPosition  = part.transform.position - EditorLogic.RootPart.transform.position;
            Vector3 projection     = Vector3.ProjectOnPlane(localPosition, EditorLogic.RootPart.transform.right);
            Vector3 projectedPoint = EditorLogic.RootPart.transform.position + projection;
            Vector3 offset         = projectedPoint - part.transform.position;

            foreach (Part symmetryCounterpart in part.symmetryCounterparts)
            {
                symmetryCounterpart.transform.position = EditorLogic.RootPart.transform.position + projection + offset;
                PartTransform.UpdateEditorGizmo(symmetryCounterpart);
                GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartOffset, symmetryCounterpart);
            }
        }
Beispiel #9
0
        private static void RotateRadialSymmetryCounterparts(Part part, Vector3 eulerAngles, Space space)
        {
            if (space == Space.World)
            {
                eulerAngles = part.transform.InverseTransformDirection(eulerAngles);
            }

            foreach (Part symmetryCounterpart in part.symmetryCounterparts)
            {
                symmetryCounterpart.transform.Rotate(eulerAngles, Space.Self);
                PartTransform.UpdateEditorGizmo(symmetryCounterpart);
                GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartRotated, symmetryCounterpart);
            }
        }
        private void Rotate(int vectorIndex, bool inverse)
        {
            Vector3 eulerAngles = new Vector3(0, 0, 0);

            eulerAngles[vectorIndex] = inverse ? -deltaRotation : deltaRotation;

            if (part.isCompund)
            {
                CompoundPartTransform.Rotate((CompoundPart)part, eulerAngles, referenceSpace, compoundTargetSelected);
            }
            else
            {
                PartTransform.Rotate(part, eulerAngles, referenceSpace);
            }
        }
Beispiel #11
0
        public static void Rotate(Part part, Vector3 eulerAngles, Space space)
        {
            part.transform.Rotate(eulerAngles, space);
            PartTransform.UpdateEditorGizmo(part);
            GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartRotated, part);

            if (part.symMethod == SymmetryMethod.Mirror)
            {
                PartTransform.UpdateMirrorSymmetryCounterpartsRotation(part);
            }
            else if (part.symMethod == SymmetryMethod.Radial)
            {
                PartTransform.RotateRadialSymmetryCounterparts(part, eulerAngles, space);
            }

            EditorLogic.fetch.SetBackup();
        }
        private string SetRotation(int vectorIndex, string value)
        {
            float      fValue          = float.Parse(value, CultureInfo.InvariantCulture.NumberFormat);
            Quaternion rotation        = PartUtil.GetRotation(part, referenceSpace, compoundTargetSelected);
            Vector3    partEulerAngles = rotation.eulerAngles;
            Vector3    eulerAngles     = new Vector3(0, 0, 0);

            eulerAngles[vectorIndex] = fValue - partEulerAngles[vectorIndex];
            if (part.isCompund)
            {
                CompoundPartTransform.Rotate((CompoundPart)part, eulerAngles, referenceSpace, compoundTargetSelected);
            }
            else
            {
                PartTransform.Rotate(part, eulerAngles, referenceSpace);
            }
            return(value);
        }
        private string SetPosition(int vectorIndex, string value)
        {
            Vector3 newPosition = GetWorldPositionToBeSet(vectorIndex, value);
            Vector3 oldPosition = PartUtil.GetPosition(part, Space.World, compoundTargetSelected);
            Bounds  partBounds;

            if (PartUtil.IsTargetActive(part, compoundTargetSelected))
            {
                partBounds = FindChildGameObjectByName(part.gameObject, "obj_targetCollider").GetComponent <Collider>().bounds;
            }
            else
            {
                partBounds = part.collider.bounds;
            }

            if (!AreBoundsOutOfHangarBounds(partBounds))
            {
                Vector3 boundsOffset = partBounds.center - oldPosition;

                partBounds.center = newPosition + boundsOffset;
                if (AreBoundsOutOfHangarBounds(partBounds))
                {
                    return(value);
                }
            }
            if (newPosition == oldPosition)
            {
                return(value);
            }

            if (part.isCompund)
            {
                CompoundPartTransform.SetWorldPosition((CompoundPart)part, newPosition, compoundTargetSelected);
            }
            else
            {
                PartTransform.SetWorldPosition(part, newPosition);
            }

            return(value);
        }
Beispiel #14
0
        private static void RotateMirrorSymmetryCounterparts(Part part, Vector3 eulerAngles, Space space)
        {
            if (space == Space.Self)
            {
                eulerAngles = part.transform.TransformDirection(eulerAngles);
            }

            eulerAngles = EditorLogic.RootPart.transform.InverseTransformDirection(eulerAngles);
            Quaternion rotation = Quaternion.Euler(eulerAngles);
            Vector3    axis;
            float      angle;

            rotation.ToAngleAxis(out angle, out axis);
            Vector3 mirrorAxis = new Vector3(-axis.x, axis.y, axis.z);

            mirrorAxis = EditorLogic.RootPart.transform.TransformDirection(mirrorAxis);

            foreach (Part symmetryCounterpart in part.symmetryCounterparts)
            {
                symmetryCounterpart.transform.Rotate(mirrorAxis, -angle, Space.World);
                PartTransform.UpdateEditorGizmo(symmetryCounterpart);
                GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartRotated, symmetryCounterpart);
            }
        }