private void CreateProperty(ref BendProperty property, Transform t) { property = new BendProperty(t, t == trs); //Create a new bend property for each child for (int i = 0; i < bendProperties.Length; i++) { //Search for properties that have the same trasform and copy their settings if (bendProperties[i].transform.transform == t) { property.enabled = bendProperties[i].enabled; property.applyRotation = bendProperties[i].applyRotation; property.applyScale = bendProperties[i].applyScale; property.bendMesh = bendProperties[i].bendMesh; property.bendCollider = bendProperties[i].bendCollider; property.generateLightmapUVs = bendProperties[i].generateLightmapUVs; property.colliderUpdateRate = bendProperties[i].colliderUpdateRate; break; } } if (t.transform != trs) { property.originalPosition = trs.InverseTransformPoint(t.position); property.originalRotation = Quaternion.Inverse(trs.rotation) * t.rotation; } }
private void GetObjects() { List <Transform> transformList = new List <Transform>(); GetTransformsRecursively(base.transform, ref transformList); BendProperty[] array = new BendProperty[transformList.Count]; for (int i = 0; i < transformList.Count; i++) { CreateProperty(ref array[i], transformList[i]); } bendProperties = array; }
public void GetPercent(BendProperty property) { if (property.transform.transform != this.transform) { property.positionPercent = GetPercentage(this.transform.InverseTransformPoint(property.transform.position)); } else { property.positionPercent = GetPercentage(Vector3.zero); } if (property.editMesh != null) { if (property.vertexPercents.Length != property.editMesh.vertexCount) { property.vertexPercents = new Vector3[property.editMesh.vertexCount]; } if (property.editColliderMesh != null) { if (property.colliderVertexPercents.Length != property.editMesh.vertexCount) { property.colliderVertexPercents = new Vector3[property.editColliderMesh.vertexCount]; } } for (int i = 0; i < property.editMesh.vertexCount; i++) { Vector3 localVertex = property.transform.TransformPoint(property.editMesh.vertices[i]); localVertex = this.transform.InverseTransformPoint(localVertex); property.vertexPercents[i] = GetPercentage(localVertex); } if (property.editColliderMesh != null) { for (int i = 0; i < property.editColliderMesh.vertexCount; i++) { Vector3 localVertex = property.transform.TransformPoint(property.editColliderMesh.vertices[i]); localVertex = this.transform.InverseTransformPoint(localVertex); property.colliderVertexPercents[i] = GetPercentage(localVertex); } } } if (property.splineComputer != null) { SplinePoint[] points = property.splineComputer.GetPoints(); property.splinePointPercents = new Vector3[points.Length]; property.primaryTangentPercents = new Vector3[points.Length]; property.secondaryTangentPercents = new Vector3[points.Length]; for (int i = 0; i < points.Length; i++) { property.splinePointPercents[i] = GetPercentage(this.transform.InverseTransformPoint(points[i].position)); property.primaryTangentPercents[i] = GetPercentage(this.transform.InverseTransformPoint(points[i].tangent)); property.secondaryTangentPercents[i] = GetPercentage(this.transform.InverseTransformPoint(points[i].tangent2)); } } }
private void GetObjects() { List <Transform> found = new List <Transform>(); GetTransformsRecursively(this.transform, ref found); BendProperty[] newProperties = new BendProperty[found.Count]; for (int i = 0; i < found.Count; i++) { CreateProperty(ref newProperties[i], found[i]); } bendProperties = newProperties; }
public void GetPercent(BendProperty property) { if (property.transform.transform != base.transform) { property.positionPercent = GetPercentage(base.transform.InverseTransformPoint(property.transform.position)); } else { property.positionPercent = GetPercentage(Vector3.zero); } if (property.editMesh != null) { if (property.vertexPercents.Length != property.editMesh.vertexCount) { property.vertexPercents = new Vector3[property.editMesh.vertexCount]; } if (property.editColliderMesh != null && property.colliderVertexPercents.Length != property.editMesh.vertexCount) { property.colliderVertexPercents = new Vector3[property.editColliderMesh.vertexCount]; } for (int i = 0; i < property.editMesh.vertexCount; i++) { Vector3 position = property.transform.TransformPoint(property.editMesh.vertices[i]); position = base.transform.InverseTransformPoint(position); property.vertexPercents[i] = GetPercentage(position); } if (property.editColliderMesh != null) { for (int j = 0; j < property.editColliderMesh.vertexCount; j++) { Vector3 position2 = property.transform.TransformPoint(property.editColliderMesh.vertices[j]); position2 = base.transform.InverseTransformPoint(position2); property.colliderVertexPercents[j] = GetPercentage(position2); } } } if (property.splineComputer != null) { SplinePoint[] points = property.splineComputer.GetPoints(); property.splinePointPercents = new Vector3[points.Length]; property.primaryTangentPercents = new Vector3[points.Length]; property.secondaryTangentPercents = new Vector3[points.Length]; for (int k = 0; k < points.Length; k++) { property.splinePointPercents[k] = GetPercentage(base.transform.InverseTransformPoint(points[k].position)); property.primaryTangentPercents[k] = GetPercentage(base.transform.InverseTransformPoint(points[k].tangent)); property.secondaryTangentPercents[k] = GetPercentage(base.transform.InverseTransformPoint(points[k].tangent2)); } } }
private void GetObjects() { List <Transform> found = new List <Transform>(); GetTransformsRecursively(transform, ref found); BendProperty[] newProperties = new BendProperty[found.Count]; for (int i = 0; i < found.Count; i++) { CreateProperty(ref newProperties[i], found[i]); } bendProperties = newProperties; SplineComputer splineComponent = GetComponent <SplineComputer>(); _parentIsTheSpline = splineComponent == spline; }
private void CreateProperty(ref BendProperty property, Transform t) { property = new BendProperty(t, t == base.transform); for (int i = 0; i < bendProperties.Length; i++) { if (bendProperties[i].transform.transform == t) { property.applyRotation = bendProperties[i].applyRotation; property.applyScale = bendProperties[i].applyScale; property.bendMesh = bendProperties[i].bendMesh; property.bendCollider = bendProperties[i].bendCollider; property.generateLightmapUVs = bendProperties[i].generateLightmapUVs; property.colliderUpdateRate = bendProperties[i].colliderUpdateRate; break; } } if (t != base.transform) { property.originalPosition = base.transform.InverseTransformPoint(t.position); property.originalRotation = Quaternion.Inverse(base.transform.rotation) * t.rotation; } }
public void BendObject(BendProperty p) { if (!p.enabled) { return; } Quaternion rhs = Quaternion.identity; switch (axis) { case Axis.X: rhs = Quaternion.AngleAxis(-90f, Vector3.up); break; case Axis.Y: rhs = Quaternion.AngleAxis(90f, Vector3.right); break; } GetBendResult(p.positionPercent); p.transform.position = bendResult.position; if (p.applyRotation) { p.transform.rotation = bendResult.rotation * rhs * p.originalRotation; } else { p.transform.rotation = p.originalRotation; } if (p.applyScale) { p.transform.scale = p.originalScale * bendResult.size; } if (p.editMesh != null) { for (int i = 0; i < p.vertexPercents.Length; i++) { GetBendResult(p.vertexPercents[i]); p.editMesh.vertices[i] = bendResult.position; switch (axis) { case Axis.X: p.editMesh.normals[i] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * rhs * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * p.normals[i]; break; case Axis.Y: p.editMesh.normals[i] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * rhs * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * p.normals[i]; break; case Axis.Z: p.editMesh.normals[i] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * p.normals[i]; break; } } p.editMesh.hasUpdate = true; } if (p._editColliderMesh != null) { for (int j = 0; j < p.colliderVertexPercents.Length; j++) { GetBendResult(p.colliderVertexPercents[j]); p.editColliderMesh.vertices[j] = bendResult.position; switch (axis) { case Axis.X: p.editColliderMesh.normals[j] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * rhs * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * p.colliderNormals[j]; break; case Axis.Y: p.editColliderMesh.normals[j] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * rhs * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * p.colliderNormals[j]; break; case Axis.Z: p.editColliderMesh.normals[j] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * p.colliderNormals[j]; break; } } p.editColliderMesh.hasUpdate = true; } if (p.originalSpline == null) { return; } for (int k = 0; k < p.splinePointPercents.Length; k++) { SplinePoint splinePoint = p.originalSpline.points[k]; GetBendResult(p.splinePointPercents[k]); splinePoint.position = bendResult.position; GetBendResult(p.primaryTangentPercents[k]); splinePoint.tangent = bendResult.position; GetBendResult(p.secondaryTangentPercents[k]); splinePoint.tangent2 = bendResult.position; switch (axis) { case Axis.X: splinePoint.normal = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * rhs * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * splinePoint.normal; break; case Axis.Y: splinePoint.normal = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * rhs * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * splinePoint.normal; break; case Axis.Z: splinePoint.normal = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * splinePoint.normal; break; } p.destinationSpline.points[k] = splinePoint; } }
private void CalculatePropertyBounds(ref BendProperty property) { if (property.transform.transform == base.transform) { if (0f < bounds.min.x) { bounds.min.x = 0f; } if (0f < bounds.min.y) { bounds.min.y = 0f; } if (0f < bounds.min.z) { bounds.min.z = 0f; } if (0f > bounds.max.x) { bounds.max.x = 0f; } if (0f > bounds.max.y) { bounds.max.y = 0f; } if (0f > bounds.max.z) { bounds.max.z = 0f; } } else { if (property.originalPosition.x < bounds.min.x) { bounds.min.x = property.originalPosition.x; } if (property.originalPosition.y < bounds.min.y) { bounds.min.y = property.originalPosition.y; } if (property.originalPosition.z < bounds.min.z) { bounds.min.z = property.originalPosition.z; } if (property.originalPosition.x > bounds.max.x) { bounds.max.x = property.originalPosition.x; } if (property.originalPosition.y > bounds.max.y) { bounds.max.y = property.originalPosition.y; } if (property.originalPosition.z > bounds.max.z) { bounds.max.z = property.originalPosition.z; } } if (property.editMesh != null) { for (int i = 0; i < property.editMesh.vertices.Length; i++) { Vector3 position = property.transform.TransformPoint(property.editMesh.vertices[i]); position = base.transform.InverseTransformPoint(position); if (position.x < bounds.min.x) { bounds.min.x = position.x; } if (position.y < bounds.min.y) { bounds.min.y = position.y; } if (position.z < bounds.min.z) { bounds.min.z = position.z; } if (position.x > bounds.max.x) { bounds.max.x = position.x; } if (position.y > bounds.max.y) { bounds.max.y = position.y; } if (position.z > bounds.max.z) { bounds.max.z = position.z; } } } if (property.editColliderMesh != null) { for (int j = 0; j < property.editColliderMesh.vertices.Length; j++) { Vector3 position2 = property.transform.TransformPoint(property.editColliderMesh.vertices[j]); position2 = base.transform.InverseTransformPoint(position2); if (position2.x < bounds.min.x) { bounds.min.x = position2.x; } if (position2.y < bounds.min.y) { bounds.min.y = position2.y; } if (position2.z < bounds.min.z) { bounds.min.z = position2.z; } if (position2.x > bounds.max.x) { bounds.max.x = position2.x; } if (position2.y > bounds.max.y) { bounds.max.y = position2.y; } if (position2.z > bounds.max.z) { bounds.max.z = position2.z; } } } if (property.originalSpline != null) { for (int k = 0; k < property.originalSpline.points.Length; k++) { Vector3 vector = base.transform.InverseTransformPoint(property.originalSpline.points[k].position); if (vector.x < bounds.min.x) { bounds.min.x = vector.x; } if (vector.y < bounds.min.y) { bounds.min.y = vector.y; } if (vector.z < bounds.min.z) { bounds.min.z = vector.z; } if (vector.x > bounds.max.x) { bounds.max.x = vector.x; } if (vector.y > bounds.max.y) { bounds.max.y = vector.y; } if (vector.z > bounds.max.z) { bounds.max.z = vector.z; } } } bounds.CreateFromMinMax(bounds.min, bounds.max); }
private void CalculatePropertyBounds(ref BendProperty property) { if (property.transform.transform == this.transform) { if (0f < bounds.min.x) { bounds.min.x = 0f; } if (0f < bounds.min.y) { bounds.min.y = 0f; } if (0f < bounds.min.z) { bounds.min.z = 0f; } if (0f > bounds.max.x) { bounds.max.x = 0f; } if (0f > bounds.max.y) { bounds.max.y = 0f; } if (0f > bounds.max.z) { bounds.max.z = 0f; } } else { if (property.originalPosition.x < bounds.min.x) { bounds.min.x = property.originalPosition.x; } if (property.originalPosition.y < bounds.min.y) { bounds.min.y = property.originalPosition.y; } if (property.originalPosition.z < bounds.min.z) { bounds.min.z = property.originalPosition.z; } if (property.originalPosition.x > bounds.max.x) { bounds.max.x = property.originalPosition.x; } if (property.originalPosition.y > bounds.max.y) { bounds.max.y = property.originalPosition.y; } if (property.originalPosition.z > bounds.max.z) { bounds.max.z = property.originalPosition.z; } } if (property.editMesh != null) { for (int n = 0; n < property.editMesh.vertices.Length; n++) { Vector3 localPos = property.transform.TransformPoint(property.editMesh.vertices[n]); localPos = this.transform.InverseTransformPoint(localPos); if (localPos.x < bounds.min.x) { bounds.min.x = localPos.x; } if (localPos.y < bounds.min.y) { bounds.min.y = localPos.y; } if (localPos.z < bounds.min.z) { bounds.min.z = localPos.z; } if (localPos.x > bounds.max.x) { bounds.max.x = localPos.x; } if (localPos.y > bounds.max.y) { bounds.max.y = localPos.y; } if (localPos.z > bounds.max.z) { bounds.max.z = localPos.z; } } } if (property.editColliderMesh != null) { for (int n = 0; n < property.editColliderMesh.vertices.Length; n++) { Vector3 localPos = property.transform.TransformPoint(property.editColliderMesh.vertices[n]); localPos = this.transform.InverseTransformPoint(localPos); if (localPos.x < bounds.min.x) { bounds.min.x = localPos.x; } if (localPos.y < bounds.min.y) { bounds.min.y = localPos.y; } if (localPos.z < bounds.min.z) { bounds.min.z = localPos.z; } if (localPos.x > bounds.max.x) { bounds.max.x = localPos.x; } if (localPos.y > bounds.max.y) { bounds.max.y = localPos.y; } if (localPos.z > bounds.max.z) { bounds.max.z = localPos.z; } } } if (property.originalSpline != null) { for (int n = 0; n < property.originalSpline.points.Length; n++) { Vector3 localPos = this.transform.InverseTransformPoint(property.originalSpline.points[n].position); if (localPos.x < bounds.min.x) { bounds.min.x = localPos.x; } if (localPos.y < bounds.min.y) { bounds.min.y = localPos.y; } if (localPos.z < bounds.min.z) { bounds.min.z = localPos.z; } if (localPos.x > bounds.max.x) { bounds.max.x = localPos.x; } if (localPos.y > bounds.max.y) { bounds.max.y = localPos.y; } if (localPos.z > bounds.max.z) { bounds.max.z = localPos.z; } } } bounds.CreateFromMinMax(bounds.min, bounds.max); }
public void BendObject(BendProperty p) { if (!p.enabled) { return; } GetevalResult(p.positionPercent); p.transform.position = evalResult.position; if (p.applyRotation) { //p.transform.rotation = evalResult.rotation * axisRotation * p.originalRotation; p.transform.rotation = bendRotation * (Quaternion.Inverse(p.parentRotation) * p.originalRotation); } else { p.transform.rotation = p.originalRotation; } if (p.applyScale) { p.transform.scale = p.originalScale * evalResult.size; } Matrix4x4 toLocalMatrix = Matrix4x4.TRS(p.transform.position, p.transform.rotation, p.transform.scale).inverse; if (p.editMesh != null) { BendMesh(p.vertexPercents, p.normals, p.editMesh, toLocalMatrix); p.editMesh.hasUpdate = true; } if (p._editColliderMesh != null) { BendMesh(p.colliderVertexPercents, p.colliderNormals, p.editColliderMesh, toLocalMatrix); p.editColliderMesh.hasUpdate = true; } if (p.originalSpline != null) { for (int n = 0; n < p.splinePointPercents.Length; n++) { SplinePoint point = p.originalSpline.points[n]; GetevalResult(p.splinePointPercents[n]); point.position = evalResult.position; GetevalResult(p.primaryTangentPercents[n]); point.tangent = evalResult.position; GetevalResult(p.secondaryTangentPercents[n]); point.tangent2 = evalResult.position; switch (axis) { case Axis.X: point.normal = Quaternion.LookRotation(evalResult.forward, evalResult.up) * Quaternion.FromToRotation(Vector3.up, evalResult.up) * point.normal; break; case Axis.Y: point.normal = Quaternion.LookRotation(evalResult.forward, evalResult.up) * Quaternion.FromToRotation(Vector3.up, evalResult.up) * point.normal; break; case Axis.Z: point.normal = Quaternion.LookRotation(evalResult.forward, evalResult.up) * point.normal; break; } p.destinationSpline.points[n] = point; } } }
public void BendObject(BendProperty p) { if (!p.enabled) { return; } Quaternion axisRotation = Quaternion.identity; switch (axis) { case Axis.X: axisRotation = Quaternion.AngleAxis(-90f, Vector3.up); break; case Axis.Y: axisRotation = Quaternion.AngleAxis(90f, Vector3.right); break; } GetBendResult(p.positionPercent); if (this.transform == computer.transform && p.transform.transform == this.transform) { } else { p.transform.position = bendResult.position; if (p.applyRotation) { p.transform.rotation = bendResult.rotation * axisRotation * p.originalRotation; } else { p.transform.rotation = p.originalRotation; } if (p.applyScale) { p.transform.scale = p.originalScale * bendResult.size; } } if (p.editMesh != null) { for (int n = 0; n < p.vertexPercents.Length; n++) { GetBendResult(p.vertexPercents[n]); p.editMesh.vertices[n] = bendResult.position; switch (axis) { case Axis.X: p.editMesh.normals[n] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * axisRotation * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * p.normals[n]; break; case Axis.Y: p.editMesh.normals[n] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * axisRotation * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * p.normals[n]; break; case Axis.Z: p.editMesh.normals[n] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * p.normals[n]; break; } } p.editMesh.hasUpdate = true; } if (p.editColliderMesh != null) { for (int n = 0; n < p.colliderVertexPercents.Length; n++) { GetBendResult(p.colliderVertexPercents[n]); p.editColliderMesh.vertices[n] = bendResult.position; switch (axis) { case Axis.X: p.editColliderMesh.normals[n] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * axisRotation * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * p.colliderNormals[n]; break; case Axis.Y: p.editColliderMesh.normals[n] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * axisRotation * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * p.colliderNormals[n]; break; case Axis.Z: p.editColliderMesh.normals[n] = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * p.colliderNormals[n]; break; } } p.editColliderMesh.hasUpdate = true; } if (p.originalSpline != null) { for (int n = 0; n < p.splinePointPercents.Length; n++) { SplinePoint point = p.originalSpline.points[n]; GetBendResult(p.splinePointPercents[n]); point.position = bendResult.position; GetBendResult(p.primaryTangentPercents[n]); point.tangent = bendResult.position; GetBendResult(p.secondaryTangentPercents[n]); point.tangent2 = bendResult.position; switch (axis) { case Axis.X: point.normal = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * axisRotation * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * point.normal; break; case Axis.Y: point.normal = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * axisRotation * Quaternion.FromToRotation(Vector3.up, bendResult.normal) * point.normal; break; case Axis.Z: point.normal = Quaternion.LookRotation(bendResult.direction, bendResult.normal) * point.normal; break; } p.destinationSpline.points[n] = point; } } }