public void Init() { _renderer = GetComponent <MeshRenderer>(); _filter = GetComponent <MeshFilter>(); _genMesh = new GeneratableMesh(64); _inited = true; }
static void AddUVs(this GeneratableMesh meshInfo, Vector2[] uvs) { var uvsList = meshInfo.UVs; for (int i = 0; i < uvs.Length; i++) { uvsList.Add(uvs[i]); } }
static void AddTriangles(this GeneratableMesh meshInfo, int[] indexes, int rootIndex) { var trisList = meshInfo.Triangles; for (int i = 0; i < indexes.Length; i++) { trisList.Add(indexes[i] + rootIndex); } }
static void AddVerticesWithPos(this GeneratableMesh meshInfo, Vector3[] verts, Vector3 rootPos) { var vertsList = meshInfo.Vertices; for (int i = 0; i < verts.Length; i++) { vertsList.Add(verts[i] + rootPos); } }
public ChunkMesher(BlockInfoProvider library, int chunkMeshCapacity, int capacity, Vector3 originPos) { _opaqueCollidedMesh = new GeneratableMesh(chunkMeshCapacity); _translucentPassableMesh = new GeneratableMesh(chunkMeshCapacity / 8); _opaquePassableMesh = new GeneratableMesh(chunkMeshCapacity / 8); _library = library; _originPos = originPos; Blocks = new List <MesherBlockInput>(capacity); }
public static void AddPlaneWithUVs(GeneratableMesh meshInfo, Vector3[] verts, Vector2[] uvs, Vector3 rootPos, int pointer, Color32 color) { meshInfo.AddVerticesWithPos(verts, rootPos); meshInfo.AddTriangles(_planeTris, pointer); meshInfo.AddUVs(uvs); //Ага meshInfo.Colors.Add(color); meshInfo.Colors.Add(color); meshInfo.Colors.Add(color); meshInfo.Colors.Add(color); }
public static void AddPlaneInv(GeneratableMesh meshInfo, Vector3[] verts, TilesetHelper helper, Byte2 tile, Vector3 rootPos, int pointer, Color32 color) { meshInfo.AddVerticesWithPos(verts, rootPos); meshInfo.AddTriangles(_planeTrisInverted, pointer); meshInfo.AddPlaneUVs(tile); //Ага meshInfo.Colors.Add(color); meshInfo.Colors.Add(color); meshInfo.Colors.Add(color); meshInfo.Colors.Add(color); }
public static void AddBlock(GeneratableMesh meshInfo, BlockDescription desc, ref Vector3 rootPos, ref MesherBlockInput input) { if (desc == null) { return; } var data = input.Block; var visibility = input.Visibility; var light = input.Lighting; switch (desc.ModelType) { case BlockModelType.None: return; case BlockModelType.FullBlockSimple: GenerateFullBlockSimple(meshInfo, desc, data, rootPos, visibility, light); return; case BlockModelType.FullBlockComplex: GenerateFullBlockComplex(meshInfo, desc, data, rootPos, visibility, light); return; case BlockModelType.HalfBlockDown: GenerateHalfBlockDown(meshInfo, desc, data, rootPos, visibility, light); return; case BlockModelType.HalfBlockUp: return; case BlockModelType.Stairs: return; case BlockModelType.Plate: return; case BlockModelType.Grass: return; case BlockModelType.HorizontalPlane: GenerateHorizontalPlane(meshInfo, desc, data, rootPos, visibility); return; case BlockModelType.SmallerBlock: return; case BlockModelType.CrossedVPlanes: GenerateCrossedVPlanes(meshInfo, desc, data, rootPos, visibility); return; default: return; } }
//Неполные блоки не рисуем только если они полностью ограждены полными блоками. public static void GenerateHorizontalPlane(GeneratableMesh meshInfo, BlockDescription desc, BlockData data, Vector3 rootPos, VisibilityFlags visibility) { if (visibility == VisibilityFlags.None) { return; } var pointer = meshInfo.Vertices.Count; var h = (byte)(data.AddColor >> 8); var l = (byte)(data.AddColor % 256); var calcColor = new Color32(data.SunLevel, data.LightLevel, h, l); AddPlane(meshInfo, _horizontalPlaneVerts, desc.Subtypes[Mathf.Clamp(data.Subtype, 0, desc.Subtypes.Count - 1)].FaceTiles[0], rootPos, pointer, calcColor); }
public static void GenerateCrossedVPlanes(GeneratableMesh meshInfo, BlockDescription desc, BlockData data, Vector3 rootPos, VisibilityFlags visibility) { var pointer = meshInfo.Vertices.Count; var tile = desc.Subtypes[Mathf.Clamp(data.Subtype, 0, desc.Subtypes.Count - 1)].FaceTiles[0]; var calcColor = new Color32(data.SunLevel, data.LightLevel, (byte)(data.AddColor >> 8), (byte)(data.AddColor % 256)); AddPlane(meshInfo, _rotVertPlaneVerts_0, tile, rootPos, pointer, calcColor); pointer += 4; AddPlane(meshInfo, _rotVertPlaneVerts_1, tile, rootPos, pointer, calcColor); pointer += 4; AddPlaneInv(meshInfo, _rotVertPlaneVerts_0, _helper, tile, rootPos, pointer, calcColor); pointer += 4; AddPlaneInv(meshInfo, _rotVertPlaneVerts_1, _helper, tile, rootPos, pointer, calcColor); pointer += 4; }
public static void GenerateFullBlockSimple(GeneratableMesh meshInfo, BlockDescription desc, BlockData data, Vector3 rootPos, VisibilityFlags visibility, LightInfo light) { var pointer = meshInfo.Vertices.Count; var tile = desc.Subtypes[Mathf.Clamp(data.Subtype, 0, desc.Subtypes.Count - 1)].FaceTiles[0]; var uvs = GetCachedUVsForTile(tile); var h = (byte)(data.AddColor >> 8); var l = (byte)(data.AddColor % 256); if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Backward)) { var calcColor = new Color32(light.SunBackward, light.OBackward, h, l); AddPlaneWithUVs(meshInfo, _fullBlockBackSide, uvs, rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Forward)) { var calcColor = new Color32(light.SunForward, light.OForward, h, l); AddPlaneWithUVs(meshInfo, _fullBlockFrontSide, uvs, rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Left)) { var calcColor = new Color32(light.SunLeft, light.OLeft, h, l); AddPlaneWithUVs(meshInfo, _fullBlockLeftSide, uvs, rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Right)) { var calcColor = new Color32(light.SunRight, light.ORight, h, l); AddPlaneWithUVs(meshInfo, _fullBlockRightSide, uvs, rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Up)) { var calcColor = new Color32(light.SunUp, light.OUp, h, l); AddPlaneWithUVs(meshInfo, _fullBlockUpSide, uvs, rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Down)) { var calcColor = new Color32(light.SunDown, light.ODown, h, l); AddPlaneWithUVs(meshInfo, _fullBlockDownSide, uvs, rootPos, pointer, calcColor); pointer += 4; } }
public static void GenerateHalfBlockDown(GeneratableMesh meshInfo, BlockDescription desc, BlockData data, Vector3 rootPos, VisibilityFlags visibility, LightInfo light) { var pointer = meshInfo.Vertices.Count; var sub = desc.Subtypes[Mathf.Clamp(data.Subtype, 0, desc.Subtypes.Count - 1)]; var h = (byte)(data.AddColor >> 8); var l = (byte)(data.AddColor % 256); if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Backward)) { var calcColor = new Color32(light.SunBackward, light.OBackward, h, l); AddPlane(meshInfo, _halfBlockDBackSide, sub.FaceTiles[0], rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Forward)) { var calcColor = new Color32(light.SunForward, light.OForward, h, l); AddPlane(meshInfo, _halfBlockDFrontSide, sub.FaceTiles[1], rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Left)) { var calcColor = new Color32(light.SunLeft, light.OLeft, h, l); AddPlane(meshInfo, _halfBlockDLeftSide, sub.FaceTiles[2], rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Right)) { var calcColor = new Color32(light.SunRight, light.ORight, h, l); AddPlane(meshInfo, _halfBlockDRightSide, sub.FaceTiles[3], rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Up)) { var calcColor = new Color32(light.SunUp, light.OUp, h, l); AddPlane(meshInfo, _halfBlockDUpside, sub.FaceTiles[4], rootPos, pointer, calcColor); pointer += 4; } if (VisibilityFlagsHelper.IsSet(visibility, VisibilityFlags.Down)) { var calcColor = new Color32(light.SunDown, light.ODown, h, l); AddPlane(meshInfo, _fullBlockDownSide, sub.FaceTiles[5], rootPos, pointer, calcColor); pointer += 4; } }
static void AddPlaneUVs(this GeneratableMesh meshInfo, Byte2 tilePos) { meshInfo.AddUVs(GetCachedUVsForTile(tilePos)); }