private static void UpdateGeometry(GameObject gameObject, float sideLength, float topDiameter, float bottomDiameter, bool hasTopGeometry, bool hasBottomGeometry)
        {
            if (!gameObject.GetComponent <MeshRenderer>())
            {
                gameObject.AddComponent <MeshRenderer>();
            }
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();

            if (!meshFilter)
            {
                meshFilter = gameObject.AddComponent <MeshFilter>();
            }
            Mesh sharedMesh = CylinderMeshFactory.CreateCylinderMesh(meshFilter.sharedMesh, sideLength, topDiameter, bottomDiameter, 32, hasTopGeometry, hasBottomGeometry, true);

            meshFilter.sharedMesh = sharedMesh;
            if (!gameObject.GetComponent <MaskOutAbstractBehaviour>())
            {
                Material maskMaterial = (Material)AssetDatabase.LoadAssetAtPath("Assets/Vuforia/Materials/DepthMask.mat", typeof(Material));
                BehaviourComponentFactory.Instance.AddMaskOutBehaviour(gameObject).maskMaterial = maskMaterial;
            }
            SceneManager.Instance.UnloadUnusedAssets();
        }
示例#2
0
 public static Mesh CreateCylinderMesh(float sideLength, float topDiameter, float bottomDiameter, int numPerimeterVertices, bool hasTopGeometry, bool hasBottomGeometry, bool insideMaterial = false)
 {
     return(CylinderMeshFactory.CreateCylinderMesh(null, sideLength, topDiameter, bottomDiameter, numPerimeterVertices, hasTopGeometry, hasBottomGeometry, insideMaterial));
 }
示例#3
0
        private Mesh CreateCylinderMesh(Mesh oldMesh, int numPerimeterVertices, bool hasTopGeometry, bool hasBottomGeometry, bool insideMaterial)
        {
            this.mPositions = new List <Vector3>();
            this.mNormals   = new List <Vector3>();
            this.mUVs       = new List <Vector2>();
            float          arg_46_0 = this.ComputeHeight(this.mSideLength);
            List <Vector3> list     = CylinderMeshFactory.CreatePerimeterPositions(0f, this.mBottomRadius, numPerimeterVertices);
            List <Vector3> list2    = CylinderMeshFactory.CreatePerimeterPositions(arg_46_0, this.mTopRadius, numPerimeterVertices);
            List <int>     list3    = this.AddBodyTriangles(list, list2);
            int            num      = 1;
            List <int>     list4    = null;

            if (hasBottomGeometry && this.mBottomRadius > 0f)
            {
                list4 = this.AddSealingTriangles(list, false);
                num++;
            }
            List <int> list5 = null;

            if (hasTopGeometry && this.mTopRadius > 0f)
            {
                list5 = this.AddSealingTriangles(list2, true);
                num++;
            }
            Mesh mesh = oldMesh ?? new Mesh();

            mesh.vertices     = this.mPositions.ToArray();
            mesh.normals      = this.mNormals.ToArray();
            mesh.uv           = this.mUVs.ToArray();
            mesh.subMeshCount = insideMaterial ? (2 * num) : num;
            int[] source = null;
            int[] array  = null;
            int[] array2 = null;
            if (insideMaterial)
            {
                source = list3.Skip(list3.Count / 2).ToArray <int>();
                list3  = list3.Take(list3.Count / 2).ToList <int>();
                if (list4 != null)
                {
                    array2 = list4.Take(list4.Count / 2).ToArray <int>();
                    list4  = list4.Skip(list4.Count / 2).ToList <int>();
                }
                if (list5 != null)
                {
                    array = list5.Skip(list5.Count / 2).ToArray <int>();
                    list5 = list5.Take(list5.Count / 2).ToList <int>();
                }
            }
            mesh.SetTriangles(list3.ToArray(), 0);
            if (list4 != null)
            {
                mesh.SetTriangles(list4.ToArray(), 1);
            }
            if (list5 != null)
            {
                mesh.SetTriangles(list5.ToArray(), num - 1);
            }
            if (insideMaterial)
            {
                mesh.SetTriangles(source.ToArray <int>(), num);
                if (array2 != null)
                {
                    mesh.SetTriangles(array2, num + 1);
                }
                if (array != null)
                {
                    mesh.SetTriangles(array, num + num - 1);
                }
            }
            return(mesh);
        }
示例#4
0
        private List <int> AddSealingTriangles(List <Vector3> perimeterVertices, bool isTop)
        {
            List <int> list = new List <int>();

            for (int i = 0; i < 2; i++)
            {
                bool    flag  = i == 0;
                Vector3 item  = flag ? Vector3.up : Vector3.down;
                int     count = this.mPositions.Count;
                this.mPositions.Add(new Vector3(0f, perimeterVertices[0].y, 0f));
                int count2 = this.mPositions.Count;
                int num    = count2 + perimeterVertices.Count - 1;
                this.mPositions.AddRange(perimeterVertices);
                for (int j = 0; j <= perimeterVertices.Count; j++)
                {
                    this.mNormals.Add(item);
                }
                this.mUVs.AddRange(CylinderMeshFactory.CreatePerimeterUVCoordinates(perimeterVertices.Count, isTop));
                for (int k = count2; k < num; k++)
                {
                    List <int>        arg_ED_0 = list;
                    IEnumerable <int> arg_ED_1;
                    if (!flag)
                    {
                        int[] expr_C3 = new int[3];
                        expr_C3[0] = count;
                        expr_C3[1] = k + 1;
                        arg_ED_1   = expr_C3;
                        expr_C3[2] = k;
                    }
                    else
                    {
                        int[] expr_DC = new int[3];
                        expr_DC[0] = count;
                        expr_DC[1] = k;
                        arg_ED_1   = expr_DC;
                        expr_DC[2] = k + 1;
                    }
                    arg_ED_0.AddRange(arg_ED_1);
                }
                List <int>        arg_12E_0 = list;
                IEnumerable <int> arg_12E_1;
                if (!flag)
                {
                    int[] expr_108 = new int[3];
                    expr_108[0] = count;
                    expr_108[1] = count2;
                    arg_12E_1   = expr_108;
                    expr_108[2] = num;
                }
                else
                {
                    int[] expr_11F = new int[3];
                    expr_11F[0] = count;
                    expr_11F[1] = num;
                    arg_12E_1   = expr_11F;
                    expr_11F[2] = count2;
                }
                arg_12E_0.AddRange(arg_12E_1);
            }
            return(list);
        }