public void AddVertexBundle(VertexBundle vBundle) { for (int i=0; i< vertexBundles.Length; i++){ if (vertexBundles [i] == null) { vertexBundles [i] = vBundle; break; } } }
public void AddVertexBundle(VertexBundle vBundle) { for (int i = 0; i < vertexBundles.Length; i++) { if (vertexBundles [i] == null) { vertexBundles [i] = vBundle; break; } } }
public void OrderVertexBundlesClockwise() { // Quick fix for Octagon if (parentModelingObject.typeOfObject == ModelingObject.ObjectType.octagon) { if (typeOfFace == faceType.TopFace) { VertexBundle[] OrderedVertexBundles = new VertexBundle[vertexBundles.Length]; for (int i = 0; i < OrderedVertexBundles.Length; i++) { OrderedVertexBundles [i] = vertexBundles [vertexBundles.Length - i - 1]; } vertexBundles = OrderedVertexBundles; } } else { VertexBundle[] OrderedVertexBundles = new VertexBundle[vertexBundles.Length]; VertexBundle[] LeftVertexBundles = vertexBundles; OrderedVertexBundles [0] = vertexBundles [0]; for (int i = 1; i < OrderedVertexBundles.Length; i++) { float distance = 0f; int idOfnextBundle = 0; // check which vertex bundle is the closes clockwise of the current one for (int j = 1; j < LeftVertexBundles.Length; j++) { if (LeftVertexBundles[j] != null) { float newDistance = Vector3.Dot(normal, Vector3.Cross(OrderedVertexBundles [i - 1].coordinates - centerPosition, LeftVertexBundles [j].coordinates - centerPosition)); if (newDistance > distance) { distance = newDistance; idOfnextBundle = j; } } } distance = 0f; OrderedVertexBundles [i] = LeftVertexBundles [idOfnextBundle]; LeftVertexBundles [idOfnextBundle] = null; } vertexBundles = OrderedVertexBundles; } }
public void CalculateCenter() { Vector3 centerPositionNew = new Vector3 (0, 0, 0); for (int i = 0; i < vertexBundles.Length; i++) { centerPositionNew += vertexBundles [i].coordinates; } centerPositionNew = centerPositionNew / vertexBundles.Length; // check if there is a bundle with the center already foreach (Transform child in transform) { if (child.gameObject.CompareTag("VertexBundle")){ if (child.gameObject.GetComponent<VertexBundle>().coordinates == centerPositionNew) { center = child.gameObject.GetComponent<VertexBundle>(); } } } if (center == null) { GameObject centerGameObject; GameObject centerVertexGameObject; centerGameObject = Instantiate (VertexBundlePrefab); centerVertexGameObject = Instantiate (VertexPrefab); centerVertexGameObject.transform.localPosition = centerPositionNew; centerVertexGameObject.transform.SetParent (centerGameObject.transform); centerGameObject.transform.SetParent (this.transform); center = centerGameObject.GetComponent<VertexBundle> (); center.coordinates = centerPositionNew; } centerPosition = centerPositionNew; if (typeOfFace == faceType.TopFace) { center.name = "Center Top"; OrderVertexBundlesClockwise (); } else if (typeOfFace == faceType.BottomFace) { center.name = "Center Bottom"; OrderVertexBundlesClockwise (); } else { center.name = "Center Side"; } center.Initialize (); }
void OnCollisionExit(Collision col) { if (parentObject.moving) { if (col.collider.gameObject.CompareTag("Vertex") && col.collider.transform.parent != transform.parent) { VertexBundle colliderVertBundle = col.collider.transform.parent.GetComponent <VertexBundle>(); if (colliderVertBundle.centerVertex && colliderVertBundle.possibleSnappingVertexBundle == parentVertexBundle) { parentVertexBundle.possibleSnappingVertexBundle = null; colliderVertBundle.possibleSnappingVertexBundle = null; colliderVertBundle.usedForSnapping = false; } } } }
void OnCollisionEnter(Collision col) { if (parentObject.moving) { if (parentVertexBundle.centerVertex && col.collider.gameObject.CompareTag("Vertex") && col.collider.transform.parent != transform.parent) { VertexBundle colliderVertBundle = col.collider.transform.parent.GetComponent <VertexBundle>(); if (colliderVertBundle.centerVertex && colliderVertBundle.possibleSnappingVertexBundle == null) { // Compare normals if (colliderVertBundle.GetComponentInParent <Face> ().normal == (-1f) * transform.parent.GetComponentInParent <Face> ().normal) { parentVertexBundle.possibleSnappingVertexBundle = colliderVertBundle; } } } } }
public void RepositionScaler() { Vector3[] vertexBundlesCoordinates = new Vector3[vertexBundles.Length]; int idOfVertexbundle; for (int i = 0; i < vertexBundles.Length; i++) { vertexBundlesCoordinates [i] = parentModelingObject.transform.TransformPoint(vertexBundles [i].coordinates); } scalerPosition = parentModelingObject.transform.InverseTransformPoint(parentModelingObject.GetPosOfClosestVertex(Camera.main.transform.position, vertexBundlesCoordinates)); for (int i = 0; i < vertexBundles.Length; i++) { if (vertexBundles [i].coordinates == scalerPosition) { scaler = vertexBundles [i]; parentModelingObject.scalerObject = vertexBundles [i]; break; } } }
public void SetScaler() { if (parentModelingObject.typeOfObject != ModelingObject.ObjectType.octagon) { if (typeOfFace == faceType.TopFace) { scaler = vertexBundles [1]; scalerPosition = scaler.coordinates; parentModelingObject.scalerObject = vertexBundles [1]; } else if (typeOfFace == faceType.BottomFace) { scaler = vertexBundles [vertexBundles.Length - 1]; scalerPosition = scaler.coordinates; parentModelingObject.scalerObject = vertexBundles [vertexBundles.Length - 1]; } } else { if (typeOfFace == faceType.TopFace) { scaler = vertexBundles [1]; scalerPosition = scaler.coordinates; parentModelingObject.scalerObject = vertexBundles [1]; } else if (typeOfFace == faceType.BottomFace) { scaler = vertexBundles [vertexBundles.Length - 2]; scalerPosition = scaler.coordinates; parentModelingObject.scalerObject = vertexBundles [vertexBundles.Length - 2]; } } }
public void CalculateCenter() { Vector3 centerPositionNew = new Vector3(0, 0, 0); for (int i = 0; i < vertexBundles.Length; i++) { if (vertexBundles [i] != null) { centerPositionNew += vertexBundles [i].coordinates; } } centerPositionNew = centerPositionNew / vertexBundles.Length; // check if there is a bundle with the center already foreach (Transform child in transform) { if (child.gameObject.CompareTag("VertexBundle")) { if (child.gameObject.GetComponent <VertexBundle>().coordinates == centerPositionNew) { center = child.gameObject.GetComponent <VertexBundle>(); } } } if (center == null) { GameObject centerGameObject; GameObject centerVertexGameObject; centerGameObject = Instantiate(VertexBundlePrefab); centerVertexGameObject = Instantiate(VertexPrefab); centerVertexGameObject.transform.localPosition = centerPositionNew; centerVertexGameObject.transform.SetParent(centerGameObject.transform); centerGameObject.transform.SetParent(this.transform); center = centerGameObject.GetComponent <VertexBundle> (); center.coordinates = centerPositionNew; } centerPosition = centerPositionNew; if (typeOfFace == faceType.TopFace) { center.name = "Center Top"; center.centerVertex = true; OrderVertexBundlesClockwise(); SetScaler(); } else if (typeOfFace == faceType.BottomFace) { center.name = "Center Bottom"; center.centerVertex = true; OrderVertexBundlesClockwise(); SetScaler(); } else { center.name = "Center Side"; center.centerVertex = true; center.DeactivateCollisionDetection(); } center.Initialize(); }
public void OrderVertexBundlesClockwise() { VertexBundle[] OrderedVertexBundles = new VertexBundle[vertexBundles.Length]; VertexBundle[] LeftVertexBundles = vertexBundles; OrderedVertexBundles [0] = vertexBundles [0]; for (int i = 1; i < OrderedVertexBundles.Length; i++) { float distance = 0f; int idOfnextBundle = 0; // check which vertex bundle is the closes clockwise of the current one for (int j = 1; j < LeftVertexBundles.Length; j++) { if (LeftVertexBundles[j] != null) { float newDistance = Vector3.Dot (normal, Vector3.Cross (OrderedVertexBundles [i-1].coordinates - centerPosition, LeftVertexBundles [j].coordinates - centerPosition)); if (newDistance > distance) { distance = newDistance; idOfnextBundle = j; } } } distance = 0f; OrderedVertexBundles [i] = LeftVertexBundles [idOfnextBundle]; Debug.Log ("next point: " + OrderedVertexBundles [i].coordinates); LeftVertexBundles [idOfnextBundle] = null; } vertexBundles = OrderedVertexBundles; }
public void Initialize() { parentVertexBundle = transform.parent.GetComponent <VertexBundle>(); parentObject = transform.parent.parent.parent.parent.GetComponent <ModelingObject>(); initialized = true; }
public void Initialize() { parentVertexBundle = transform.parent.GetComponent<VertexBundle>(); parentObject = transform.parent.parent.parent.parent.GetComponent<ModelingObject>(); initialized = true; }