示例#1
0
        // Use this for initialization
        public void Init(SLO_Join j0, SLO_Join j1, SLO_Join j2, Material mat, float thickness, int index, TriMesh.Extrusion extrusion)
        {
            m_Join0 = j0;
            m_Join1 = j1;
            m_Join2 = j2;

            m_Index = index;

            gameObject.name = "Face " + index;

            m_TriMesh       = gameObject.AddComponent <TriMesh>() as TriMesh;
            m_TriMesh.m_Mat = mat;

            m_Thickness = thickness;

            m_TriMesh.m_Thickness = m_Thickness * .001f;

            // TODO: If edge is tube then the diameter should come from the edge to give a flush finish
            m_InnerVerts = new Vector3[3];
            m_InnerVerts = TriMeshTest1.FindInnerVertsForFace(j0.transform.position, j1.transform.position, j2.transform.position, ((m_Join0.Diameter / 2f) + m_TabTolerance) * .001f);

            // need to put in code to handle inner, outer, center offset and line it up with joint tabs
            m_TriMesh.CreateTri(m_InnerVerts[0], m_InnerVerts[1], m_InnerVerts[2], extrusion);

            UpdateMeasurements();

            // Make selectable
            gameObject.tag = "Selectable";
            gameObject.AddComponent <MeshCollider>();
        }
        // Use this for initialization
        public void Init(SLOObject sloObj, SLO_Join j0, SLO_Join j1, SLO_Join j2, Material mat, bool makeInner, bool makeOuter)
        {
            #region Initialization of references
            // Sets reference to SLO object
            m_Object = sloObj;

            // Set name
            gameObject.name = "Tab";

            // Setup the connect joins
            m_BaseJoin      = j0;
            m_ConnctedJoin0 = j1;
            m_ConnctedJoin1 = j2;

            // Find arms
            for (int i = 0; i < m_BaseJoin.m_Arms.Count; i++)
            {
                if (m_BaseJoin.m_Arms[i].LookAtJoin == m_ConnctedJoin0)
                {
                    m_Arm12 = m_BaseJoin.m_Arms[i];
                }

                if (m_BaseJoin.m_Arms[i].LookAtJoin == m_ConnctedJoin1)
                {
                    m_Arm13 = m_BaseJoin.m_Arms[i];
                }
            }
            #endregion

            #region Calculations
            m_InnerVerts = TriMeshTest1.FindInnerVerts(m_BaseJoin.transform.position, m_ConnctedJoin0.transform.position, m_ConnctedJoin1.transform.position, (m_BaseJoin.Diameter / 2f) * .001f, m_BaseJoin.Length * .001f);
            Vector3 v0 = m_InnerVerts[0];
            Vector3 v1 = m_InnerVerts[1];
            Vector3 v2 = m_InnerVerts[2];

            // Get the normal of the triangle
            m_Normal = Vector3.Cross(v1 - v0, v2 - v0).normalized;

            // calculate the offset based on spacing
            //Vector3 normalOffset = m_Normal * ((SpacingRadius / 2f)) * .001f;
            #endregion

            if (makeInner)
            {
                // FIND INNER VERTS HERE
                m_TabInner      = new GameObject().AddComponent <TriMesh>() as TriMesh;
                m_TabInner.name = "Tab Inner";
                m_TabInner.transform.SetParent(transform);
                m_TabInner.transform.position = Vector3.zero;
                m_TabInner.transform.rotation = Quaternion.identity;
                m_TabInner.m_Mat       = mat;
                m_TabInner.m_Thickness = .001f;
                m_TabInner.CreateTri(v0, v1, v2, TriMesh.Extrusion.Center);
            }

            if (makeOuter)
            {
                m_TabOuter      = new GameObject().AddComponent <TriMesh>() as TriMesh;
                m_TabOuter.name = "Tab Outer";
                m_TabOuter.transform.SetParent(transform);
                m_TabOuter.m_Mat       = mat;
                m_TabOuter.m_Thickness = .001f;
                m_TabOuter.CreateTri(v0, v1, v2, TriMesh.Extrusion.Center);
            }

            //transform.SetParent (m_BaseJoin.transform );
        }