public void SetRefEdge(MLinearEdge edge) { refEdge = edge; if (refEdge != null) { refEdgeLength = refEdge.GetLength(); } }
public void OnLeave(IState nextState) { sceneManager.rightEvents.TriggerPressed -= rightTriggerPressed; ClearSelectPoint(); activeEdge = null; curObject = null; }
private void UpdateAdjustLen() { Vector3 pos = curObj.worldToLocalMatrix.MultiplyPoint(sceneManager.rightControllerPosition); MFace f = selectedEntity[0] as MFace; MPoint p = selectedEntity[1] as MPoint; pos = f.GetVerticalPoint(p.position, pos); float relativeLen = curObj.RefEdgeRelativeLength(Vector3.Distance(p.position, pos)); pos = RevisePos(ref relativeLen, p.position, pos); activePoint.SetPosition(pos); activeTextMesh.GetComponentInChildren <TextMesh>().text = relativeLen.ToString(); activeTextMesh.transform.position = sceneManager.rightControllerPosition + MDefinitions.DEFAULT_ACTIVE_TEXT_OFFSET; if (sceneManager.camera != null) { activeTextMesh.transform.rotation = Quaternion.LookRotation((sceneManager.camera.transform.position - activeTextMesh.transform.position) * -1, Vector3.up); } if (activeEdge == null) { activeEdge = new MLinearEdge(p, activePoint); activeEdge.entityStatus = MEntity.MEntityStatus.ACTIVE; activeEdge.end.edges.Add(activeEdge); } activePoint.Render(curObj.localToWorldMatrix); if (activeEdge != null && activeEdge.IsValid()) { activeEdge.Render(curObj.localToWorldMatrix); } }
private void InitRefEdge() { refEdge = mesh.GetLinearEdge(); if (refEdge != null) { refEdgeLength = refEdge.GetLength(); } }
private void AddEdge(MLinearEdge edge) { if (edge.entityStatus != MEntity.MEntityStatus.SPECIAL) { edge.entityStatus = MEntity.MEntityStatus.SELECT; } selectEdges.Add(edge); }
private void ResetStatus() { status = STATUS.DEFAULT; ClearSelectedEntity(); activeTextMesh.SetActive(false); activeEdge = null; curObj = null; }
private void RemoveEdge(MLinearEdge edge) { if (edge.entityStatus == MEntity.MEntityStatus.SELECT) { edge.entityStatus = MEntity.MEntityStatus.DEFAULT; } selectEdges.Remove(edge); }
private void ResetStatus() { status = STATUS.SELECT_FACE; SelectEntity(ref selectFace, null); activeTextMesh.SetActive(false); activeEdge = null; curObj = null; validAngle = false; }
private void SelectEdge(MLinearEdge edge) { if (selectEdges.Contains(edge)) { RemoveEdge(edge); } else { AddEdge(edge); } }
private int AddEdgeToMesh(MEdge edge) { int i, j; if ((i = edgeList.IndexOf(edge)) == -1) { edgeList.Add(edge); switch (edge.edgeType) { case MEdge.MEdgeType.LINEAR: MLinearEdge le = edge as MLinearEdge; j = AddPointToMesh(le.start); if (j != -1) { le.start = pointList[j]; } le.start.edges.Add(edge); j = AddPointToMesh(le.end); if (j != -1) { le.end = pointList[j]; } le.end.edges.Add(edge); break; case MEdge.MEdgeType.CURVE: MCurveEdge ce = edge as MCurveEdge; foreach (Vector3 v in ce.mesh.vertices) { boundingBox.AdjustToContain(v); } j = AddPointToMesh(ce.center); if (j != -1) { ce.center = pointList[j]; } ce.center.edges.Add(edge); break; case MEdge.MEdgeType.GENERAL: MGeneralEdge ge = edge as MGeneralEdge; foreach (Vector3 v in ge.points) { boundingBox.AdjustToContain(v); } break; default: Debug.Log("MMesh: AddEdgeToList: unhandled edge type " + edge.edgeType); break; } } return(i); }
public static MMesh GetMMesh() { MMesh mesh = new MMesh(); MPoint a = mesh.CreatePoint(new Vector3(Mathf.Sqrt(3) / 4, -0.75f, -0.25f)); MPoint b = mesh.CreatePoint(new Vector3(-Mathf.Sqrt(3) / 4, -0.75f, -0.25f)); MPoint c = mesh.CreatePoint(new Vector3(0, -0.75f, 0.5f)); MPoint e = mesh.CreatePoint(new Vector3(Mathf.Sqrt(3) / 4, 0.75f, -0.25f)); MPoint f = mesh.CreatePoint(new Vector3(-Mathf.Sqrt(3) / 4, 0.75f, -0.25f)); MPoint g = mesh.CreatePoint(new Vector3(0, 0.75f, 0.5f)); MLinearEdge ab = mesh.CreateLinearEdge(a, b); MLinearEdge bc = mesh.CreateLinearEdge(b, c); MLinearEdge ca = mesh.CreateLinearEdge(c, a); MLinearEdge ef = mesh.CreateLinearEdge(e, f); MLinearEdge fg = mesh.CreateLinearEdge(f, g); MLinearEdge ge = mesh.CreateLinearEdge(g, e); MLinearEdge ae = mesh.CreateLinearEdge(a, e); MLinearEdge bf = mesh.CreateLinearEdge(b, f); MLinearEdge cg = mesh.CreateLinearEdge(c, g); List <MLinearEdge> abc = new List <MLinearEdge>(); abc.Add(ab); abc.Add(bc); abc.Add(ca); mesh.CreatePolygonFace(abc); List <MLinearEdge> efg = new List <MLinearEdge>(); efg.Add(ef); efg.Add(fg); efg.Add(ge); mesh.CreatePolygonFace(efg); List <MLinearEdge> abef = new List <MLinearEdge>(); abef.Add(ab); abef.Add(ae); abef.Add(ef); abef.Add(bf); mesh.CreatePolygonFace(abef); List <MLinearEdge> bcfg = new List <MLinearEdge>(); bcfg.Add(bc); bcfg.Add(bf); bcfg.Add(fg); bcfg.Add(cg); mesh.CreatePolygonFace(bcfg); List <MLinearEdge> cage = new List <MLinearEdge>(); cage.Add(ca); cage.Add(cg); cage.Add(ge); cage.Add(ae); mesh.CreatePolygonFace(cage); return(mesh); }
public void OnLeave(IState nextState) { sceneManager.rightEvents.TriggerPressed -= rightTriggerPressed; foreach (MObject obj in sceneManager.objects) { MLinearEdge refEdge = obj.refEdge; if (refEdge != null) { refEdge.entityStatus = MEntity.MEntityStatus.DEFAULT; } } }
private string GetEdgeString(MLinearEdge edge, MObject obj) { string str = null; string s1 = obj.GetPointIdentifier(edge.start); string s2 = obj.GetPointIdentifier(edge.end); if (s1 != null && s2 != null) { str = s1 + s2; } return(str); }
public void OnEnter(StateMachine machine, IState prevState, object param) { sceneManager.rightEvents.TriggerPressed += rightTriggerPressed; foreach (MObject obj in sceneManager.objects) { MLinearEdge refEdge = obj.refEdge; if (refEdge != null) { refEdge.entityStatus = MEntity.MEntityStatus.SPECIAL; } } }
public void OnLeave(IState nextState) { sceneManager.rightEvents.TriggerPressed -= rightTriggerPressed; ClearSelectedEntity(); textMesh.SetActive(false); foreach (MObject obj in sceneManager.objects) { MLinearEdge refEdge = obj.refEdge; if (refEdge != null) { refEdge.entityStatus = MEntity.MEntityStatus.DEFAULT; } } }
public void OnEnter(StateMachine machine, IState prevState, object param) { sceneManager.rightEvents.TriggerPressed += rightTriggerPressed; sceneManager.rightEvents.GripPressed += rightGripPressed; status = STATUS.DEFAULT; activePoint.entityStatus = MEntity.MEntityStatus.ACTIVE; curObj = null; foreach (MObject obj in sceneManager.objects) { MLinearEdge refEdge = obj.refEdge; if (refEdge != null) { refEdge.entityStatus = MEntity.MEntityStatus.SPECIAL; } } }
public static MMesh GetMMesh() { MMesh mesh = new MMesh(); MPoint a = mesh.CreatePoint(new Vector3(Mathf.Sqrt(3) / 2, 0, -0.5f)); MPoint b = mesh.CreatePoint(new Vector3(-Mathf.Sqrt(3) / 2, 0, -0.5f)); MPoint c = mesh.CreatePoint(new Vector3(0, 0, 1)); MLinearEdge ab = mesh.CreateLinearEdge(a, b); MLinearEdge bc = mesh.CreateLinearEdge(b, c); MLinearEdge ca = mesh.CreateLinearEdge(c, a); List <MLinearEdge> abc = new List <MLinearEdge>(); abc.Add(ab); abc.Add(bc); abc.Add(ca); mesh.CreatePolygonFace(abc); return(mesh); }
private void RightTriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e) { if (sceneManager.activeEntity.entity != null) { MEdge edge = sceneManager.activeEntity.entity as MEdge; if (edge.edgeType == MEdge.MEdgeType.LINEAR) { MLinearEdge refEdge = sceneManager.activeEntity.obj.refEdge; if (refEdge != null) { refEdge.entityStatus = MEntity.MEntityStatus.DEFAULT; } sceneManager.activeEntity.obj.SetRefEdge((MLinearEdge)edge); edge.entityStatus = MEntity.MEntityStatus.SPECIAL; } } }
public void OnEnter(StateMachine machine, IState prevState, object param) { sceneManager.rightEvents.TriggerPressed += rightTriggerPressed; foreach (MObject obj in sceneManager.objects) { MLinearEdge refEdge = obj.refEdge; if (refEdge != null) { refEdge.entityStatus = MEntity.MEntityStatus.SPECIAL; } obj.ActiveTextMesh(); } selectLengthCount = new float[sceneManager.objects.Count]; selectSurfaceCount = new float[sceneManager.objects.Count]; objectSurface = new float[sceneManager.objects.Count]; CalcSurfaceAndVolumn(); UpdateTextPlane(); }
private void RightTriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e) { if (sceneManager.activeEntity.entity != null && ((MEdge)sceneManager.activeEntity.entity).edgeType == MEdge.MEdgeType.LINEAR) { if (curObject == null) { curObject = sceneManager.activeEntity.obj; } else { if (sceneManager.activeEntity.obj != curObject) { ResetStatus(); return; } } MLinearEdge le = sceneManager.activeEntity.entity as MLinearEdge; if (selectEdges.Count > 1) { Vector3 normal = Vector3.Cross(selectEdges[0].direction, selectEdges[1].direction).normalized; if (!MHelperFunctions.Perpendicular(normal, le.direction)) { ResetStatus(); return; } } SelectEdge(le); if (selectEdges.Count < 3) { curObject = null; return; } MPolygonFace face = new MPolygonFace(selectEdges); if (face.IsValid()) { curObject.CreatePolygonFace(new List <MLinearEdge>(selectEdges)); ResetStatus(); } } else { ResetStatus(); } }
private void UpdateActiveEdge() { Vector3 v = curObject.worldToLocalMatrix.MultiplyPoint(sceneManager.rightControllerPosition); if (activeEdge == null) { activeEdge = new MLinearEdge(selectPoint, new MPoint(v)); activeEdge.entityStatus = MEntity.MEntityStatus.ACTIVE; activeEdge.end.edges.Add(activeEdge); } else { activeEdge.end.SetPosition(v); } if (activeEdge != null && activeEdge.IsValid()) { activeEdge.Render(curObject.localToWorldMatrix); } }
public MLinearEdge CreateLinearEdge(MPoint start, MPoint end) { MLinearEdge edge = new MLinearEdge(start, end); if (!edge.IsValid()) { return(null); } int i; if ((i = AddEdgeToMesh(edge)) != -1) { return(edgeList[i] as MLinearEdge); } else { return(edge); } }
private void RightTriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e) { switch (status) { case STATUS.DEFAULT: obj.transform.position = sceneManager.rightControllerPosition; stablePoint = obj.worldToLocalMatrix.MultiplyPoint(sceneManager.rightControllerPosition); status = STATUS.CREATE_EDGE; activeEdges[0] = new MLinearEdge(new MPoint(stablePoint), new MPoint(activePoint.position)); activeEdges[0].end.edges.Add(activeEdges[0]); break; case STATUS.CREATE_EDGE: activeEdges[1] = new MLinearEdge(activeEdges[0].start, new MPoint(activePoint.position + activeEdges[0].start.position - activeEdges[0].end.position)); activeEdges[1].end.edges.Add(activeEdges[1]); activeEdges[2] = new MLinearEdge(activeEdges[0].end, new MPoint(activePoint.position)); activeEdges[2].end.edges.Add(activeEdges[2]); activeEdges[3] = new MLinearEdge(activeEdges[1].end, activeEdges[2].end); activeEdges[3].start.edges.Add(activeEdges[3]); activeEdges[3].end.edges.Add(activeEdges[3]); activeFace = new MPolygonFace(new List <MLinearEdge>(activeEdges)); activeEdges[1].faces.Add(activeFace); activeEdges[2].faces.Add(activeFace); activeEdges[3].faces.Add(activeFace); activeTextMesh.SetActive(true); status = STATUS.STRETCH; break; case STATUS.STRETCH: if (activeFace != null && activeFace.IsValid()) { status = STATUS.FINISH; obj.CreatePolygonFace(new List <MLinearEdge>(activeEdges)); sceneManager.objects.Add(obj); sceneManager.sceneStateMachine.SwitchState((uint)SceneManager.SceneStatus.TRANSFORM, null); } else { ResetStatus(); } break; } }
private void UpdateConnecting() { Vector3 pos = curObj.worldToLocalMatrix.MultiplyPoint(sceneManager.rightControllerPosition); MPoint p = selectedEntity[0] as MPoint; if (sceneManager.activeEntity.entity != null) { pos = sceneManager.activeEntity.entity.GetProjection(p.position, pos); } activePoint.SetPosition(pos); if (activeEdge == null) { activeEdge = new MLinearEdge(p, activePoint); activeEdge.entityStatus = MEntity.MEntityStatus.ACTIVE; activeEdge.end.edges.Add(activeEdge); } activePoint.Render(curObj.localToWorldMatrix); if (activeEdge != null && activeEdge.IsValid()) { activeEdge.Render(curObj.localToWorldMatrix); } }
private void CalcNormal() { MLinearEdge e1 = edgeList[0]; MLinearEdge e2 = e1; int i; int count = edgeList.Count; for (i = 1; i < count; i++) { e2 = edgeList[i]; if (!e1.Parallel(e2)) { break; } } if (i != count) { normal = Vector3.Normalize(Vector3.Cross(e1.direction, e2.direction)); } else { Debug.Log("MPolygonFace: CalcNormal: wrong edgeList"); buildSuccess = false; } if (buildSuccess) { Vector3 p = sortedPoints[0].position; count = sortedPoints.Count; for (i = 1; i < count; i++) { Vector3 v = MHelperFunctions.PointProjectionInFace(sortedPoints[i].position, normal, sortedPoints[0].position); if (Vector3.Distance(sortedPoints[i].position, v) >= MDefinitions.VECTOR3_PRECISION) { buildSuccess = false; return; } } } }
public static MMesh GetMMesh() { mesh = new MMesh(); MPoint a = mesh.CreatePoint(new Vector3(Mathf.Sqrt(3) / 2, -0.75f, -0.5f)); MPoint b = mesh.CreatePoint(new Vector3(-Mathf.Sqrt(3) / 2, -0.75f, -0.5f)); MPoint c = mesh.CreatePoint(new Vector3(0, -0.75f, 1)); MPoint d = mesh.CreatePoint(new Vector3(0, 0.75f, 0)); MLinearEdge ab = mesh.CreateLinearEdge(a, b); MLinearEdge bc = mesh.CreateLinearEdge(b, c); MLinearEdge ca = mesh.CreateLinearEdge(c, a); MLinearEdge ad = mesh.CreateLinearEdge(a, d); MLinearEdge bd = mesh.CreateLinearEdge(b, d); MLinearEdge cd = mesh.CreateLinearEdge(c, d); List <MLinearEdge> abc = new List <MLinearEdge>(); abc.Add(ab); abc.Add(bc); abc.Add(ca); mesh.CreatePolygonFace(abc); List <MLinearEdge> abd = new List <MLinearEdge>(); abd.Add(ab); abd.Add(bd); abd.Add(ad); mesh.CreatePolygonFace(abd); List <MLinearEdge> bcd = new List <MLinearEdge>(); bcd.Add(bc); bcd.Add(bd); bcd.Add(cd); mesh.CreatePolygonFace(bcd); List <MLinearEdge> cad = new List <MLinearEdge>(); cad.Add(ca); cad.Add(cd); cad.Add(ad); mesh.CreatePolygonFace(cad); return(mesh); }
private void RightTriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e) { activeEdge = null; if (sceneManager.activeEntity.entity == null || sceneManager.activeEntity.entity.entityType != MEntity.MEntityType.POINT) { connecting = false; curObject = null; ClearSelectPoint(); } else if (connecting) { if (curObject != sceneManager.activeEntity.obj) { curObject = sceneManager.activeEntity.obj; SelectPoint((MPoint)sceneManager.activeEntity.entity); } else if ((MPoint)sceneManager.activeEntity.entity == selectPoint) { connecting = false; curObject = null; ClearSelectPoint(); } else { MPoint p = (MPoint)sceneManager.activeEntity.entity; curObject.CreateLinearEdge(selectPoint, p); connecting = false; curObject = null; ClearSelectPoint(); } } else { connecting = true; curObject = sceneManager.activeEntity.obj; SelectPoint((MPoint)sceneManager.activeEntity.entity); } }
public bool Perpendicular(MLinearEdge edge) { return(MHelperFunctions.Perpendicular(direction, edge.direction)); }
private void RightTriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e) { if (sceneManager.pointerOnMenu) { return; } switch (status) { case STATUS.DEFAULT: if (sceneManager.activeEntity.entity != null) { if (sceneManager.activeEntity.entity.entityType == MEntity.MEntityType.POINT) { status = STATUS.CONNECTING; activeEdge = null; SelectEntity(sceneManager.activeEntity.entity); curObj = sceneManager.activeEntity.obj; } else if (((MFace)sceneManager.activeEntity.entity).faceType == MFace.MFaceType.POLYGON || ((MFace)sceneManager.activeEntity.entity).faceType == MFace.MFaceType.CIRCLE || ((MFace)sceneManager.activeEntity.entity).faceType == MFace.MFaceType.GENERAL_FLAT) { status = STATUS.SELECT_POINT; SelectEntity(sceneManager.activeEntity.entity); curObj = sceneManager.activeEntity.obj; } } break; case STATUS.SELECT_POINT: if (sceneManager.activeEntity.entity == null) { ResetStatus(); } else { SelectEntity(sceneManager.activeEntity.entity); activeTextMesh.SetActive(true); status = STATUS.ADJUST_LEN; activeEdge = null; } break; case STATUS.CONNECTING: if (sceneManager.activeEntity.entity == null || (sceneManager.activeEntity.entity.entityType == MEntity.MEntityType.EDGE && ((MEdge)sceneManager.activeEntity.entity).edgeType != MEdge.MEdgeType.LINEAR) || (sceneManager.activeEntity.entity.entityType == MEntity.MEntityType.FACE && ((MFace)sceneManager.activeEntity.entity).faceType == MFace.MFaceType.GENERAL_CURVE) ) { ResetStatus(); } else { curObj.CreateLinearEdge((MPoint)selectedEntity[0], new MPoint(activePoint.position)); ResetStatus(); } break; case STATUS.ADJUST_LEN: curObj.CreateLinearEdge((MPoint)selectedEntity[1], new MPoint(activePoint.position)); ResetStatus(); break; } }
public bool Parallel(MLinearEdge edge) { return(MHelperFunctions.Parallel(direction, edge.direction)); }