Exemplo n.º 1
0
        public void Build(Map map, RenderBuffer targetBuffer, ref BlockData block, ref Vector3Int worldPos,
            ref Vector3Int localPos)
        {
            float dmg = block.GetDamagePercent();
            Color32 color = BlockDatabase.GetBlockInfo(block.BlockType).Color;
            
            for (int i = 0; i<SFaces.Length; i++)
            {
                int yy = worldPos.Y+SDirections[i].Y;
                if (yy<0)
                    continue; // Nothing to do at the bottom of the world

                int xx = worldPos.X+SDirections[i].X;
                int zz = worldPos.Z+SDirections[i].Z;
                
                // Building of faces is only necessary if there's solid geometry around
                BlockData b = map.GetBlock(xx, yy, zz);
                if (!b.IsAlpha())
                    continue;

                int iface = (int)SFaces[i];

                // Fill buffers with data
                {
                    // Add indices
                    int pom = targetBuffer.Positions.Count;
                    targetBuffer.Triangles.Add(pom+2);
                    targetBuffer.Triangles.Add(pom+1);
                    targetBuffer.Triangles.Add(pom+0);
                    targetBuffer.Triangles.Add(pom+3);
                    targetBuffer.Triangles.Add(pom+2);
                    targetBuffer.Triangles.Add(pom+0);

                    // Add vertices
                    targetBuffer.Positions.Add(new Vector3(SVertices[i][0].x+localPos.X,
                                                           SVertices[i][0].y+localPos.Y,
                                                           SVertices[i][0].z+localPos.Z));
                    targetBuffer.Positions.Add(new Vector3(SVertices[i][1].x+localPos.X,
                                                           SVertices[i][1].y+localPos.Y,
                                                           SVertices[i][1].z+localPos.Z));
                    targetBuffer.Positions.Add(new Vector3(SVertices[i][2].x+localPos.X,
                                                           SVertices[i][2].y+localPos.Y,
                                                           SVertices[i][2].z+localPos.Z));
                    targetBuffer.Positions.Add(new Vector3(SVertices[i][3].x+localPos.X,
                                                           SVertices[i][3].y+localPos.Y,
                                                           SVertices[i][3].z+localPos.Z));

                    // Add colors
                    targetBuffer.Colors.Add(color);
                    targetBuffer.Colors.Add(color);
                    targetBuffer.Colors.Add(color);
                    targetBuffer.Colors.Add(color);

                    // Add UVs
                    Rect texCoords = GetTexture(iface);
                    targetBuffer.UVs.Add(new Vector2(texCoords.xMax, 1f-texCoords.yMax));
                    targetBuffer.UVs.Add(new Vector2(texCoords.xMax, 1f-texCoords.yMin));
                    targetBuffer.UVs.Add(new Vector2(texCoords.xMin, 1f-texCoords.yMin));
                    targetBuffer.UVs.Add(new Vector2(texCoords.xMin, 1f-texCoords.yMax));

                    // Add damage UVs
                    float damage = dmg*(RenderBufferExtension.DamageFrames-1);
                    int dmgFrame = Mathf.FloorToInt(damage);
                    texCoords = new Rect(dmgFrame*RenderBufferExtension.DamageMultiplier, 0f,
                                         RenderBufferExtension.DamageMultiplier, 1f);
                    targetBuffer.UV2.Add(new Vector2(texCoords.xMax, 1f-texCoords.yMin));
                    targetBuffer.UV2.Add(new Vector2(texCoords.xMax, 1f-texCoords.yMax));
                    targetBuffer.UV2.Add(new Vector2(texCoords.xMin, 1f-texCoords.yMax));
                    targetBuffer.UV2.Add(new Vector2(texCoords.xMin, 1f-texCoords.yMin));

                    // Add normals
                    targetBuffer.Normals.AddRange(SNormals[iface]);
                }
            }
        }
Exemplo n.º 2
0
        public void Build(Map map, RenderBuffer targetBuffer, ref BlockData block, int face, bool backFace,
            ref Vector3[] vecs, ref Vector3Int worldPos)
        {
            if (worldPos.Y<0)
                return;

            int i = face;
            int iface = (int)SFaces[i];

            float dmg = block.GetDamagePercent();
            Color32 color = BlockDatabase.GetBlockInfo(block.BlockType).Color;

            // Empty block found, create a face
            targetBuffer.AddFaceIndices(backFace);
            targetBuffer.AddVertices(ref vecs);
            targetBuffer.AddFaceColors(ref color);
            targetBuffer.AddFaceUv(GetTexture(iface));
            targetBuffer.AddDamageUVs(dmg);
            targetBuffer.AddNormals(ref SNormals[iface]);
        }