Example #1
0
        protected virtual void AddRenderUV(MeshData meshData, byte extendId, Direction direction)
        {
            Direction resultDirection = GetRealDirection(extendId, direction);

            Rect uvRect = GetUVRect(extendId, resultDirection);

            meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(uvRect.x, uvRect.y));
            meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(uvRect.x, uvRect.y));
            meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(uvRect.x, uvRect.y));
            meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(uvRect.x, uvRect.y));
        }
Example #2
0
        protected virtual void AddSpecialUV(MeshData meshData, byte extendId, Direction direction)
        {
            Direction resultDirection = GetRealDirection(extendId, direction);

            Rect  uvRect = GetUVRect(extendId, resultDirection);
            float scale  = uvRect.width * 0.03f;

            meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(uvRect.x + scale, uvRect.y + scale));
            meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(uvRect.x + uvRect.width - scale, uvRect.y + scale));
            meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(uvRect.x + uvRect.width - scale, uvRect.y + uvRect.height - scale));
            meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(uvRect.x + scale, uvRect.y + uvRect.height - scale));
        }
        private void AddUVRotate(MeshData meshData, byte extendId, Direction direction, float sinDic, float cosDic)
        {
            Direction resultDirection = GetRealDirection(extendId, Direction.up);

            Rect    uvRect = GetUVRect(extendId, resultDirection);
            Vector2 center = uvRect.center;

            float scale = 0;

            meshData.AddUV(Rotate(center, MeshBaseDataCache.Instance.GetVector2(uvRect.x + scale, uvRect.y + scale), sinDic, cosDic));
            meshData.AddUV(Rotate(center, MeshBaseDataCache.Instance.GetVector2(uvRect.x + uvRect.width - scale, uvRect.y + scale), sinDic, cosDic));
            meshData.AddUV(Rotate(center, MeshBaseDataCache.Instance.GetVector2(uvRect.x + uvRect.width - scale, uvRect.y + uvRect.height - scale), sinDic, cosDic));
            meshData.AddUV(Rotate(center, MeshBaseDataCache.Instance.GetVector2(uvRect.x + scale, uvRect.y + uvRect.height - scale), sinDic, cosDic));
        }
        public override void CalculateSpecialMesh(Chunk chunk, int x, int y, int z, MeshData meshData, Block self, Block other, BlockAttributeCalculator otherCalculator, Direction direction)
        {
            //因为会计算六次
            if (direction != Direction.right)
            {
                return;
            }
            if (!IsModelCenter(self.ExtendId))
            {
                return;
            }
            ModelData modelData  = ModelDataManager.Instance.GetModelData((int)self.BlockType);
            Direction face       = GetFaceDirection(self.ExtendId);
            Vector2   rotate     = GetRotateSinAndCos(face);
            int       sunLight   = chunk.GetSunLight(x, y, z, true);
            int       blockLight = chunk.GetBlockLight(x, y, z, true);
            Rect      rect       = GetUVRect(self.ExtendId, direction);

            meshData.useRenderDataForCol = true;
            int verticesIndex    = meshData.GetCurVerticesIndex();
            int colVerticesIndex = meshData.GetCurColVerticesIndex();

            for (int i = 0; i < modelData.vertices.Length; i++)
            {
                Vector3[] vertices = modelData.vertices;
                Vector2[] uvs      = modelData.uvs;

                float verX  = vertices[i].x * rotate.y + vertices[i].z * rotate.x;
                float verZ  = -vertices[i].x * rotate.x + vertices[i].z * rotate.y;
                float realX = x + 0.5f + verX;
                float realY = y + vertices[i].y;
                float realZ = z + 0.5f + verZ;
                //添加渲染网格
                meshData.AddVertice(MeshBaseDataCache.Instance.GetVector3(realX, realY, realZ));
                meshData.AddColor(MeshBaseDataCache.Instance.GetColor(LightConst.lightColor[sunLight], LightConst.lightColor[blockLight], 0, 2));
                //这里要转换uv坐标
                meshData.AddUV(MeshBaseDataCache.Instance.GetVector2(rect.x + uvs[i].x * rect.width, rect.y + uvs[i].y * rect.height));

                //添加碰撞网格
                meshData.AddColVertice(MeshBaseDataCache.Instance.GetVector3(realX, realY, realZ));
            }
            for (int i = 0; i < modelData.triangles.Length; i++)
            {
                meshData.AddTriangle(verticesIndex + modelData.triangles[i]);

                meshData.AddColTriangle(colVerticesIndex + modelData.triangles[i]);
            }
            meshData.useRenderDataForCol = MeshData.DefaultUseRenderDataForCol;
        }