Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
 private bool RemoveEdge(MEdge edge)
 {
     if (!edgeList.Remove(edge))
     {
         return(false);
     }
     foreach (MFace face in edge.faces)
     {
         RemoveFace(face);
     }
     return(true);
 }
Exemplo n.º 3
0
 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;
         }
     }
 }
Exemplo n.º 4
0
    public float GetClosetEdge(out MEdge edge, Vector3 pos)
    {
        float min = float.MaxValue;
        float temp;
        MEdge te = null;

        foreach (MEdge e in edgeList)
        {
            if ((temp = e.CalcDistance(pos)) < min)
            {
                min = temp;
                te  = e;
            }
        }
        edge = te;
        return(min);
    }
    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));
    }
Exemplo n.º 6
0
 public float GetEdgeLength(MEdge edge)
 {
     return RefEdgeRelativeLength(edge.GetLength());
 }