public void UpdateFaceFromCenter() { Vector3 difference = center.coordinates - centerPosition; centerPosition = center.coordinates; // go through each vertex and apply a similar translation for (int i = 0; i < vertexBundles.Length; i++) { if (vertexBundles[i] != center) { vertexBundles[i].coordinates += difference; } } scaleHandle.transform.localPosition += difference; centerHandle.transform.localPosition = centerPosition; if (heightHandle != null) { heightHandle.transform.localPosition = centerPosition; } scalerPosition = scaler.coordinates; parentModelingObject.CalculateBoundingBox(); parentModelingObject.PositionHandles(false); parentModelingObject.RotateHandles(); }
public void ShowSelectionButton(Selection controller) { if (!active) { connectedObject.CalculateBoundingBox(); RePosition(Camera.main.transform.position); } buttonGameObject.SetActive(true); active = true; Collider.SetActive(true); LeanTween.alpha(buttonGameObject, 1f, 0.15f); if (connectedObject != null) { connectedObject.ShowBoundingBox(true); } }
public void createNewObject(ModelingObject.ObjectType type, Face groundface, ModelingObject original, Vector3 offSet, bool insideStage, Group group, Color color, GameObject complexObject) { Mesh mesh = new Mesh(); if (type == ModelingObject.ObjectType.triangle) { mesh = triangle; } else if (type == ModelingObject.ObjectType.square) { mesh = square; } else if (type == ModelingObject.ObjectType.octagon) { mesh = octagon; } GameObject newObject = Instantiate(modelingObject); if (insideStage) { newObject.transform.SetParent(objects); } else { newObject.transform.SetParent(library); } ModelingObject newModelingObject = newObject.GetComponent <ModelingObject>(); newObject.name = "Object " + objectIDcount; newModelingObject.ObjectID = objectIDcount; objectIDcount++; newModelingObject.typeOfObject = type; newObject.GetComponent <ModelingObject>().Initiate(mesh); if (groundface != null) { newObject.transform.localEulerAngles = new Vector3(0f, 0f, 0f); newObject.transform.position = groundface.center.transform.TransformPoint(groundface.center.coordinates + groundface.normal * 0.4f); newObject.transform.localScale = groundface.transform.parent.parent.transform.localScale; newModelingObject.bottomFace.ReplaceFaceOnOtherFace(groundface, new Vector3(0f, 0f, 0f), true); newModelingObject.topFace.ReplaceFaceOnOtherFace(groundface, groundface.normal.normalized * 0.1f, false); // recalculate centers newModelingObject.RecalculateCenters(); // recalculate normals newModelingObject.RecalculateNormals(); } else { if (insideStage) { newObject.transform.localScale = new Vector3(1f, 1f, 1f); newObject.transform.localEulerAngles = new Vector3(0f, 0f, 0f); newObject.transform.localPosition = new Vector3(0f, 0f, 0f); newObject.transform.localPosition = offSet; } else { newObject.transform.localPosition = offSet; newObject.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); } } if (original != null) { // SetVertexBundlePositions(Vector3[] topFaceCoordinates, Vector3[] bottomFaceCoordinates, Vector3 topFaceCenter, Vector3 bottomFaceCenter) Vector3[] topFaceCoordinates = new Vector3[original.topFace.vertexBundles.Length]; Vector3[] bottomFaceCoordinates = new Vector3[original.bottomFace.vertexBundles.Length]; for (int i = 0; i < topFaceCoordinates.Length; i++) { topFaceCoordinates[i] = original.topFace.vertexBundles[i].coordinates; } for (int i = 0; i < bottomFaceCoordinates.Length; i++) { bottomFaceCoordinates[i] = original.bottomFace.vertexBundles[i].coordinates; } newModelingObject.SetVertexBundlePositions(topFaceCoordinates, bottomFaceCoordinates, original.topFace.centerPosition, original.bottomFace.centerPosition); newObject.transform.localPosition = offSet; newModelingObject.coordinateSystem.transform.localRotation = original.coordinateSystem.transform.localRotation; } // newModelingObject.CorrectOffset(); newModelingObject.CalculateBoundingBox(); newModelingObject.InitiateHandles(); if (group != null) { ObjectsManager.Instance.AddObjectToGroup(group, newModelingObject); //newObject.transform.position = offSet; } newModelingObject.ChangeColor(color, false); latestModelingObject = newModelingObject; if (complexObject != null) { newModelingObject.InsertObject(complexObject); } }
public bool ApplyChanges(GameObject pointOfCollision, bool alreadyMoving, Selection controller) { if (!alreadyMoving) { //connectedModelingObject.HideBoundingBox (false); } switch (typeOfHandle) { case handleType.ScaleFace: ScaleFace(pointOfCollision); break; case handleType.PositionCenter: MoveCenterPosition(pointOfCollision); break; case handleType.Height: ChangeHeight(pointOfCollision); break; case handleType.Rotation: if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); connectedModelingObject.CalculateBoundingBox(); connectedModelingObject.CalculateBoundingBoxWorld(); handles.HideScalingHandlesExcept(null); TouchElements.Instance.Hide(); newRotation = true; } Rotate(pointOfCollision, controller, true); connectedModelingObject.PositionHandles(true); connectedModelingObject.RotateHandles(); handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); break; case handleType.ScaleX: if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); newScaling = true; } ScaleNonUniform(pointOfCollision, new Vector3(1f, 0f, 0f)); break; case handleType.ScaleY: if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); newScaling = true; } ScaleNonUniform(pointOfCollision, new Vector3(0f, 1f, 0f)); break; case handleType.ScaleZ: if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); newScaling = true; } ScaleNonUniform(pointOfCollision, new Vector3(0f, 0f, 1f)); break; case handleType.ScaleMinusX: if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); newScaling = true; } ScaleNonUniform(pointOfCollision, new Vector3(1f, 0f, 0f)); break; case handleType.ScaleMinusY: if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); newScaling = true; } ScaleNonUniform(pointOfCollision, new Vector3(0f, 1f, 0f)); break; case handleType.ScaleMinusZ: if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); newScaling = true; } ScaleNonUniform(pointOfCollision, new Vector3(0f, 0f, 1f)); break; case handleType.MoveY: if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); newMovement = true; } MoveYPosition(pointOfCollision); handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); break; case handleType.UniformScale: Debug.Log("already moving " + alreadyMoving); if (!alreadyMoving) { handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); newScaling = true; } ScaleUniform(pointOfCollision); handles.HideRotationHandlesExcept(null); handles.HideScalingHandlesExcept(this); break; case handleType.RotationHandleToggle: //handles.ToggleOnOffRotationHandles (); break; } connectedModelingObject.RecalculateSideCenters(); connectedModelingObject.RecalculateNormals(); //handles.HideRotationHandlesExcept (null); //handles.HideScalingHandlesExcept (this); //connectedModelingObject.ShowBoundingBox (); //connectedModelingObject.ShowBoundingBox (); return(true); }