public bool TryGetBlockModel(ResourceLocation modelName, out ResourcePackModelBase model) { if (BlockModels.TryGetValue(modelName, out model)) { return(true); } var m = BlockModels.FirstOrDefault(x => x.Key.ToString().EndsWith(modelName.Path, StringComparison.InvariantCultureIgnoreCase)) .Value; if (m != null) { model = m; return(true); } model = null; return(false); }
/// <summary> /// Create a new overlay renderer. /// </summary> public OverlayRenderer() { (float[] vertices, uint[] indices) = BlockModels.CreatePlaneModel(); drawGroup = ElementDrawGroup.Create(); drawGroup.SetStorage(elements: 6, vertices.Length, vertices, indices.Length, indices); Shaders.Overlay.Use(); drawGroup.VertexArrayBindBuffer(size: 5); int vertexLocation = Shaders.Overlay.GetAttributeLocation("aPosition"); drawGroup.VertexArrayBindAttribute(vertexLocation, size: 3, offset: 0); int texCordLocation = Shaders.Overlay.GetAttributeLocation("aTexCoord"); drawGroup.VertexArrayBindAttribute(texCordLocation, size: 2, offset: 3); }
public bool TryGetBlockModel(string @namespace, string modelName, out BlockModel model) { string fullName = $"{@namespace}:{modelName}"; if (BlockModels.TryGetValue(fullName, out model)) { return(true); } var m = BlockModels.FirstOrDefault(x => x.Value.Name.EndsWith(modelName, StringComparison.InvariantCultureIgnoreCase)) .Value; if (m != null) { model = m; return(true); } model = null; return(false); }
void MeshSimpleSide(BlockSide side) { ClientSection?neighbor = neighbors[(int)side]; Block? blockToCheck; Vector3i checkPos = side.Offset(pos); if (IsPositionOutOfSection(checkPos)) { checkPos = checkPos.Mod(SectionSize); bool atVerticalEnd = side is BlockSide.Top or BlockSide.Bottom; blockToCheck = neighbor?.GetBlock(checkPos) ?? (atVerticalEnd ? Block.Air : null); } else { blockToCheck = GetBlock(checkPos); } if (blockToCheck == null) { return; } if (!blockToCheck.IsFull || !blockToCheck.IsOpaque && (currentBlock.IsOpaque || currentBlock.RenderFaceAtNonOpaques || blockToCheck.RenderFaceAtNonOpaques)) { BlockMeshData mesh = currentBlock.GetMesh( BlockMeshInfo.Simple(side, data, currentLiquid)); side.Corners(out int[] a, out int[] b, out int[] c, out int[] d); int[][] uvs = BlockModels.GetBlockUVs(mesh.IsTextureRotated); // int: uv-- ---- ---- -xxx xxyy yyyz zzzz (uv: texture coords; xyz: position) int upperDataA = (uvs[0][0] << 31) | (uvs[0][1] << 30) | ((a[0] + x) << 10) | ((a[1] + y) << 5) | (a[2] + z); int upperDataB = (uvs[1][0] << 31) | (uvs[1][1] << 30) | ((b[0] + x) << 10) | ((b[1] + y) << 5) | (b[2] + z); int upperDataC = (uvs[2][0] << 31) | (uvs[2][1] << 30) | ((c[0] + x) << 10) | ((c[1] + y) << 5) | (c[2] + z); int upperDataD = (uvs[3][0] << 31) | (uvs[3][1] << 30) | ((d[0] + x) << 10) | ((d[1] + y) << 5) | (d[2] + z); // int: tttt tttt t--n nn-a ---i iiii iiii iiii (t: tint; n: normal; a: animated; i: texture index) int lowerData = (mesh.Tint.GetBits(blockTint) << 23) | ((int)side << 18) | mesh.GetAnimationBit(shift: 16) | mesh.TextureIndex; blockMeshFaceHolders[(int)side].AddFace( pos, lowerData, (upperDataA, upperDataB, upperDataC, upperDataD), mesh.IsTextureRotated); } }
/// <summary> /// Creates a new <see cref="SectionRenderer" />. /// </summary> public SectionRenderer() { simpleDrawGroup = ArrayIDataDrawGroup.Create(size: 2); crossPlantDrawGroup = ElementInstancedIDataDrawGroup.Create( BlockModels.CreateCrossPlantModel(Application.Client.Instance.Graphics.FoliageQuality), instanceSize: 2); cropPlantDrawGroup = ElementInstancedIDataDrawGroup.Create( BlockModels.CreateCropPlantModel(Application.Client.Instance.Graphics.FoliageQuality), instanceSize: 2); complexDrawGroup = ElementPositionDataDrawGroup.Create(positionSize: 3, dataSize: 2); varyingHeightDrawGroup = ElementIDataDrawGroup.Create(size: 2); opaqueLiquidDrawGroup = ElementIDataDrawGroup.Create(size: 2); transparentLiquidDrawGroup = ElementIDataDrawGroup.Create(size: 2); #region SIMPLE BUFFER SETUP simpleDrawGroup.VertexArrayBindBuffer(); Shaders.SimpleSection.Use(); int dataLocation = Shaders.SimpleSection.GetAttributeLocation("aData"); simpleDrawGroup.VertexArrayAttributeBinding(dataLocation); #endregion SIMPLE BUFFER SETUP #region CROSS PLANT BUFFER SETUP crossPlantDrawGroup.VertexArrayBindBuffer(modelSize: 5); Shaders.CrossPlantSection.Use(); dataLocation = Shaders.CrossPlantSection.GetAttributeLocation("aVertexPosition"); crossPlantDrawGroup.VertexArrayModelAttributeBinding(dataLocation, size: 3, offset: 0); dataLocation = Shaders.CrossPlantSection.GetAttributeLocation("aTexCoord"); crossPlantDrawGroup.VertexArrayModelAttributeBinding(dataLocation, size: 2, offset: 3); dataLocation = Shaders.CrossPlantSection.GetAttributeLocation("aInstanceData"); crossPlantDrawGroup.VertexArrayInstanceAttributeBinding(dataLocation); #endregion CROSS PLANT BUFFER SETUP #region CROP PLANT BUFFER SETUP cropPlantDrawGroup.VertexArrayBindBuffer(modelSize: 8); Shaders.CropPlantSection.Use(); dataLocation = Shaders.CropPlantSection.GetAttributeLocation("aVertexPositionNS"); cropPlantDrawGroup.VertexArrayModelAttributeBinding(dataLocation, size: 3, offset: 0); dataLocation = Shaders.CropPlantSection.GetAttributeLocation("aVertexPositionEW"); cropPlantDrawGroup.VertexArrayModelAttributeBinding(dataLocation, size: 3, offset: 3); dataLocation = Shaders.CropPlantSection.GetAttributeLocation("aTexCoord"); cropPlantDrawGroup.VertexArrayModelAttributeBinding(dataLocation, size: 2, offset: 6); dataLocation = Shaders.CropPlantSection.GetAttributeLocation("aInstanceData"); cropPlantDrawGroup.VertexArrayInstanceAttributeBinding(dataLocation); #endregion CROP PLANT BUFFER SETUP #region COMPLEX BUFFER SETUP complexDrawGroup.VertexArrayBindBuffer(); Shaders.ComplexSection.Use(); int positionLocation = Shaders.ComplexSection.GetAttributeLocation("aPosition"); dataLocation = Shaders.ComplexSection.GetAttributeLocation("aData"); complexDrawGroup.VertexArrayAttributeBinding(positionLocation, dataLocation); #endregion COMPLEX BUFFER SETUP #region VARYING HEIGHT BUFFER SETUP varyingHeightDrawGroup.VertexArrayBindBuffer(); Shaders.VaryingHeightSection.Use(); dataLocation = Shaders.VaryingHeightSection.GetAttributeLocation("aData"); varyingHeightDrawGroup.VertexArrayAttributeBinding(dataLocation); #endregion VARYING HEIGHT BUFFER SETUP #region OPAQUE LIQUID BUFFER SETUP opaqueLiquidDrawGroup.VertexArrayBindBuffer(); Shaders.OpaqueLiquidSection.Use(); dataLocation = Shaders.OpaqueLiquidSection.GetAttributeLocation("aData"); opaqueLiquidDrawGroup.VertexArrayAttributeBinding(dataLocation); #endregion OPAQUE LIQUID BUFFER SETUP #region TRANSPARENT LIQUID BUFFER SETUP transparentLiquidDrawGroup.VertexArrayBindBuffer(); Shaders.TransparentLiquidSection.Use(); dataLocation = Shaders.TransparentLiquidSection.GetAttributeLocation("aData"); transparentLiquidDrawGroup.VertexArrayAttributeBinding(dataLocation); #endregion TRANSPARENT LIQUID BUFFER SETUP }
/// <inheritdoc /> protected override void Setup(ITextureIndexProvider indexProvider) { indices = BlockModels.GenerateIndexDataArray(faces: 2); textureIndices = BlockModels.GenerateTextureDataArray(indexProvider.GetTextureIndex(texture), length: 8); }
private static float[] CreateSide(Orientation orientation) { return(BlockModels.CreateFlatModel(orientation.ToBlockSide().Opposite(), offset: 0.01f)); }