コード例 #1
0
    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);
        }
    }
コード例 #2
0
    public float GetClosetFace(out MFace face, Vector3 pos, bool useBoundingBox, float precision)
    {
        float min = float.MaxValue;
        float temp;
        MFace tf = null;

        foreach (MFace f in faceList)
        {
            if (useBoundingBox && !f.boundingBox.Contains(pos, precision))
            {
                continue;
            }
            if ((temp = f.CalcDistance(pos)) < min)
            {
                min = temp;
                tf  = f;
            }
        }
        face = tf;
        return(min);
    }
コード例 #3
0
    private string GetFaceString(MFace face, MObject obj)
    {
        string hs = "";
        string s;

        switch (face.faceType)
        {
        case MFace.MFaceType.POLYGON:
            hs += "平面";
            MPolygonFace polyf = face as MPolygonFace;
            foreach (MPoint p in polyf.sortedPoints)
            {
                s = obj.GetPointIdentifier(p);
                if (s == null)
                {
                    hs = null;
                    break;
                }
                hs += s;
            }
            break;

        case MFace.MFaceType.CIRCLE:
            hs += "圆";
            MCircleFace cirf = face as MCircleFace;
            s = obj.GetPointIdentifier(cirf.circle.center);
            if (s == null)
            {
                hs = null;
                break;
            }
            hs += s;
            break;

        default:
            hs = null;
            break;
        }
        return(hs);
    }
コード例 #4
0
 private bool RemoveFace(MFace face)
 {
     return(faceList.Remove(face));
 }
コード例 #5
0
    private int AddFaceToMesh(MFace face)
    {
        int i, j;

        if ((i = faceList.IndexOf(face)) == -1)
        {
            faceList.Add(face);
            switch (face.faceType)
            {
            case MFace.MFaceType.POLYGON:
                MPolygonFace pf    = face as MPolygonFace;
                int          count = pf.edgeList.Count;
                for (int k = 0; k < count; k++)
                {
                    j = AddEdgeToMesh(pf.edgeList[k]);
                    if (j != -1)
                    {
                        pf.edgeList[k] = edgeList[j] as MLinearEdge;
                    }
                    pf.edgeList[k].faces.Add(face);
                }
                break;

            case MFace.MFaceType.CIRCLE:
                MCircleFace cirf = face as MCircleFace;
                j = AddEdgeToMesh(cirf.circle);
                if (j != -1)
                {
                    cirf.circle = edgeList[j] as MCurveEdge;
                }
                cirf.circle.faces.Add(face);
                break;

            case MFace.MFaceType.CONE:
                MConeFace conf = face as MConeFace;
                j = AddEdgeToMesh(conf.bottom);
                if (j != -1)
                {
                    conf.bottom = edgeList[j] as MCurveEdge;
                }
                conf.bottom.faces.Add(face);
                j = AddPointToMesh(conf.top);
                if (j != -1)
                {
                    conf.top = pointList[j];
                }
                conf.top.faces.Add(face);
                break;

            case MFace.MFaceType.CYLINDER:
                MCylinderFace cylf = face as MCylinderFace;
                j = AddEdgeToMesh(cylf.top);
                if (j != -1)
                {
                    cylf.top = edgeList[j] as MCurveEdge;
                }
                cylf.top.faces.Add(face);
                j = AddEdgeToMesh(cylf.bottom);
                if (j != -1)
                {
                    cylf.bottom = edgeList[j] as MCurveEdge;
                }
                cylf.bottom.faces.Add(face);
                break;

            case MFace.MFaceType.SPHERE:
                MSphereFace sf = face as MSphereFace;
                j = AddPointToMesh(sf.center);
                if (j != -1)
                {
                    sf.center = pointList[j];
                }
                sf.center.faces.Add(face);
                break;

            case MFace.MFaceType.GENERAL_FLAT:
                break;

            case MFace.MFaceType.GENERAL_CURVE:
                break;

            default:
                Debug.Log("MMesh: AddFaceToList: unhandled edge type " + face.faceType);
                break;
            }
            boundingBox.AdjustToContain(face.boundingBox);
        }
        return(i);
    }
コード例 #6
0
    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));
    }
コード例 #7
0
 public float GetFaceSurface(MFace face)
 {
     return RefEdgeRelativeSurface(face.GetSurface());
 }
コード例 #8
0
 public MFaceIlluminance(MFace face)
 {
     Face        = face;
     Illuminance = new Spectrum[3];
 }