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; } }
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; // Check for visibility.. if (!node.visible || !visible) { return; } Profiler.BeginSample("TreeGroupLeaf.UpdateNodeMesh"); Vector2 windFactors = ComputeWindFactor(node, node.offset); if (geometryMode == (int)GeometryMode.MESH) { // Exit if no instance mesh is selected if (cloneMesh == null) { // Debug.LogError("No cloneMesh"); return; } if (cloneVerts == null) { // Debug.LogError("No cloneVerts"); return; } if (cloneNormals == null) { // Debug.LogError("No cloneNormals"); return; } if (cloneTangents == null) { // Debug.LogError("No cloneTangents"); return; } if (cloneUVs == null) { // Debug.LogError("No cloneUVs"); return; } Matrix4x4 cloneMatrix = instanceMesh.transform.localToWorldMatrix; Matrix4x4 tformMatrix = node.matrix * cloneMatrix; int vertOffset = verts.Count; float dist = 5.0f; // copy verts for (int i = 0; i < cloneVerts.Length; i++) { TreeVertex v0 = new TreeVertex(); v0.pos = tformMatrix.MultiplyPoint(cloneVerts[i]); v0.nor = tformMatrix.MultiplyVector(cloneNormals[i]).normalized; v0.uv0 = new Vector2(cloneUVs[i].x, cloneUVs[i].y); Vector3 tangent = tformMatrix.MultiplyVector(new Vector3(cloneTangents[i].x, cloneTangents[i].y, cloneTangents[i].z)).normalized; v0.tangent = new Vector4(tangent.x, tangent.y, tangent.z, cloneTangents[i].w); // wind float windEdge = (cloneVerts[i].magnitude / dist) * animationEdge; v0.SetAnimationProperties(windFactors.x, windFactors.y, windEdge, node.animSeed); // AO if ((buildFlags & (int)BuildFlag.BuildAmbientOcclusion) != 0) { v0.SetAmbientOcclusion(ComputeAmbientOcclusion(v0.pos, v0.nor, aoSpheres, aoDensity)); } verts.Add(v0); } // copy tris for (int s = 0; s < cloneMesh.subMeshCount; s++) { int[] instanceTris = cloneMesh.GetTriangles(s); int materialIndex; if (instanceMesh.GetComponent <Renderer>() != null && s < instanceMesh.GetComponent <Renderer>().sharedMaterials.Length) { materialIndex = GetMaterialIndex(instanceMesh.GetComponent <Renderer>().sharedMaterials[s], materials, false); } else { materialIndex = GetMaterialIndex(null, materials, false); } for (int i = 0; i < instanceTris.Length; i += 3) { TreeTriangle t0 = new TreeTriangle(materialIndex, instanceTris[i] + vertOffset, instanceTris[i + 1] + vertOffset, instanceTris[i + 2] + vertOffset); tris.Add(t0); } } } else if (geometryMode == (int)GeometryMode.BILLBOARD) { // rotation Vector3 eulerRot = node.rotation.eulerAngles; eulerRot.z = eulerRot.x * 2.0f; eulerRot.x = 0.0f; eulerRot.y = 0.0f; Quaternion billboardRotation = Quaternion.Euler(eulerRot); // normal Vector3 normalBase = new Vector3(GenerateBendBillboardNormalFactor, GenerateBendBillboardNormalFactor, 1.0f); Vector3 tangentBase = billboardRotation * new Vector3(1, 0, 0); float normalFix = node.scale / (GenerateBendBillboardNormalFactor * GenerateBendBillboardNormalFactor); TreeVertex v0 = CreateBillboardVertex(node, billboardRotation, normalBase, normalFix, tangentBase, new Vector2(0, 1)); TreeVertex v1 = CreateBillboardVertex(node, billboardRotation, normalBase, normalFix, tangentBase, new Vector2(0, 0)); TreeVertex v2 = CreateBillboardVertex(node, billboardRotation, normalBase, normalFix, tangentBase, new Vector2(1, 0)); TreeVertex v3 = CreateBillboardVertex(node, billboardRotation, normalBase, normalFix, tangentBase, new Vector2(1, 1)); // wind v0.SetAnimationProperties(windFactors.x, windFactors.y, animationEdge, node.animSeed); v1.SetAnimationProperties(windFactors.x, windFactors.y, animationEdge, node.animSeed); v2.SetAnimationProperties(windFactors.x, windFactors.y, animationEdge, node.animSeed); v3.SetAnimationProperties(windFactors.x, windFactors.y, animationEdge, node.animSeed); if ((buildFlags & (int)BuildFlag.BuildAmbientOcclusion) != 0) { // Vector3 pushU = Vector3.up * internalSize; Vector3 pushR = Vector3.right * node.scale; Vector3 pushF = Vector3.forward * node.scale; float a = 0.0f; // ComputeAmbientOcclusion(partID, v0.pos + pushU, Vector3.up, aoSpheres); //a += ComputeAmbientOcclusion(partID, v0.pos - pushU, -Vector3.up, aoSpheres); a = ComputeAmbientOcclusion(v0.pos + pushR, Vector3.right, aoSpheres, aoDensity); a += ComputeAmbientOcclusion(v0.pos - pushR, -Vector3.right, aoSpheres, aoDensity); a += ComputeAmbientOcclusion(v0.pos + pushF, Vector3.forward, aoSpheres, aoDensity); a += ComputeAmbientOcclusion(v0.pos - pushF, -Vector3.forward, aoSpheres, aoDensity); a /= 4.0f; v0.SetAmbientOcclusion(a); v1.SetAmbientOcclusion(a); v2.SetAmbientOcclusion(a); v3.SetAmbientOcclusion(a); } int index0 = verts.Count; verts.Add(v0); verts.Add(v1); verts.Add(v2); verts.Add(v3); int materialIndex = GetMaterialIndex(materialLeaf, materials, false); tris.Add(new TreeTriangle(materialIndex, index0, index0 + 2, index0 + 1, true)); tris.Add(new TreeTriangle(materialIndex, index0, index0 + 3, index0 + 2, true)); } else { // plane, cross, tri-cross int planes = 0; switch ((GeometryMode)geometryMode) { case GeometryMode.PLANE: planes = 1; break; case GeometryMode.CROSS: planes = 2; break; case GeometryMode.TRI_CROSS: planes = 3; break; } int materialIndex = GetMaterialIndex(materialLeaf, materials, false); Vector2[] rawHull = new Vector2[] { new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1) }; Vector2[] textureHull = GetPlaneHullVertices(materialLeaf); if (textureHull == null) { textureHull = rawHull; } float ns = node.scale; Vector3[] positionsRaw = new Vector3[] { new Vector3(-ns, 0f, -ns), new Vector3(-ns, 0f, ns), new Vector3(ns, 0f, ns), new Vector3(ns, 0f, -ns) }; Vector3 normal = new Vector3(GenerateBendNormalFactor, 1.0f - GenerateBendNormalFactor, GenerateBendNormalFactor); Vector3[] normalsRaw = new Vector3[] { new Vector3(-normal.x, normal.y, -normal.z).normalized, new Vector3(-normal.x, normal.y, 0).normalized, // note z always 0 new Vector3(normal.x, normal.y, 0).normalized, // note z always 0 new Vector3(normal.x, normal.y, -normal.z).normalized }; for (int ipl = 0; ipl < planes; ipl++) { Quaternion rot = Quaternion.Euler(new Vector3(90, 0, 0)); switch (ipl) { case 1: rot = Quaternion.Euler(new Vector3(90, 90, 0)); break; case 2: rot = Quaternion.Euler(new Vector3(0, 90, 0)); break; } TreeVertex[] tv = new TreeVertex[8] { new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), // initial quad new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex() // from bounding hull }; for (int i = 0; i < 4; ++i) { tv[i].pos = node.matrix.MultiplyPoint(rot * positionsRaw[i]); tv[i].nor = node.matrix.MultiplyVector(rot * normalsRaw[i]); tv[i].tangent = CreateTangent(node, rot, tv[i].nor); tv[i].uv0 = textureHull[i]; tv[i].SetAnimationProperties(windFactors.x, windFactors.y, animationEdge, node.animSeed); if ((buildFlags & (int)BuildFlag.BuildAmbientOcclusion) != 0) { tv[i].SetAmbientOcclusion(ComputeAmbientOcclusion(tv[i].pos, tv[i].nor, aoSpheres, aoDensity)); } } // now lerp positions into correct placed based on the bounding hull for (int i = 0; i < 4; ++i) { tv[i + 4].Lerp4(tv, textureHull[i]); tv[i + 4].uv0 = tv[i].uv0; tv[i + 4].uv1 = tv[i].uv1; tv[i + 4].flag = tv[i].flag; } int index0 = verts.Count; for (int i = 0; i < 4; ++i) { verts.Add(tv[i + 4]); } tris.Add(new TreeTriangle(materialIndex, index0, index0 + 1, index0 + 2)); tris.Add(new TreeTriangle(materialIndex, index0, index0 + 2, index0 + 3)); Vector3 faceNormal = node.matrix.MultiplyVector(rot * new Vector3(0, 1, 0)); if (GenerateDoubleSidedGeometry) { // Duplicate vertices with mirrored normal and tangent TreeVertex[] tv2 = new TreeVertex[8] { new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex(), // initial quad new TreeVertex(), new TreeVertex(), new TreeVertex(), new TreeVertex() // from bounding hull }; for (int i = 0; i < 4; ++i) { tv2[i].pos = tv[i].pos; tv2[i].nor = Vector3.Reflect(tv[i].nor, faceNormal); tv2[i].tangent = Vector3.Reflect(tv[i].tangent, faceNormal); tv2[i].tangent.w = -1; tv2[i].uv0 = tv[i].uv0; tv2[i].SetAnimationProperties(windFactors.x, windFactors.y, animationEdge, node.animSeed); if ((buildFlags & (int)BuildFlag.BuildAmbientOcclusion) != 0) { tv2[i].SetAmbientOcclusion(ComputeAmbientOcclusion(tv2[i].pos, tv2[i].nor, aoSpheres, aoDensity)); } } // now lerp positions into correct placed based on the bounding hull for (int i = 0; i < 4; ++i) { tv2[i + 4].Lerp4(tv2, textureHull[i]); tv2[i + 4].uv0 = tv2[i].uv0; tv2[i + 4].uv1 = tv2[i].uv1; tv2[i + 4].flag = tv2[i].flag; } int index4 = verts.Count; for (int i = 0; i < 4; ++i) { verts.Add(tv2[i + 4]); } tris.Add(new TreeTriangle(materialIndex, index4, index4 + 2, index4 + 1)); tris.Add(new TreeTriangle(materialIndex, index4, index4 + 3, index4 + 2)); } } } node.triEnd = tris.Count; node.vertEnd = verts.Count; Profiler.EndSample(); // TreeGroupLeaf.UpdateNodeMesh }
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(); }
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(); }
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; } }