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 MRelation GetEntityRelation(MEntityPair e1, MEntityPair e2) { MEntityPair lowerEntity, higherEntity; CompareEntity(e1, e2, out lowerEntity, out higherEntity); bool shareObject = (e1.obj == e2.obj); MObject obj = null; if (shareObject) { obj = e1.obj; } float distance = -1; float angle = 0; MRelation.EntityRelationType type; if (higherEntity.entity.entityType == MEntity.MEntityType.POINT) //点点关系 { type = MRelation.EntityRelationType.POINT_POINT; if (shareObject) { Vector3 p1 = ((MPoint)lowerEntity.entity).position; Vector3 p2 = ((MPoint)higherEntity.entity).position; distance = obj.RefEdgeRelativeLength(Vector3.Distance(p1, p2)); } } else if (lowerEntity.entity.entityType == MEntity.MEntityType.POINT && higherEntity.entity.entityType == MEntity.MEntityType.EDGE) //点线关系 { type = MRelation.EntityRelationType.POINT_EDGE; if (shareObject) { MEdge edge = (MEdge)higherEntity.entity; if (edge.edgeType != MEdge.MEdgeType.LINEAR) { return(null); } distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceP2L( ((MPoint)lowerEntity.entity).position, ((MLinearEdge)edge).direction, ((MLinearEdge)edge).end.position)); } } else if (higherEntity.entity.entityType == MEntity.MEntityType.EDGE) //线线关系 { type = MRelation.EntityRelationType.EDGE_EDGE; MEdge edge1 = (MEdge)lowerEntity.entity; MEdge edge2 = (MEdge)higherEntity.entity; if (edge1.edgeType != MEdge.MEdgeType.LINEAR || edge2.edgeType != MEdge.MEdgeType.LINEAR) { return(null); } MLinearEdge le1 = edge1 as MLinearEdge; MLinearEdge le2 = edge2 as MLinearEdge; if (shareObject) { distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceL2L(le1.start.position, le1.direction, le2.start.position, le2.direction)); angle = MHelperFunctions.CalcAngle(le1.direction, le2.direction); } else { angle = MHelperFunctions.CalcAngle( lowerEntity.obj.localToWorldMatrix.MultiplyVector(le1.direction), higherEntity.obj.localToWorldMatrix.MultiplyVector(le2.direction)); } } else if (lowerEntity.entity.entityType == MEntity.MEntityType.POINT) //点面关系 { type = MRelation.EntityRelationType.POINT_FACE; MFace face = (MFace)higherEntity.entity; Vector3 normal; Vector3 facePoint; if (shareObject) { if (face.faceType == MFace.MFaceType.POLYGON) { normal = ((MPolygonFace)face).normal; facePoint = ((MPolygonFace)face).edgeList[0].start.position; } else if (face.faceType == MFace.MFaceType.CIRCLE) { normal = ((MCircleFace)face).circle.normal; facePoint = ((MCircleFace)face).circle.center.position; } else { return(null); } distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceP2F(((MPoint)lowerEntity.entity).position, normal, facePoint)); } } else if (lowerEntity.entity.entityType == MEntity.MEntityType.EDGE) //线面关系 { type = MRelation.EntityRelationType.EDGE_FACE; MEdge edge = (MEdge)lowerEntity.entity; if (edge.edgeType != MEdge.MEdgeType.LINEAR) { return(null); } MFace face = (MFace)higherEntity.entity; Vector3 normal; Vector3 facePoint; if (face.faceType == MFace.MFaceType.POLYGON) { normal = ((MPolygonFace)face).normal; facePoint = ((MPolygonFace)face).edgeList[0].start.position; } else if (face.faceType == MFace.MFaceType.CIRCLE) { normal = ((MCircleFace)face).circle.normal; facePoint = ((MCircleFace)face).circle.center.position; } else { return(null); } if (shareObject) { angle = 90 - MHelperFunctions.CalcAngle(((MLinearEdge)edge).direction, normal); if (MHelperFunctions.FloatEqual(angle, 0)) { distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceP2F(((MLinearEdge)edge).start.position, normal, facePoint)); } } else { angle = 90 - MHelperFunctions.CalcAngle( lowerEntity.obj.localToWorldMatrix.MultiplyVector(((MLinearEdge)edge).direction), higherEntity.obj.localToWorldMatrix.MultiplyVector(normal)); } } else //面面关系 { type = MRelation.EntityRelationType.FACE_FACE; MFace f1 = (MFace)lowerEntity.entity; MFace f2 = (MFace)higherEntity.entity; Vector3 normal1, normal2; Vector3 facePoint1, facePoint2; if (f1.faceType == MFace.MFaceType.POLYGON) { normal1 = ((MPolygonFace)f1).normal; facePoint1 = ((MPolygonFace)f1).edgeList[0].start.position; } else if (f1.faceType == MFace.MFaceType.CIRCLE) { normal1 = ((MCircleFace)f1).circle.normal; facePoint1 = ((MCircleFace)f1).circle.center.position; } else { return(null); } if (f2.faceType == MFace.MFaceType.POLYGON) { normal2 = ((MPolygonFace)f2).normal; facePoint2 = ((MPolygonFace)f2).edgeList[0].start.position; } else if (f2.faceType == MFace.MFaceType.CIRCLE) { normal2 = ((MCircleFace)f2).circle.normal; facePoint2 = ((MCircleFace)f2).circle.center.position; } else { return(null); } if (shareObject) { angle = MHelperFunctions.CalcAngle(normal1, normal2); if (MHelperFunctions.FloatEqual(angle, 0)) { distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceP2F(facePoint1, normal2, facePoint2)); } } else { angle = MHelperFunctions.CalcAngle( lowerEntity.obj.localToWorldMatrix.MultiplyVector(normal1), higherEntity.obj.localToWorldMatrix.MultiplyVector(normal2)); } } return(new MRelation(type, lowerEntity, higherEntity, distance, angle, shareObject)); }