GetMaterialIndex() protected static method

protected static GetMaterialIndex ( Material m, List materials, bool tileV ) : int
m UnityEngine.Material
materials List
tileV bool
return int
コード例 #1
0
 public override void UpdateMesh(List <TreeMaterial> materials, List <TreeVertex> verts, List <TreeTriangle> tris, List <TreeAOSphere> aoSpheres, int buildFlags, float adaptiveQuality, float aoDensity)
 {
     if (this.geometryMode == 4)
     {
         if (this.instanceMesh != null)
         {
             TreeGroupLeaf.cloneMeshFilter = this.instanceMesh.GetComponent <MeshFilter>();
             if (TreeGroupLeaf.cloneMeshFilter != null)
             {
                 TreeGroupLeaf.cloneMesh = TreeGroupLeaf.cloneMeshFilter.sharedMesh;
                 if (TreeGroupLeaf.cloneMesh != null)
                 {
                     Vector3 extents = TreeGroupLeaf.cloneMesh.bounds.extents;
                     float   num     = Mathf.Max(extents.x, extents.z) * 0.5f;
                     TreeGroupLeaf.cloneVerts    = TreeGroupLeaf.cloneMesh.vertices;
                     TreeGroupLeaf.cloneNormals  = TreeGroupLeaf.cloneMesh.normals;
                     TreeGroupLeaf.cloneUVs      = TreeGroupLeaf.cloneMesh.uv;
                     TreeGroupLeaf.cloneTangents = TreeGroupLeaf.cloneMesh.tangents;
                     for (int i = 0; i < TreeGroupLeaf.cloneVerts.Length; i++)
                     {
                         Vector3[] expr_D8_cp_0 = TreeGroupLeaf.cloneVerts;
                         int       expr_D8_cp_1 = i;
                         expr_D8_cp_0[expr_D8_cp_1].x = expr_D8_cp_0[expr_D8_cp_1].x / num;
                         Vector3[] expr_F0_cp_0 = TreeGroupLeaf.cloneVerts;
                         int       expr_F0_cp_1 = i;
                         expr_F0_cp_0[expr_F0_cp_1].y = expr_F0_cp_0[expr_F0_cp_1].y / num;
                         Vector3[] expr_108_cp_0 = TreeGroupLeaf.cloneVerts;
                         int       expr_108_cp_1 = i;
                         expr_108_cp_0[expr_108_cp_1].z = expr_108_cp_0[expr_108_cp_1].z / num;
                     }
                 }
             }
             if (this.instanceMesh.GetComponent <Renderer>() != null)
             {
                 Material[] sharedMaterials = this.instanceMesh.GetComponent <Renderer>().sharedMaterials;
                 for (int j = 0; j < sharedMaterials.Length; j++)
                 {
                     TreeGroup.GetMaterialIndex(sharedMaterials[j], materials, false);
                 }
             }
         }
     }
     else
     {
         TreeGroup.GetMaterialIndex(this.materialLeaf, materials, false);
     }
     for (int k = 0; k < this.nodes.Count; k++)
     {
         this.UpdateNodeMesh(this.nodes[k], materials, verts, tris, aoSpheres, buildFlags, adaptiveQuality, aoDensity);
     }
     TreeGroupLeaf.cloneMesh       = null;
     TreeGroupLeaf.cloneMeshFilter = null;
     TreeGroupLeaf.cloneVerts      = null;
     TreeGroupLeaf.cloneNormals    = null;
     TreeGroupLeaf.cloneUVs        = null;
     TreeGroupLeaf.cloneTangents   = null;
     base.UpdateMesh(materials, verts, tris, aoSpheres, buildFlags, adaptiveQuality, aoDensity);
 }
コード例 #2
0
 public override void UpdateMesh(List <TreeMaterial> materials, List <TreeVertex> verts, List <TreeTriangle> tris, List <TreeAOSphere> aoSpheres, int buildFlags, float adaptiveQuality, float aoDensity)
 {
     if ((this.geometryMode == GeometryMode.Branch) || (this.geometryMode == GeometryMode.BranchFrond))
     {
         TreeGroup.GetMaterialIndex(this.materialBranch, materials, true);
         if (this.breakingChance > 0f)
         {
             TreeGroup.GetMaterialIndex(this.materialBreak, materials, false);
         }
     }
     if ((this.geometryMode == GeometryMode.Frond) || (this.geometryMode == GeometryMode.BranchFrond))
     {
         TreeGroup.GetMaterialIndex(this.materialFrond, materials, false);
     }
     for (int i = 0; i < base.nodes.Count; i++)
     {
         this.UpdateNodeMesh(base.nodes[i], materials, verts, tris, aoSpheres, buildFlags, adaptiveQuality, aoDensity);
     }
     base.UpdateMesh(materials, verts, tris, aoSpheres, buildFlags, adaptiveQuality, aoDensity);
 }
コード例 #3
0
        private void UpdateNodeMesh(TreeNode node, List <TreeMaterial> materials, List <TreeVertex> verts, List <TreeTriangle> tris, List <TreeAOSphere> aoSpheres, int buildFlags, float adaptiveQuality, float aoDensity)
        {
            node.triStart  = tris.Count;
            node.triEnd    = tris.Count;
            node.vertStart = verts.Count;
            node.vertEnd   = verts.Count;
            if (node.visible && base.visible)
            {
                Vector2 vector = base.ComputeWindFactor(node, node.offset);
                if (this.geometryMode == 4)
                {
                    if ((((cloneMesh == null) || (cloneVerts == null)) || ((cloneNormals == null) || (cloneTangents == null))) || (cloneUVs == null))
                    {
                        return;
                    }
                    Matrix4x4 localToWorldMatrix = this.instanceMesh.transform.localToWorldMatrix;
                    Matrix4x4 matrixx2           = node.matrix * localToWorldMatrix;
                    int       count = verts.Count;
                    float     num2  = 5f;
                    for (int i = 0; i < cloneVerts.Length; i++)
                    {
                        TreeVertex item = new TreeVertex {
                            pos = matrixx2.MultiplyPoint(cloneVerts[i]),
                            nor = matrixx2.MultiplyVector(cloneNormals[i]).normalized,
                            uv0 = new Vector2(cloneUVs[i].x, cloneUVs[i].y)
                        };
                        Vector3 normalized = matrixx2.MultiplyVector(new Vector3(cloneTangents[i].x, cloneTangents[i].y, cloneTangents[i].z)).normalized;
                        item.tangent = new Vector4(normalized.x, normalized.y, normalized.z, cloneTangents[i].w);
                        float edgeFactor = (cloneVerts[i].magnitude / num2) * base.animationEdge;
                        item.SetAnimationProperties(vector.x, vector.y, edgeFactor, node.animSeed);
                        if ((buildFlags & 1) != 0)
                        {
                            item.SetAmbientOcclusion(TreeGroup.ComputeAmbientOcclusion(item.pos, item.nor, aoSpheres, aoDensity));
                        }
                        verts.Add(item);
                    }
                    for (int j = 0; j < cloneMesh.subMeshCount; j++)
                    {
                        int   num6;
                        int[] triangles = cloneMesh.GetTriangles(j);
                        if ((this.instanceMesh.GetComponent <Renderer>() != null) && (j < this.instanceMesh.GetComponent <Renderer>().sharedMaterials.Length))
                        {
                            num6 = TreeGroup.GetMaterialIndex(this.instanceMesh.GetComponent <Renderer>().sharedMaterials[j], materials, false);
                        }
                        else
                        {
                            num6 = TreeGroup.GetMaterialIndex(null, materials, false);
                        }
                        for (int k = 0; k < triangles.Length; k += 3)
                        {
                            TreeTriangle triangle = new TreeTriangle(num6, triangles[k] + count, triangles[k + 1] + count, triangles[k + 2] + count);
                            tris.Add(triangle);
                        }
                    }
                }
                else if (this.geometryMode == 3)
                {
                    Vector3 eulerAngles = node.rotation.eulerAngles;
                    eulerAngles.z = eulerAngles.x * 2f;
                    eulerAngles.x = 0f;
                    eulerAngles.y = 0f;
                    Quaternion billboardRotation = Quaternion.Euler(eulerAngles);
                    Vector3    normalBase        = new Vector3(TreeGroup.GenerateBendBillboardNormalFactor, TreeGroup.GenerateBendBillboardNormalFactor, 1f);
                    Vector3    tangentBase       = (Vector3)(billboardRotation * new Vector3(1f, 0f, 0f));
                    float      normalFix         = node.scale / (TreeGroup.GenerateBendBillboardNormalFactor * TreeGroup.GenerateBendBillboardNormalFactor);
                    TreeVertex vertex2           = CreateBillboardVertex(node, billboardRotation, normalBase, normalFix, tangentBase, new Vector2(0f, 1f));
                    TreeVertex vertex3           = CreateBillboardVertex(node, billboardRotation, normalBase, normalFix, tangentBase, new Vector2(0f, 0f));
                    TreeVertex vertex4           = CreateBillboardVertex(node, billboardRotation, normalBase, normalFix, tangentBase, new Vector2(1f, 0f));
                    TreeVertex vertex5           = CreateBillboardVertex(node, billboardRotation, normalBase, normalFix, tangentBase, new Vector2(1f, 1f));
                    vertex2.SetAnimationProperties(vector.x, vector.y, base.animationEdge, node.animSeed);
                    vertex3.SetAnimationProperties(vector.x, vector.y, base.animationEdge, node.animSeed);
                    vertex4.SetAnimationProperties(vector.x, vector.y, base.animationEdge, node.animSeed);
                    vertex5.SetAnimationProperties(vector.x, vector.y, base.animationEdge, node.animSeed);
                    if ((buildFlags & 1) != 0)
                    {
                        Vector3 vector8 = (Vector3)(Vector3.right * node.scale);
                        Vector3 vector9 = (Vector3)(Vector3.forward * node.scale);
                        float   ao      = 0f;
                        ao  = TreeGroup.ComputeAmbientOcclusion(vertex2.pos + vector8, Vector3.right, aoSpheres, aoDensity) + TreeGroup.ComputeAmbientOcclusion(vertex2.pos - vector8, -Vector3.right, aoSpheres, aoDensity);
                        ao += TreeGroup.ComputeAmbientOcclusion(vertex2.pos + vector9, Vector3.forward, aoSpheres, aoDensity);
                        ao += TreeGroup.ComputeAmbientOcclusion(vertex2.pos - vector9, -Vector3.forward, aoSpheres, aoDensity);
                        ao /= 4f;
                        vertex2.SetAmbientOcclusion(ao);
                        vertex3.SetAmbientOcclusion(ao);
                        vertex4.SetAmbientOcclusion(ao);
                        vertex5.SetAmbientOcclusion(ao);
                    }
                    int num10 = verts.Count;
                    verts.Add(vertex2);
                    verts.Add(vertex3);
                    verts.Add(vertex4);
                    verts.Add(vertex5);
                    int material = TreeGroup.GetMaterialIndex(this.materialLeaf, materials, false);
                    tris.Add(new TreeTriangle(material, num10, num10 + 2, num10 + 1, true));
                    tris.Add(new TreeTriangle(material, num10, num10 + 3, num10 + 2, true));
                }
                else
                {
                    int num12 = 0;
                    switch (((GeometryMode)this.geometryMode))
                    {
                    case GeometryMode.PLANE:
                        num12 = 1;
                        break;

                    case GeometryMode.CROSS:
                        num12 = 2;
                        break;

                    case GeometryMode.TRI_CROSS:
                        num12 = 3;
                        break;
                    }
                    int       num13             = TreeGroup.GetMaterialIndex(this.materialLeaf, materials, false);
                    Vector2[] vectorArray       = new Vector2[] { new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(1f, 1f) };
                    Vector2[] planeHullVertices = this.GetPlaneHullVertices(this.materialLeaf);
                    if (planeHullVertices == null)
                    {
                        planeHullVertices = vectorArray;
                    }
                    float     scale        = node.scale;
                    Vector3[] vectorArray3 = new Vector3[] { new Vector3(-scale, 0f, -scale), new Vector3(-scale, 0f, scale), new Vector3(scale, 0f, scale), new Vector3(scale, 0f, -scale) };
                    Vector3   vector10     = new Vector3(TreeGroup.GenerateBendNormalFactor, 1f - TreeGroup.GenerateBendNormalFactor, TreeGroup.GenerateBendNormalFactor);
                    Vector3[] vectorArray6 = new Vector3[4];
                    Vector3   vector11     = new Vector3(-vector10.x, vector10.y, -vector10.z);
                    vectorArray6[0] = vector11.normalized;
                    Vector3 vector12 = new Vector3(-vector10.x, vector10.y, 0f);
                    vectorArray6[1] = vector12.normalized;
                    Vector3 vector13 = new Vector3(vector10.x, vector10.y, 0f);
                    vectorArray6[2] = vector13.normalized;
                    Vector3 vector14 = new Vector3(vector10.x, vector10.y, -vector10.z);
                    vectorArray6[3] = vector14.normalized;
                    Vector3[] vectorArray4 = vectorArray6;
                    for (int m = 0; m < num12; m++)
                    {
                        Quaternion rot = Quaternion.Euler(new Vector3(90f, 0f, 0f));
                        switch (m)
                        {
                        case 1:
                            rot = Quaternion.Euler(new Vector3(90f, 90f, 0f));
                            break;

                        case 2:
                            rot = Quaternion.Euler(new Vector3(0f, 90f, 0f));
                            break;
                        }
                        TreeVertex[] tv = new TreeVertex[] { new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex() };
                        for (int n = 0; n < 4; n++)
                        {
                            tv[n].pos     = node.matrix.MultiplyPoint((Vector3)(rot * vectorArray3[n]));
                            tv[n].nor     = node.matrix.MultiplyVector((Vector3)(rot * vectorArray4[n]));
                            tv[n].tangent = TreeGroup.CreateTangent(node, rot, tv[n].nor);
                            tv[n].uv0     = planeHullVertices[n];
                            tv[n].SetAnimationProperties(vector.x, vector.y, base.animationEdge, node.animSeed);
                            if ((buildFlags & 1) != 0)
                            {
                                tv[n].SetAmbientOcclusion(TreeGroup.ComputeAmbientOcclusion(tv[n].pos, tv[n].nor, aoSpheres, aoDensity));
                            }
                        }
                        for (int num17 = 0; num17 < 4; num17++)
                        {
                            tv[num17 + 4].Lerp4(tv, planeHullVertices[num17]);
                            tv[num17 + 4].uv0  = tv[num17].uv0;
                            tv[num17 + 4].uv1  = tv[num17].uv1;
                            tv[num17 + 4].flag = tv[num17].flag;
                        }
                        int num18 = verts.Count;
                        for (int num19 = 0; num19 < 4; num19++)
                        {
                            verts.Add(tv[num19 + 4]);
                        }
                        tris.Add(new TreeTriangle(num13, num18, num18 + 1, num18 + 2));
                        tris.Add(new TreeTriangle(num13, num18, num18 + 2, num18 + 3));
                        Vector3 inNormal = node.matrix.MultiplyVector((Vector3)(rot * new Vector3(0f, 1f, 0f)));
                        if (TreeGroup.GenerateDoubleSidedGeometry)
                        {
                            TreeVertex[] vertexArray2 = new TreeVertex[] { new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex() };
                            for (int num20 = 0; num20 < 4; num20++)
                            {
                                vertexArray2[num20].pos       = tv[num20].pos;
                                vertexArray2[num20].nor       = Vector3.Reflect(tv[num20].nor, inNormal);
                                vertexArray2[num20].tangent   = Vector3.Reflect((Vector3)tv[num20].tangent, inNormal);
                                vertexArray2[num20].tangent.w = -1f;
                                vertexArray2[num20].uv0       = tv[num20].uv0;
                                vertexArray2[num20].SetAnimationProperties(vector.x, vector.y, base.animationEdge, node.animSeed);
                                if ((buildFlags & 1) != 0)
                                {
                                    vertexArray2[num20].SetAmbientOcclusion(TreeGroup.ComputeAmbientOcclusion(vertexArray2[num20].pos, vertexArray2[num20].nor, aoSpheres, aoDensity));
                                }
                            }
                            for (int num21 = 0; num21 < 4; num21++)
                            {
                                vertexArray2[num21 + 4].Lerp4(vertexArray2, planeHullVertices[num21]);
                                vertexArray2[num21 + 4].uv0  = vertexArray2[num21].uv0;
                                vertexArray2[num21 + 4].uv1  = vertexArray2[num21].uv1;
                                vertexArray2[num21 + 4].flag = vertexArray2[num21].flag;
                            }
                            int num22 = verts.Count;
                            for (int num23 = 0; num23 < 4; num23++)
                            {
                                verts.Add(vertexArray2[num23 + 4]);
                            }
                            tris.Add(new TreeTriangle(num13, num22, num22 + 2, num22 + 1));
                            tris.Add(new TreeTriangle(num13, num22, num22 + 3, num22 + 2));
                        }
                    }
                }
                node.triEnd  = tris.Count;
                node.vertEnd = verts.Count;
            }
        }
コード例 #4
0
        private void UpdateNodeMesh(TreeNode node, List <TreeMaterial> materials, List <TreeVertex> verts, List <TreeTriangle> tris, List <TreeAOSphere> aoSpheres, int buildFlags, float adaptiveQuality, float aoDensity)
        {
            node.triStart  = tris.Count;
            node.triEnd    = tris.Count;
            node.vertStart = verts.Count;
            node.vertEnd   = verts.Count;
            if (!node.visible || !this.visible)
            {
                return;
            }
            Profiler.BeginSample("TreeGroupLeaf.UpdateNodeMesh");
            Vector2 vector = base.ComputeWindFactor(node, node.offset);

            if (this.geometryMode == 4)
            {
                if (TreeGroupLeaf.cloneMesh == null)
                {
                    return;
                }
                if (TreeGroupLeaf.cloneVerts == null)
                {
                    return;
                }
                if (TreeGroupLeaf.cloneNormals == null)
                {
                    return;
                }
                if (TreeGroupLeaf.cloneTangents == null)
                {
                    return;
                }
                if (TreeGroupLeaf.cloneUVs == null)
                {
                    return;
                }
                Matrix4x4 localToWorldMatrix = this.instanceMesh.transform.localToWorldMatrix;
                Matrix4x4 matrix4x           = node.matrix * localToWorldMatrix;
                int       count = verts.Count;
                float     num   = 5f;
                for (int i = 0; i < TreeGroupLeaf.cloneVerts.Length; i++)
                {
                    TreeVertex treeVertex = new TreeVertex();
                    treeVertex.pos = matrix4x.MultiplyPoint(TreeGroupLeaf.cloneVerts[i]);
                    treeVertex.nor = matrix4x.MultiplyVector(TreeGroupLeaf.cloneNormals[i]).normalized;
                    treeVertex.uv0 = new Vector2(TreeGroupLeaf.cloneUVs[i].x, TreeGroupLeaf.cloneUVs[i].y);
                    Vector3 normalized = matrix4x.MultiplyVector(new Vector3(TreeGroupLeaf.cloneTangents[i].x, TreeGroupLeaf.cloneTangents[i].y, TreeGroupLeaf.cloneTangents[i].z)).normalized;
                    treeVertex.tangent = new Vector4(normalized.x, normalized.y, normalized.z, TreeGroupLeaf.cloneTangents[i].w);
                    float edgeFactor = TreeGroupLeaf.cloneVerts[i].magnitude / num * this.animationEdge;
                    treeVertex.SetAnimationProperties(vector.x, vector.y, edgeFactor, node.animSeed);
                    if ((buildFlags & 1) != 0)
                    {
                        treeVertex.SetAmbientOcclusion(TreeGroup.ComputeAmbientOcclusion(treeVertex.pos, treeVertex.nor, aoSpheres, aoDensity));
                    }
                    verts.Add(treeVertex);
                }
                for (int j = 0; j < TreeGroupLeaf.cloneMesh.subMeshCount; j++)
                {
                    int[] triangles = TreeGroupLeaf.cloneMesh.GetTriangles(j);
                    int   materialIndex;
                    if (this.instanceMesh.GetComponent <Renderer>() != null && j < this.instanceMesh.GetComponent <Renderer>().sharedMaterials.Length)
                    {
                        materialIndex = TreeGroup.GetMaterialIndex(this.instanceMesh.GetComponent <Renderer>().sharedMaterials[j], materials, false);
                    }
                    else
                    {
                        materialIndex = TreeGroup.GetMaterialIndex(null, materials, false);
                    }
                    for (int k = 0; k < triangles.Length; k += 3)
                    {
                        TreeTriangle item = new TreeTriangle(materialIndex, triangles[k] + count, triangles[k + 1] + count, triangles[k + 2] + count);
                        tris.Add(item);
                    }
                }
            }
            else
            {
                if (this.geometryMode == 3)
                {
                    Vector3 eulerAngles = node.rotation.eulerAngles;
                    eulerAngles.z = eulerAngles.x * 2f;
                    eulerAngles.x = 0f;
                    eulerAngles.y = 0f;
                    Quaternion quaternion  = Quaternion.Euler(eulerAngles);
                    Vector3    normalBase  = new Vector3(TreeGroup.GenerateBendBillboardNormalFactor, TreeGroup.GenerateBendBillboardNormalFactor, 1f);
                    Vector3    tangentBase = quaternion * new Vector3(1f, 0f, 0f);
                    float      normalFix   = node.scale / (TreeGroup.GenerateBendBillboardNormalFactor * TreeGroup.GenerateBendBillboardNormalFactor);
                    TreeVertex treeVertex2 = TreeGroupLeaf.CreateBillboardVertex(node, quaternion, normalBase, normalFix, tangentBase, new Vector2(0f, 1f));
                    TreeVertex treeVertex3 = TreeGroupLeaf.CreateBillboardVertex(node, quaternion, normalBase, normalFix, tangentBase, new Vector2(0f, 0f));
                    TreeVertex treeVertex4 = TreeGroupLeaf.CreateBillboardVertex(node, quaternion, normalBase, normalFix, tangentBase, new Vector2(1f, 0f));
                    TreeVertex treeVertex5 = TreeGroupLeaf.CreateBillboardVertex(node, quaternion, normalBase, normalFix, tangentBase, new Vector2(1f, 1f));
                    treeVertex2.SetAnimationProperties(vector.x, vector.y, this.animationEdge, node.animSeed);
                    treeVertex3.SetAnimationProperties(vector.x, vector.y, this.animationEdge, node.animSeed);
                    treeVertex4.SetAnimationProperties(vector.x, vector.y, this.animationEdge, node.animSeed);
                    treeVertex5.SetAnimationProperties(vector.x, vector.y, this.animationEdge, node.animSeed);
                    if ((buildFlags & 1) != 0)
                    {
                        Vector3 b    = Vector3.right * node.scale;
                        Vector3 b2   = Vector3.forward * node.scale;
                        float   num2 = TreeGroup.ComputeAmbientOcclusion(treeVertex2.pos + b, Vector3.right, aoSpheres, aoDensity);
                        num2 += TreeGroup.ComputeAmbientOcclusion(treeVertex2.pos - b, -Vector3.right, aoSpheres, aoDensity);
                        num2 += TreeGroup.ComputeAmbientOcclusion(treeVertex2.pos + b2, Vector3.forward, aoSpheres, aoDensity);
                        num2 += TreeGroup.ComputeAmbientOcclusion(treeVertex2.pos - b2, -Vector3.forward, aoSpheres, aoDensity);
                        num2 /= 4f;
                        treeVertex2.SetAmbientOcclusion(num2);
                        treeVertex3.SetAmbientOcclusion(num2);
                        treeVertex4.SetAmbientOcclusion(num2);
                        treeVertex5.SetAmbientOcclusion(num2);
                    }
                    int count2 = verts.Count;
                    verts.Add(treeVertex2);
                    verts.Add(treeVertex3);
                    verts.Add(treeVertex4);
                    verts.Add(treeVertex5);
                    int materialIndex2 = TreeGroup.GetMaterialIndex(this.materialLeaf, materials, false);
                    tris.Add(new TreeTriangle(materialIndex2, count2, count2 + 2, count2 + 1, true));
                    tris.Add(new TreeTriangle(materialIndex2, count2, count2 + 3, count2 + 2, true));
                }
                else
                {
                    int num3 = 0;
                    switch (this.geometryMode)
                    {
                    case 0:
                        num3 = 1;
                        break;

                    case 1:
                        num3 = 2;
                        break;

                    case 2:
                        num3 = 3;
                        break;
                    }
                    int       materialIndex3 = TreeGroup.GetMaterialIndex(this.materialLeaf, materials, false);
                    Vector2[] array          = new Vector2[]
                    {
                        new Vector2(0f, 1f),
                        new Vector2(0f, 0f),
                        new Vector2(1f, 0f),
                        new Vector2(1f, 1f)
                    };
                    Vector2[] array2 = this.GetPlaneHullVertices(this.materialLeaf);
                    if (array2 == null)
                    {
                        array2 = array;
                    }
                    float     scale  = node.scale;
                    Vector3[] array3 = new Vector3[]
                    {
                        new Vector3(-scale, 0f, -scale),
                        new Vector3(-scale, 0f, scale),
                        new Vector3(scale, 0f, scale),
                        new Vector3(scale, 0f, -scale)
                    };
                    Vector3   vector2        = new Vector3(TreeGroup.GenerateBendNormalFactor, 1f - TreeGroup.GenerateBendNormalFactor, TreeGroup.GenerateBendNormalFactor);
                    Vector3[] expr_788       = new Vector3[4];
                    int       arg_7B4_0_cp_1 = 0;
                    Vector3   vector3        = new Vector3(-vector2.x, vector2.y, -vector2.z);
                    expr_788[arg_7B4_0_cp_1] = vector3.normalized;
                    int     arg_7E2_0_cp_1 = 1;
                    Vector3 vector4        = new Vector3(-vector2.x, vector2.y, 0f);
                    expr_788[arg_7E2_0_cp_1] = vector4.normalized;
                    int     arg_80F_0_cp_1 = 2;
                    Vector3 vector5        = new Vector3(vector2.x, vector2.y, 0f);
                    expr_788[arg_80F_0_cp_1] = vector5.normalized;
                    int     arg_83F_0_cp_1 = 3;
                    Vector3 vector6        = new Vector3(vector2.x, vector2.y, -vector2.z);
                    expr_788[arg_83F_0_cp_1] = vector6.normalized;
                    Vector3[] array4 = expr_788;
                    for (int l = 0; l < num3; l++)
                    {
                        Quaternion quaternion2 = Quaternion.Euler(new Vector3(90f, 0f, 0f));
                        int        num4        = l;
                        if (num4 != 1)
                        {
                            if (num4 == 2)
                            {
                                quaternion2 = Quaternion.Euler(new Vector3(0f, 90f, 0f));
                            }
                        }
                        else
                        {
                            quaternion2 = Quaternion.Euler(new Vector3(90f, 90f, 0f));
                        }
                        TreeVertex[] array5 = new TreeVertex[]
                        {
                            new TreeVertex(),
                            new TreeVertex(),
                            new TreeVertex(),
                            new TreeVertex(),
                            new TreeVertex(),
                            new TreeVertex(),
                            new TreeVertex(),
                            new TreeVertex()
                        };
                        for (int m = 0; m < 4; m++)
                        {
                            array5[m].pos     = node.matrix.MultiplyPoint(quaternion2 * array3[m]);
                            array5[m].nor     = node.matrix.MultiplyVector(quaternion2 * array4[m]);
                            array5[m].tangent = TreeGroup.CreateTangent(node, quaternion2, array5[m].nor);
                            array5[m].uv0     = array2[m];
                            array5[m].SetAnimationProperties(vector.x, vector.y, this.animationEdge, node.animSeed);
                            if ((buildFlags & 1) != 0)
                            {
                                array5[m].SetAmbientOcclusion(TreeGroup.ComputeAmbientOcclusion(array5[m].pos, array5[m].nor, aoSpheres, aoDensity));
                            }
                        }
                        for (int n = 0; n < 4; n++)
                        {
                            array5[n + 4].Lerp4(array5, array2[n]);
                            array5[n + 4].uv0  = array5[n].uv0;
                            array5[n + 4].uv1  = array5[n].uv1;
                            array5[n + 4].flag = array5[n].flag;
                        }
                        int count3 = verts.Count;
                        for (int num5 = 0; num5 < 4; num5++)
                        {
                            verts.Add(array5[num5 + 4]);
                        }
                        tris.Add(new TreeTriangle(materialIndex3, count3, count3 + 1, count3 + 2));
                        tris.Add(new TreeTriangle(materialIndex3, count3, count3 + 2, count3 + 3));
                        Vector3 inNormal = node.matrix.MultiplyVector(quaternion2 * new Vector3(0f, 1f, 0f));
                        if (TreeGroup.GenerateDoubleSidedGeometry)
                        {
                            TreeVertex[] array6 = new TreeVertex[]
                            {
                                new TreeVertex(),
                                new TreeVertex(),
                                new TreeVertex(),
                                new TreeVertex(),
                                new TreeVertex(),
                                new TreeVertex(),
                                new TreeVertex(),
                                new TreeVertex()
                            };
                            for (int num6 = 0; num6 < 4; num6++)
                            {
                                array6[num6].pos       = array5[num6].pos;
                                array6[num6].nor       = Vector3.Reflect(array5[num6].nor, inNormal);
                                array6[num6].tangent   = Vector3.Reflect(array5[num6].tangent, inNormal);
                                array6[num6].tangent.w = -1f;
                                array6[num6].uv0       = array5[num6].uv0;
                                array6[num6].SetAnimationProperties(vector.x, vector.y, this.animationEdge, node.animSeed);
                                if ((buildFlags & 1) != 0)
                                {
                                    array6[num6].SetAmbientOcclusion(TreeGroup.ComputeAmbientOcclusion(array6[num6].pos, array6[num6].nor, aoSpheres, aoDensity));
                                }
                            }
                            for (int num7 = 0; num7 < 4; num7++)
                            {
                                array6[num7 + 4].Lerp4(array6, array2[num7]);
                                array6[num7 + 4].uv0  = array6[num7].uv0;
                                array6[num7 + 4].uv1  = array6[num7].uv1;
                                array6[num7 + 4].flag = array6[num7].flag;
                            }
                            int count4 = verts.Count;
                            for (int num8 = 0; num8 < 4; num8++)
                            {
                                verts.Add(array6[num8 + 4]);
                            }
                            tris.Add(new TreeTriangle(materialIndex3, count4, count4 + 2, count4 + 1));
                            tris.Add(new TreeTriangle(materialIndex3, count4, count4 + 3, count4 + 2));
                        }
                    }
                }
            }
            node.triEnd  = tris.Count;
            node.vertEnd = verts.Count;
            Profiler.EndSample();
        }
コード例 #5
0
 private void UpdateNodeMesh(TreeNode node, List <TreeMaterial> materials, List <TreeVertex> verts, List <TreeTriangle> tris, List <TreeAOSphere> aoSpheres, int buildFlags, float adaptiveQuality, float aoDensity)
 {
     node.triStart  = tris.Count;
     node.triEnd    = tris.Count;
     node.vertStart = verts.Count;
     node.vertEnd   = verts.Count;
     if (node.visible && base.visible)
     {
         int             count             = verts.Count;
         float           approximateLength = node.spline.GetApproximateLength();
         List <RingLoop> list  = new List <RingLoop>();
         float           num3  = Mathf.Clamp01(adaptiveQuality * this.lodQualityMultiplier);
         List <float>    list2 = TreeData.GetAdaptiveSamples(this, node, num3);
         int             adaptiveRadialSegments = TreeData.GetAdaptiveRadialSegments(this.radius, num3);
         TreeGroupBranch parentGroup            = null;
         if ((base.parentGroup != null) && (base.parentGroup.GetType() == typeof(TreeGroupBranch)))
         {
             parentGroup = (TreeGroupBranch)base.parentGroup;
         }
         if ((this.geometryMode == GeometryMode.BranchFrond) || (this.geometryMode == GeometryMode.Branch))
         {
             int   materialIndex = TreeGroup.GetMaterialIndex(this.materialBranch, materials, true);
             float bOffset       = 0f;
             float num7          = 0f;
             float num8          = approximateLength / ((this.GetRadiusAtTime(node, 0f, false) * 3.141593f) * 2f);
             bool  flag          = true;
             if ((node.parent != null) && (parentGroup != null))
             {
                 num7 = node.offset * node.parent.spline.GetApproximateLength();
             }
             float num9 = 1f - node.capRange;
             for (int i = 0; i < list2.Count; i++)
             {
                 float      timeParam      = list2[i];
                 Vector3    positionAtTime = node.spline.GetPositionAtTime(timeParam);
                 Quaternion rotationAtTime = node.spline.GetRotationAtTime(timeParam);
                 float      r = this.GetRadiusAtTime(node, timeParam, false);
                 Matrix4x4  m = node.matrix * Matrix4x4.TRS(positionAtTime, rotationAtTime, new Vector3(1f, 1f, 1f));
                 Vector3    flareWeldAtTime = this.GetFlareWeldAtTime(node, timeParam);
                 float      num13           = Mathf.Max(flareWeldAtTime.x, Mathf.Max(flareWeldAtTime.y, flareWeldAtTime.z) * 0.25f);
                 if (timeParam <= num9)
                 {
                     adaptiveRadialSegments = TreeData.GetAdaptiveRadialSegments(r + num13, num3);
                 }
                 if (flag)
                 {
                     if (i > 0)
                     {
                         float t     = list2[i - 1];
                         float num15 = timeParam - t;
                         float num16 = (r + this.GetRadiusAtTime(node, t, false)) * 0.5f;
                         bOffset += (num15 * approximateLength) / ((num16 * 3.141593f) * 2f);
                     }
                 }
                 else
                 {
                     bOffset = num7 + (timeParam * num8);
                 }
                 Vector2  vector3 = base.ComputeWindFactor(node, timeParam);
                 RingLoop item    = new RingLoop();
                 item.Reset(r, m, bOffset, adaptiveRadialSegments);
                 item.SetSurfaceAngle(node.GetSurfaceAngleAtTime(timeParam));
                 item.SetAnimationProperties(vector3.x, vector3.y, 0f, node.animSeed);
                 item.SetSpread(flareWeldAtTime.y, flareWeldAtTime.z);
                 item.SetNoise(this.noise * Mathf.Clamp01(this.noiseCurve.Evaluate(timeParam)), this.noiseScaleU * 10f, this.noiseScaleV * 10f);
                 item.SetFlares(flareWeldAtTime.x, this.flareNoise * 10f);
                 int num17 = verts.Count;
                 item.BuildVertices(verts);
                 int num18 = verts.Count;
                 if ((buildFlags & 2) != 0)
                 {
                     float weldHeight = this.weldHeight;
                     float num20      = Mathf.Pow(Mathf.Clamp01(((1f - timeParam) - (1f - this.weldHeight)) / this.weldHeight), 1.5f);
                     float num21      = 1f - num20;
                     if ((timeParam < weldHeight) && ((node.parent != null) && (node.parent.spline != null)))
                     {
                         Ray ray = new Ray();
                         for (int k = num17; k < num18; k++)
                         {
                             ray.origin    = verts[k].pos;
                             ray.direction = m.MultiplyVector(-Vector3.up);
                             Vector3 pos   = verts[k].pos;
                             Vector3 nor   = verts[k].nor;
                             float   num23 = -10000f;
                             float   num24 = 100000f;
                             for (int n = node.parent.triStart; n < node.parent.triEnd; n++)
                             {
                                 object obj2 = MathUtils.IntersectRayTriangle(ray, verts[tris[n].v[0]].pos, verts[tris[n].v[1]].pos, verts[tris[n].v[2]].pos, true);
                                 if (obj2 != null)
                                 {
                                     RaycastHit hit = (RaycastHit)obj2;
                                     if ((Mathf.Abs(hit.distance) < num24) && (hit.distance > num23))
                                     {
                                         num24        = Mathf.Abs(hit.distance);
                                         verts[k].nor = (Vector3)(((verts[tris[n].v[0]].nor * hit.barycentricCoordinate.x) + (verts[tris[n].v[1]].nor * hit.barycentricCoordinate.y)) + (verts[tris[n].v[2]].nor * hit.barycentricCoordinate.z));
                                         verts[k].nor = (Vector3)((verts[k].nor * num20) + (nor * num21));
                                         verts[k].pos = (Vector3)((hit.point * num20) + (pos * num21));
                                     }
                                 }
                             }
                         }
                     }
                 }
                 list.Add(item);
                 if ((timeParam == 1f) && (item.radius > 0.005f))
                 {
                     RingLoop loop2 = item.Clone();
                     loop2.radius      = 0f;
                     loop2.baseOffset += r / 6.283185f;
                     loop2.BuildVertices(verts);
                     list.Add(loop2);
                 }
             }
             if (((list.Count > 0) && (list[list.Count - 1].radius > 0.025f)) && (node.breakOffset < 1f))
             {
                 float    mappingScale   = 1f / ((this.radius * 3.141593f) * 2f);
                 float    sphereFactor   = 0f;
                 float    noise          = 1f;
                 int      mappingMode    = 0;
                 Material materialBranch = this.materialBranch;
                 if (this.materialBreak != null)
                 {
                     materialBranch = this.materialBreak;
                 }
                 int num30 = TreeGroup.GetMaterialIndex(materialBranch, materials, false);
                 list[list.Count - 1].Cap(sphereFactor, noise, mappingMode, mappingScale, verts, tris, num30);
             }
             node.triStart = tris.Count;
             for (int j = 0; j < (list.Count - 1); j++)
             {
                 list[j].Connect(list[j + 1], tris, materialIndex, false, false);
             }
             node.triEnd = tris.Count;
             list.Clear();
         }
         float num32 = Mathf.Min(this.frondRange.x, this.frondRange.y);
         float num33 = Mathf.Max(this.frondRange.x, this.frondRange.y);
         float num34 = num32;
         float num35 = num33;
         num32 = Mathf.Clamp(num32, 0f, node.breakOffset);
         num33 = Mathf.Clamp(num33, 0f, node.breakOffset);
         if (((this.geometryMode == GeometryMode.BranchFrond) || (this.geometryMode == GeometryMode.Frond)) && ((this.frondCount > 0) && (num32 != num33)))
         {
             bool flag2 = true;
             bool flag3 = true;
             for (int num36 = 0; num36 < list2.Count; num36++)
             {
                 float num37 = list2[num36];
                 if (num37 < num32)
                 {
                     list2.RemoveAt(num36);
                     num36--;
                 }
                 else if (num37 == num32)
                 {
                     flag2 = false;
                 }
                 else if (num37 == num33)
                 {
                     flag3 = false;
                 }
                 else if (num37 > num33)
                 {
                     list2.RemoveAt(num36);
                     num36--;
                 }
             }
             if (flag2)
             {
                 list2.Insert(0, num32);
             }
             if (flag3)
             {
                 list2.Add(num33);
             }
             int   material = TreeGroup.GetMaterialIndex(this.materialFrond, materials, false);
             float num39    = 1f - node.capRange;
             for (int num40 = 0; num40 < this.frondCount; num40++)
             {
                 float   num41    = (this.frondCrease * 90f) * 0.01745329f;
                 float   num42    = (((this.frondRotation * 360f) + ((num40 * 180f) / ((float)this.frondCount))) - 90f) * 0.01745329f;
                 float   f        = -num42 - num41;
                 float   num44    = num42 - num41;
                 Vector3 vector9  = new Vector3(Mathf.Sin(f), 0f, Mathf.Cos(f));
                 Vector3 v        = new Vector3(vector9.z, 0f, -vector9.x);
                 Vector3 vector11 = new Vector3(Mathf.Sin(num44), 0f, -Mathf.Cos(num44));
                 Vector3 vector12 = new Vector3(-vector11.z, 0f, vector11.x);
                 for (int num45 = 0; num45 < list2.Count; num45++)
                 {
                     float num46 = list2[num45];
                     float y     = (num46 - num34) / (num35 - num34);
                     float num48 = num46;
                     if (num46 > num39)
                     {
                         num48 = num39;
                         float num49 = Mathf.Acos(Mathf.Clamp01((num46 - num39) / node.capRange));
                         float num50 = Mathf.Sin(num49);
                         float num51 = Mathf.Cos(num49) * this.capSmoothing;
                         vector9  = new Vector3(Mathf.Sin(f) * num50, num51, Mathf.Cos(f) * num50);
                         v        = new Vector3(vector9.z, vector9.y, -vector9.x);
                         vector11 = new Vector3(Mathf.Sin(num44) * num50, num51, -Mathf.Cos(num44) * num50);
                         vector12 = new Vector3(-vector11.z, vector11.y, vector11.x);
                     }
                     Vector3    vector13 = new Vector3(0f, 0f, -1f);
                     Vector3    vector14 = node.spline.GetPositionAtTime(num48);
                     Quaternion q        = node.spline.GetRotationAtTime(num46);
                     float      num52    = (Mathf.Clamp01(this.frondCurve.Evaluate(num46)) * this.frondWidth) * node.GetScale();
                     Matrix4x4  matrixx2 = node.matrix * Matrix4x4.TRS(vector14, q, new Vector3(1f, 1f, 1f));
                     if (TreeGroup.GenerateDoubleSidedGeometry)
                     {
                         for (float num53 = -1f; num53 < 2f; num53 += 2f)
                         {
                             TreeVertex vertex = new TreeVertex {
                                 pos = matrixx2.MultiplyPoint((Vector3)(vector9 * num52)),
                                 nor = matrixx2.MultiplyVector((Vector3)(v * num53)).normalized
                             };
                             vertex.tangent   = TreeGroup.CreateTangent(node, q, vertex.nor);
                             vertex.tangent.w = -num53;
                             vertex.uv0       = new Vector2(1f, y);
                             TreeVertex vertex2 = new TreeVertex {
                                 pos = matrixx2.MultiplyPoint(Vector3.zero),
                                 nor = matrixx2.MultiplyVector((Vector3)(vector13 * num53)).normalized
                             };
                             vertex2.tangent   = TreeGroup.CreateTangent(node, q, vertex2.nor);
                             vertex2.tangent.w = -num53;
                             vertex2.uv0       = new Vector2(0.5f, y);
                             TreeVertex vertex3 = new TreeVertex {
                                 pos = matrixx2.MultiplyPoint(Vector3.zero),
                                 nor = matrixx2.MultiplyVector((Vector3)(vector13 * num53)).normalized
                             };
                             vertex3.tangent   = TreeGroup.CreateTangent(node, q, vertex3.nor);
                             vertex3.tangent.w = -num53;
                             vertex3.uv0       = new Vector2(0.5f, y);
                             TreeVertex vertex4 = new TreeVertex {
                                 pos = matrixx2.MultiplyPoint((Vector3)(vector11 * num52)),
                                 nor = matrixx2.MultiplyVector((Vector3)(vector12 * num53)).normalized
                             };
                             vertex4.tangent   = TreeGroup.CreateTangent(node, q, vertex4.nor);
                             vertex4.tangent.w = -num53;
                             vertex4.uv0       = new Vector2(0f, y);
                             Vector2 vector19 = base.ComputeWindFactor(node, num46);
                             vertex.SetAnimationProperties(vector19.x, vector19.y, base.animationEdge, node.animSeed);
                             vertex2.SetAnimationProperties(vector19.x, vector19.y, 0f, node.animSeed);
                             vertex3.SetAnimationProperties(vector19.x, vector19.y, 0f, node.animSeed);
                             vertex4.SetAnimationProperties(vector19.x, vector19.y, base.animationEdge, node.animSeed);
                             verts.Add(vertex);
                             verts.Add(vertex2);
                             verts.Add(vertex3);
                             verts.Add(vertex4);
                         }
                         if (num45 > 0)
                         {
                             int          num54     = verts.Count;
                             TreeTriangle triangle  = new TreeTriangle(material, num54 - 4, num54 - 3, num54 - 11);
                             TreeTriangle triangle2 = new TreeTriangle(material, num54 - 4, num54 - 11, num54 - 12);
                             triangle.flip();
                             triangle2.flip();
                             TreeTriangle triangle3 = new TreeTriangle(material, num54 - 8, num54 - 7, num54 - 15);
                             TreeTriangle triangle4 = new TreeTriangle(material, num54 - 8, num54 - 15, num54 - 0x10);
                             tris.Add(triangle);
                             tris.Add(triangle2);
                             tris.Add(triangle3);
                             tris.Add(triangle4);
                             TreeTriangle triangle5 = new TreeTriangle(material, num54 - 2, num54 - 9, num54 - 1);
                             TreeTriangle triangle6 = new TreeTriangle(material, num54 - 2, num54 - 10, num54 - 9);
                             TreeTriangle triangle7 = new TreeTriangle(material, num54 - 6, num54 - 13, num54 - 5);
                             TreeTriangle triangle8 = new TreeTriangle(material, num54 - 6, num54 - 14, num54 - 13);
                             triangle7.flip();
                             triangle8.flip();
                             tris.Add(triangle5);
                             tris.Add(triangle6);
                             tris.Add(triangle7);
                             tris.Add(triangle8);
                         }
                     }
                     else
                     {
                         TreeVertex vertex5 = new TreeVertex {
                             pos = matrixx2.MultiplyPoint((Vector3)(vector9 * num52)),
                             nor = matrixx2.MultiplyVector(v).normalized,
                             uv0 = new Vector2(0f, y)
                         };
                         TreeVertex vertex6 = new TreeVertex {
                             pos = matrixx2.MultiplyPoint(Vector3.zero),
                             nor = matrixx2.MultiplyVector(Vector3.back).normalized,
                             uv0 = new Vector2(0.5f, y)
                         };
                         TreeVertex vertex7 = new TreeVertex {
                             pos = matrixx2.MultiplyPoint((Vector3)(vector11 * num52)),
                             nor = matrixx2.MultiplyVector(vector12).normalized,
                             uv0 = new Vector2(1f, y)
                         };
                         Vector2 vector23 = base.ComputeWindFactor(node, num46);
                         vertex5.SetAnimationProperties(vector23.x, vector23.y, base.animationEdge, node.animSeed);
                         vertex6.SetAnimationProperties(vector23.x, vector23.y, 0f, node.animSeed);
                         vertex7.SetAnimationProperties(vector23.x, vector23.y, base.animationEdge, node.animSeed);
                         verts.Add(vertex5);
                         verts.Add(vertex6);
                         verts.Add(vertex7);
                         if (num45 > 0)
                         {
                             int          num55      = verts.Count;
                             TreeTriangle triangle9  = new TreeTriangle(material, num55 - 2, num55 - 3, num55 - 6);
                             TreeTriangle triangle10 = new TreeTriangle(material, num55 - 2, num55 - 6, num55 - 5);
                             tris.Add(triangle9);
                             tris.Add(triangle10);
                             TreeTriangle triangle11 = new TreeTriangle(material, num55 - 2, num55 - 4, num55 - 1);
                             TreeTriangle triangle12 = new TreeTriangle(material, num55 - 2, num55 - 5, num55 - 4);
                             tris.Add(triangle11);
                             tris.Add(triangle12);
                         }
                     }
                 }
             }
         }
         if ((buildFlags & 1) != 0)
         {
             for (int num56 = count; num56 < verts.Count; num56++)
             {
                 verts[num56].SetAmbientOcclusion(TreeGroup.ComputeAmbientOcclusion(verts[num56].pos, verts[num56].nor, aoSpheres, aoDensity));
             }
         }
         node.vertEnd = verts.Count;
     }
 }
コード例 #6
0
        private void UpdateNodeMesh(TreeNode node, List <TreeMaterial> materials, List <TreeVertex> verts, List <TreeTriangle> tris, List <TreeAOSphere> aoSpheres, int buildFlags, float adaptiveQuality, float aoDensity)
        {
            node.triStart  = tris.Count;
            node.triEnd    = tris.Count;
            node.vertStart = verts.Count;
            node.vertEnd   = verts.Count;
            if (!node.visible || !this.visible)
            {
                return;
            }
            Profiler.BeginSample("TreeGroupBranch.UpdateNodeMesh");
            int             count             = verts.Count;
            float           approximateLength = node.spline.GetApproximateLength();
            List <RingLoop> list                   = new List <RingLoop>();
            float           adaptiveQuality2       = Mathf.Clamp01(adaptiveQuality * this.lodQualityMultiplier);
            List <float>    adaptiveSamples        = TreeData.GetAdaptiveSamples(this, node, adaptiveQuality2);
            int             adaptiveRadialSegments = TreeData.GetAdaptiveRadialSegments(this.radius, adaptiveQuality2);
            TreeGroupBranch treeGroupBranch        = null;

            if (this.parentGroup != null && this.parentGroup.GetType() == typeof(TreeGroupBranch))
            {
                treeGroupBranch = (TreeGroupBranch)this.parentGroup;
            }
            if (this.geometryMode == TreeGroupBranch.GeometryMode.BranchFrond || this.geometryMode == TreeGroupBranch.GeometryMode.Branch)
            {
                int   materialIndex = TreeGroup.GetMaterialIndex(this.materialBranch, materials, true);
                float num           = 0f;
                float num2          = 0f;
                float num3          = approximateLength / (this.GetRadiusAtTime(node, 0f, false) * 3.14159274f * 2f);
                bool  flag          = true;
                if (node.parent != null && treeGroupBranch != null)
                {
                    num2 = node.offset * node.parent.spline.GetApproximateLength();
                }
                float num4 = 1f - node.capRange;
                for (int i = 0; i < adaptiveSamples.Count; i++)
                {
                    float      num5           = adaptiveSamples[i];
                    Vector3    positionAtTime = node.spline.GetPositionAtTime(num5);
                    Quaternion rotationAtTime = node.spline.GetRotationAtTime(num5);
                    float      radiusAtTime   = this.GetRadiusAtTime(node, num5, false);
                    Matrix4x4  m = node.matrix * Matrix4x4.TRS(positionAtTime, rotationAtTime, new Vector3(1f, 1f, 1f));
                    Vector3    flareWeldAtTime = this.GetFlareWeldAtTime(node, num5);
                    float      num6            = Mathf.Max(flareWeldAtTime.x, Mathf.Max(flareWeldAtTime.y, flareWeldAtTime.z) * 0.25f);
                    if (num5 <= num4)
                    {
                        adaptiveRadialSegments = TreeData.GetAdaptiveRadialSegments(radiusAtTime + num6, adaptiveQuality2);
                    }
                    if (flag)
                    {
                        if (i > 0)
                        {
                            float num7 = adaptiveSamples[i - 1];
                            float num8 = num5 - num7;
                            float num9 = (radiusAtTime + this.GetRadiusAtTime(node, num7, false)) * 0.5f;
                            num += num8 * approximateLength / (num9 * 3.14159274f * 2f);
                        }
                    }
                    else
                    {
                        num = num2 + num5 * num3;
                    }
                    Vector2  vector   = base.ComputeWindFactor(node, num5);
                    RingLoop ringLoop = new RingLoop();
                    ringLoop.Reset(radiusAtTime, m, num, adaptiveRadialSegments);
                    ringLoop.SetSurfaceAngle(node.GetSurfaceAngleAtTime(num5));
                    ringLoop.SetAnimationProperties(vector.x, vector.y, 0f, node.animSeed);
                    ringLoop.SetSpread(flareWeldAtTime.y, flareWeldAtTime.z);
                    ringLoop.SetNoise(this.noise * Mathf.Clamp01(this.noiseCurve.Evaluate(num5)), this.noiseScaleU * 10f, this.noiseScaleV * 10f);
                    ringLoop.SetFlares(flareWeldAtTime.x, this.flareNoise * 10f);
                    int count2 = verts.Count;
                    ringLoop.BuildVertices(verts);
                    int count3 = verts.Count;
                    if ((buildFlags & 2) != 0)
                    {
                        float num10 = this.weldHeight;
                        float num11 = Mathf.Pow(Mathf.Clamp01((1f - num5 - (1f - this.weldHeight)) / this.weldHeight), 1.5f);
                        float d     = 1f - num11;
                        if (num5 < num10 && node.parent != null && node.parent.spline != null)
                        {
                            Ray ray = default(Ray);
                            for (int j = count2; j < count3; j++)
                            {
                                ray.origin    = verts[j].pos;
                                ray.direction = m.MultiplyVector(-Vector3.up);
                                Vector3 pos   = verts[j].pos;
                                Vector3 nor   = verts[j].nor;
                                float   num12 = -10000f;
                                float   num13 = 100000f;
                                for (int k = node.parent.triStart; k < node.parent.triEnd; k++)
                                {
                                    object obj = MathUtils.IntersectRayTriangle(ray, verts[tris[k].v[0]].pos, verts[tris[k].v[1]].pos, verts[tris[k].v[2]].pos, true);
                                    if (obj != null)
                                    {
                                        RaycastHit raycastHit = (RaycastHit)obj;
                                        if (Mathf.Abs(raycastHit.distance) < num13 && raycastHit.distance > num12)
                                        {
                                            num13        = Mathf.Abs(raycastHit.distance);
                                            verts[j].nor = verts[tris[k].v[0]].nor * raycastHit.barycentricCoordinate.x + verts[tris[k].v[1]].nor * raycastHit.barycentricCoordinate.y + verts[tris[k].v[2]].nor * raycastHit.barycentricCoordinate.z;
                                            verts[j].nor = verts[j].nor * num11 + nor * d;
                                            verts[j].pos = raycastHit.point * num11 + pos * d;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    list.Add(ringLoop);
                    if (num5 == 1f && ringLoop.radius > 0.005f)
                    {
                        RingLoop ringLoop2 = ringLoop.Clone();
                        ringLoop2.radius      = 0f;
                        ringLoop2.baseOffset += radiusAtTime / 6.28318548f;
                        ringLoop2.BuildVertices(verts);
                        list.Add(ringLoop2);
                    }
                }
                if (list.Count > 0 && list[list.Count - 1].radius > 0.025f && node.breakOffset < 1f)
                {
                    float    mappingScale = 1f / (this.radius * 3.14159274f * 2f);
                    float    sphereFactor = 0f;
                    float    num14        = 1f;
                    int      mappingMode  = 0;
                    Material m2           = this.materialBranch;
                    if (this.materialBreak != null)
                    {
                        m2 = this.materialBreak;
                    }
                    int materialIndex2 = TreeGroup.GetMaterialIndex(m2, materials, false);
                    list[list.Count - 1].Cap(sphereFactor, num14, mappingMode, mappingScale, verts, tris, materialIndex2);
                }
                node.triStart = tris.Count;
                for (int l = 0; l < list.Count - 1; l++)
                {
                    list[l].Connect(list[l + 1], tris, materialIndex, false, false);
                }
                node.triEnd = tris.Count;
                list.Clear();
            }
            float num15 = Mathf.Min(this.frondRange.x, this.frondRange.y);
            float num16 = Mathf.Max(this.frondRange.x, this.frondRange.y);
            float num17 = num15;
            float num18 = num16;

            num15 = Mathf.Clamp(num15, 0f, node.breakOffset);
            num16 = Mathf.Clamp(num16, 0f, node.breakOffset);
            if ((this.geometryMode == TreeGroupBranch.GeometryMode.BranchFrond || this.geometryMode == TreeGroupBranch.GeometryMode.Frond) && this.frondCount > 0 && num15 != num16)
            {
                bool flag2 = true;
                bool flag3 = true;
                for (int n = 0; n < adaptiveSamples.Count; n++)
                {
                    float num19 = adaptiveSamples[n];
                    if (num19 < num15)
                    {
                        adaptiveSamples.RemoveAt(n);
                        n--;
                    }
                    else
                    {
                        if (num19 == num15)
                        {
                            flag2 = false;
                        }
                        else
                        {
                            if (num19 == num16)
                            {
                                flag3 = false;
                            }
                            else
                            {
                                if (num19 > num16)
                                {
                                    adaptiveSamples.RemoveAt(n);
                                    n--;
                                }
                            }
                        }
                    }
                }
                if (flag2)
                {
                    adaptiveSamples.Insert(0, num15);
                }
                if (flag3)
                {
                    adaptiveSamples.Add(num16);
                }
                int   materialIndex3 = TreeGroup.GetMaterialIndex(this.materialFrond, materials, false);
                float num20          = 1f - node.capRange;
                for (int num21 = 0; num21 < this.frondCount; num21++)
                {
                    float   num22   = this.frondCrease * 90f * 0.0174532924f;
                    float   num23   = (this.frondRotation * 360f + (float)num21 * 180f / (float)this.frondCount - 90f) * 0.0174532924f;
                    float   f       = -num23 - num22;
                    float   f2      = num23 - num22;
                    Vector3 a       = new Vector3(Mathf.Sin(f), 0f, Mathf.Cos(f));
                    Vector3 vector2 = new Vector3(a.z, 0f, -a.x);
                    Vector3 a2      = new Vector3(Mathf.Sin(f2), 0f, -Mathf.Cos(f2));
                    Vector3 vector3 = new Vector3(-a2.z, 0f, a2.x);
                    for (int num24 = 0; num24 < adaptiveSamples.Count; num24++)
                    {
                        float num25     = adaptiveSamples[num24];
                        float y         = (num25 - num17) / (num18 - num17);
                        float timeParam = num25;
                        if (num25 > num20)
                        {
                            timeParam = num20;
                            float f3    = Mathf.Acos(Mathf.Clamp01((num25 - num20) / node.capRange));
                            float num26 = Mathf.Sin(f3);
                            float y2    = Mathf.Cos(f3) * this.capSmoothing;
                            a       = new Vector3(Mathf.Sin(f) * num26, y2, Mathf.Cos(f) * num26);
                            vector2 = new Vector3(a.z, a.y, -a.x);
                            a2      = new Vector3(Mathf.Sin(f2) * num26, y2, -Mathf.Cos(f2) * num26);
                            vector3 = new Vector3(-a2.z, a2.y, a2.x);
                        }
                        Vector3    a3 = new Vector3(0f, 0f, -1f);
                        Vector3    positionAtTime2 = node.spline.GetPositionAtTime(timeParam);
                        Quaternion rotationAtTime2 = node.spline.GetRotationAtTime(num25);
                        float      d2       = Mathf.Clamp01(this.frondCurve.Evaluate(num25)) * this.frondWidth * node.GetScale();
                        Matrix4x4  matrix4x = node.matrix * Matrix4x4.TRS(positionAtTime2, rotationAtTime2, new Vector3(1f, 1f, 1f));
                        if (TreeGroup.GenerateDoubleSidedGeometry)
                        {
                            for (float num27 = -1f; num27 < 2f; num27 += 2f)
                            {
                                TreeVertex treeVertex = new TreeVertex();
                                treeVertex.pos       = matrix4x.MultiplyPoint(a * d2);
                                treeVertex.nor       = matrix4x.MultiplyVector(vector2 * num27).normalized;
                                treeVertex.tangent   = TreeGroup.CreateTangent(node, rotationAtTime2, treeVertex.nor);
                                treeVertex.tangent.w = -num27;
                                treeVertex.uv0       = new Vector2(1f, y);
                                TreeVertex treeVertex2 = new TreeVertex();
                                treeVertex2.pos       = matrix4x.MultiplyPoint(Vector3.zero);
                                treeVertex2.nor       = matrix4x.MultiplyVector(a3 * num27).normalized;
                                treeVertex2.tangent   = TreeGroup.CreateTangent(node, rotationAtTime2, treeVertex2.nor);
                                treeVertex2.tangent.w = -num27;
                                treeVertex2.uv0       = new Vector2(0.5f, y);
                                TreeVertex treeVertex3 = new TreeVertex();
                                treeVertex3.pos       = matrix4x.MultiplyPoint(Vector3.zero);
                                treeVertex3.nor       = matrix4x.MultiplyVector(a3 * num27).normalized;
                                treeVertex3.tangent   = TreeGroup.CreateTangent(node, rotationAtTime2, treeVertex3.nor);
                                treeVertex3.tangent.w = -num27;
                                treeVertex3.uv0       = new Vector2(0.5f, y);
                                TreeVertex treeVertex4 = new TreeVertex();
                                treeVertex4.pos       = matrix4x.MultiplyPoint(a2 * d2);
                                treeVertex4.nor       = matrix4x.MultiplyVector(vector3 * num27).normalized;
                                treeVertex4.tangent   = TreeGroup.CreateTangent(node, rotationAtTime2, treeVertex4.nor);
                                treeVertex4.tangent.w = -num27;
                                treeVertex4.uv0       = new Vector2(0f, y);
                                Vector2 vector4 = base.ComputeWindFactor(node, num25);
                                treeVertex.SetAnimationProperties(vector4.x, vector4.y, this.animationEdge, node.animSeed);
                                treeVertex2.SetAnimationProperties(vector4.x, vector4.y, 0f, node.animSeed);
                                treeVertex3.SetAnimationProperties(vector4.x, vector4.y, 0f, node.animSeed);
                                treeVertex4.SetAnimationProperties(vector4.x, vector4.y, this.animationEdge, node.animSeed);
                                verts.Add(treeVertex);
                                verts.Add(treeVertex2);
                                verts.Add(treeVertex3);
                                verts.Add(treeVertex4);
                            }
                            if (num24 > 0)
                            {
                                int          count4        = verts.Count;
                                TreeTriangle treeTriangle  = new TreeTriangle(materialIndex3, count4 - 4, count4 - 3, count4 - 11);
                                TreeTriangle treeTriangle2 = new TreeTriangle(materialIndex3, count4 - 4, count4 - 11, count4 - 12);
                                treeTriangle.flip();
                                treeTriangle2.flip();
                                TreeTriangle item  = new TreeTriangle(materialIndex3, count4 - 8, count4 - 7, count4 - 15);
                                TreeTriangle item2 = new TreeTriangle(materialIndex3, count4 - 8, count4 - 15, count4 - 16);
                                tris.Add(treeTriangle);
                                tris.Add(treeTriangle2);
                                tris.Add(item);
                                tris.Add(item2);
                                TreeTriangle item3         = new TreeTriangle(materialIndex3, count4 - 2, count4 - 9, count4 - 1);
                                TreeTriangle item4         = new TreeTriangle(materialIndex3, count4 - 2, count4 - 10, count4 - 9);
                                TreeTriangle treeTriangle3 = new TreeTriangle(materialIndex3, count4 - 6, count4 - 13, count4 - 5);
                                TreeTriangle treeTriangle4 = new TreeTriangle(materialIndex3, count4 - 6, count4 - 14, count4 - 13);
                                treeTriangle3.flip();
                                treeTriangle4.flip();
                                tris.Add(item3);
                                tris.Add(item4);
                                tris.Add(treeTriangle3);
                                tris.Add(treeTriangle4);
                            }
                        }
                        else
                        {
                            TreeVertex treeVertex5 = new TreeVertex();
                            treeVertex5.pos = matrix4x.MultiplyPoint(a * d2);
                            treeVertex5.nor = matrix4x.MultiplyVector(vector2).normalized;
                            treeVertex5.uv0 = new Vector2(0f, y);
                            TreeVertex treeVertex6 = new TreeVertex();
                            treeVertex6.pos = matrix4x.MultiplyPoint(Vector3.zero);
                            treeVertex6.nor = matrix4x.MultiplyVector(Vector3.back).normalized;
                            treeVertex6.uv0 = new Vector2(0.5f, y);
                            TreeVertex treeVertex7 = new TreeVertex();
                            treeVertex7.pos = matrix4x.MultiplyPoint(a2 * d2);
                            treeVertex7.nor = matrix4x.MultiplyVector(vector3).normalized;
                            treeVertex7.uv0 = new Vector2(1f, y);
                            Vector2 vector5 = base.ComputeWindFactor(node, num25);
                            treeVertex5.SetAnimationProperties(vector5.x, vector5.y, this.animationEdge, node.animSeed);
                            treeVertex6.SetAnimationProperties(vector5.x, vector5.y, 0f, node.animSeed);
                            treeVertex7.SetAnimationProperties(vector5.x, vector5.y, this.animationEdge, node.animSeed);
                            verts.Add(treeVertex5);
                            verts.Add(treeVertex6);
                            verts.Add(treeVertex7);
                            if (num24 > 0)
                            {
                                int          count5 = verts.Count;
                                TreeTriangle item5  = new TreeTriangle(materialIndex3, count5 - 2, count5 - 3, count5 - 6);
                                TreeTriangle item6  = new TreeTriangle(materialIndex3, count5 - 2, count5 - 6, count5 - 5);
                                tris.Add(item5);
                                tris.Add(item6);
                                TreeTriangle item7 = new TreeTriangle(materialIndex3, count5 - 2, count5 - 4, count5 - 1);
                                TreeTriangle item8 = new TreeTriangle(materialIndex3, count5 - 2, count5 - 5, count5 - 4);
                                tris.Add(item7);
                                tris.Add(item8);
                            }
                        }
                    }
                }
            }
            if ((buildFlags & 1) != 0)
            {
                for (int num28 = count; num28 < verts.Count; num28++)
                {
                    verts[num28].SetAmbientOcclusion(TreeGroup.ComputeAmbientOcclusion(verts[num28].pos, verts[num28].nor, aoSpheres, aoDensity));
                }
            }
            node.vertEnd = verts.Count;
            Profiler.EndSample();
        }