/* * Handles creation of fibre-optic cable mesh following bezier curve. * Only run through inspector button. * * I think running this every frame/fixedupdate might be a bit much, * so no moving fibre-optics for the moment */ public void CreateBezierMesh() { if (bezierMeshPrefab == null) { Debug.LogError("No BezierMeshPrefab given"); return; } Debug.Log("Creating Bezier Mesh..."); GameObject meshObject = Instantiate(bezierMeshPrefab, transform.parent); meshObject.transform.position = Vector3.zero; meshObject.transform.rotation = Quaternion.identity; Mesh fibreMesh = FibreOpticMeshCreator.CreateMeshForBezier(GetBezierPoints()); meshObject.GetComponent <MeshFilter>().mesh = fibreMesh; meshObject.GetComponent <MeshCollider>().sharedMesh = fibreMesh; Debug.Log("Done Creating Mesh"); }
private void OnSceneGUI() { FibreOpticController fibre = target as FibreOpticController; Info <Vector3, Vector3, Vector3, Vector3> bezierPoints = fibre.GetBezierPoints(); if (bezierPoints == null) { return; } Transform fibreTransform = fibre.transform; Vector3 point1 = bezierPoints.arg0; Vector3 point2 = bezierPoints.arg3; Vector3 tangent1 = bezierPoints.arg1; Vector3 tangent2 = bezierPoints.arg2; Handles.DrawBezier(point1, point2, tangent1, tangent2, Color.red, null, 1f); Handles.color = Color.green; Handles.DrawLine(point1, tangent1); Quaternion handleRotation = Tools.pivotRotation == PivotRotation.Local ? fibreTransform.rotation : Quaternion.identity; EditorGUI.BeginChangeCheck(); tangent1 = Handles.DoPositionHandle(tangent1, handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(fibre, "Move Point"); EditorUtility.SetDirty(fibre); fibre.bezierTargetPosition = fibreTransform.InverseTransformPoint(tangent1); } testVertices = FibreOpticMeshCreator.GetBezierMeshVertices(fibre.GetBezierPoints()); if (testVertices != null) { DrawWireframeBezierMesh(); } }