public ToolMoldRenderer(BlockPos pos, ICoreClientAPI api, Cuboidf[] fillQuadsByLevel = null)
        {
            this.pos = pos;
            this.api = api;

            this.fillQuadsByLevel = fillQuadsByLevel;

            quadModelRefs = new MeshRef[fillQuadsByLevel.Length];
            MeshData modeldata = QuadMeshUtil.GetQuad();

            modeldata.Rgba = new byte[4 * 4];
            modeldata.Rgba.Fill((byte)255);
            modeldata.Flags = new int[4 * 4];

            for (int i = 0; i < quadModelRefs.Length; i++)
            {
                Cuboidf size = fillQuadsByLevel[i];

                modeldata.Uv = new float[]
                {
                    size.X2 / 16f, size.Z2 / 16f,
                    size.X1 / 16f, size.Z2 / 16f,
                    size.X1 / 16f, size.Z1 / 16f,
                    size.X2 / 16f, size.Z1 / 16f
                };

                quadModelRefs[i] = api.Render.UploadMesh(modeldata);
            }
        }
        public ForgeContentsRenderer(BlockPos pos, ICoreClientAPI capi)
        {
            this.pos  = pos;
            this.capi = capi;

            metals = capi.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();

            Block block = capi.World.GetBlock(new AssetLocation("forge"));

            coaltexpos  = capi.BlockTextureAtlas.GetPosition(block, "coal");
            embertexpos = capi.BlockTextureAtlas.GetPosition(block, "ember");

            MeshData emberMesh = QuadMeshUtil.GetCustomQuadHorizontal(3 / 16f, 0, 3 / 16f, 10 / 16f, 10 / 16f, 255, 255, 255, 255);

            for (int i = 0; i < emberMesh.Uv.Length; i += 2)
            {
                emberMesh.Uv[i + 0] = embertexpos.x1 + emberMesh.Uv[i + 0] * 32f / AtlasSize;
                emberMesh.Uv[i + 1] = embertexpos.y1 + emberMesh.Uv[i + 1] * 32f / AtlasSize;
            }
            emberMesh.Flags = new int[] { 128, 128, 128, 128 };

            MeshData coalMesh = QuadMeshUtil.GetCustomQuadHorizontal(3 / 16f, 0, 3 / 16f, 10 / 16f, 10 / 16f, 255, 255, 255, 255);

            for (int i = 0; i < coalMesh.Uv.Length; i += 2)
            {
                coalMesh.Uv[i + 0] = coaltexpos.x1 + coalMesh.Uv[i + 0] * 32f / AtlasSize;;
                coalMesh.Uv[i + 1] = coaltexpos.y1 + coalMesh.Uv[i + 1] * 32f / AtlasSize;;
            }


            emberQuadRef = capi.Render.UploadMesh(emberMesh);
            coalQuadRef  = capi.Render.UploadMesh(coalMesh);
        }
Пример #3
0
        public WaypointMapComponent(Waypoint waypoint, LoadedTexture texture, ICoreClientAPI capi) : base(capi)
        {
            this.waypoint = waypoint;
            this.Texture  = texture;
            ColorUtil.ToRGBAVec4f(waypoint.Color, ref color);

            quadModel = capi.Render.UploadMesh(QuadMeshUtil.GetQuad());
        }
Пример #4
0
        public ScreenSpaceRenderer(ICoreClientAPI api, List <IShaderProgram> progs)
        {
            this.progs = progs;
            capi       = api;
            MeshData quadMesh = QuadMeshUtil.GetQuad();

            quadMesh.Rgba = null;
            quadRef       = capi.Render.UploadMesh(quadMesh);
        }
Пример #5
0
        public OrthoRenderer(ICoreClientAPI api, IShaderProgram prog)
        {
            this.prog = prog;
            capi      = api;
            MeshData quadMesh = QuadMeshUtil.GetQuad();

            quadMesh.Rgba = null;

            quadRef = capi.Render.UploadMesh(quadMesh);
        }
        public WaypointMapComponent(int waypointIndex, Waypoint waypoint, WaypointMapLayer wpLayer, ICoreClientAPI capi) : base(capi)
        {
            this.waypointIndex = waypointIndex;
            this.waypoint      = waypoint;
            this.wpLayer       = wpLayer;

            ColorUtil.ToRGBAVec4f(waypoint.Color, ref color);

            quadModel = capi.Render.UploadMesh(QuadMeshUtil.GetQuad());
        }
Пример #7
0
        public ExampleOverlayRenderer(ICoreClientAPI capi, IShaderProgram overlayShaderProg)
        {
            this.capi = capi;
            this.overlayShaderProg = overlayShaderProg;

            MeshData quadMesh = QuadMeshUtil.GetCustomQuadModelData(-1, -1, 0, 2, 2);

            quadMesh.Rgba = null;

            quadRef = capi.Render.UploadMesh(quadMesh);
        }
        public SquintOverlayRenderer(ICoreClientAPI capi)
        {
            this.capi = capi;
            MeshData quadMesh = QuadMeshUtil.GetCustomQuadModelData(-1, -1, 0, 2, 2);

            quadMesh.Rgba = null;
            quadRef       = capi.Render.UploadMesh(quadMesh);

            LoadShader();
            capi.Event.ReloadShader += LoadShader;
            capi.Event.RegisterRenderer(this, EnumRenderStage.Ortho);
        }
Пример #9
0
        public WeirdProgressBarRenderer(ICoreClientAPI api)
        {
            this.capi = api;

            // This will get a line loop with vertices inside [-1,-1] till [1,1]
            MeshData rectangle = LineMeshUtil.GetRectangle(ColorUtil.WhiteArgb);

            whiteRectangleRef = api.Render.UploadMesh(rectangle);

            // This will get a quad with vertices inside [-1,-1] till [1,1]
            progressQuadRef = api.Render.UploadMesh(QuadMeshUtil.GetQuad());
        }
Пример #10
0
        public OrthoRenderer(ICoreClientAPI Api, IShaderProgram prog)
        {
            this.prog = prog;
            capi      = Api;

            MeshData quadMesh = QuadMeshUtil.GetCustomQuadModelData(-1, -1, 0, 2, 2);

            quadMesh.Rgba = null;

            quadRef    = capi.Render.UploadMesh(quadMesh);
            healthTree = capi.World.Player.Entity.WatchedAttributes.GetTreeAttribute("health");
        }
Пример #11
0
        public EyesOverlayRenderer(ICoreClientAPI capi, IShaderProgram eyeShaderProg)
        {
            this.capi          = capi;
            this.eyeShaderProg = eyeShaderProg;

            MeshData quadMesh = QuadMeshUtil.GetCustomQuadModelData(-1, -1, -20000 + 151 + 1, 2, 2);

            quadMesh.Rgba = null;

            quadRef = capi.Render.UploadMesh(quadMesh);

            string hotkey = capi.Input.HotKeys["sneak"].CurrentMapping.ToString();

            exitHelpTexture = capi.Gui.TextTexture.GenTextTexture(Lang.Get("bed-exithint", hotkey), CairoFont.WhiteSmallishText());
        }
Пример #12
0
        public RiftRenderer(ICoreClientAPI capi, List <Rift> rifts)
        {
            this.capi  = capi;
            this.rifts = rifts;

            capi.Event.RegisterRenderer(this, EnumRenderStage.AfterBlit, "rendertest");
            MeshData mesh = QuadMeshUtil.GetQuad();

            meshref = capi.Render.UploadMesh(mesh);
            matrixf = new Matrixf();

            capi.Event.ReloadShader += LoadShader;
            LoadShader();

            modsys = capi.ModLoader.GetModSystem <ModSystemRifts>();
        }
Пример #13
0
        public WaypointMapLayer(ICoreAPI api, IWorldMapManager mapSink) : base(api, mapSink)
        {
            if (api.Side == EnumAppSide.Server)
            {
                ICoreServerAPI sapi = api as ICoreServerAPI;
                this.sapi = sapi;

                sapi.Event.GameWorldSave += OnSaveGameGettingSaved;
                sapi.RegisterCommand("waypoint", "Put a waypoint at this location which will be visible for you on the map", "[add|addat|modify|remove|list]", OnCmdWayPoint, Privilege.chat);
                sapi.RegisterCommand("tpwp", "Teleport yourself to a waypoint starting with the supplied name", "[name]", OnCmdTpTo, Privilege.tp);
            }
            else
            {
                quadModel = (api as ICoreClientAPI).Render.UploadMesh(QuadMeshUtil.GetQuad());
            }
        }
Пример #14
0
        public ProgressBarRenderer(ICoreClientAPI capi, int shaderid)
        {
            this.capi = capi;
            var      shader   = capi.Shader.GetProgram(shaderid);
            MeshData quadMesh = QuadMeshUtil.GetQuad();

            quadMesh.Rgba = null;
            quadRef       = capi.Render.UploadMesh(quadMesh);

            if (shader.Compile())
            {
                prog = shader;
            }
            else
            {
                Dispose();
            }
        }
Пример #15
0
        public IngotMoldRenderer(BlockPos pos, ICoreClientAPI api)
        {
            this.pos = pos;
            this.api = api;

            MeshData modeldata = QuadMeshUtil.GetQuad();

            modeldata.Uv = new float[]
            {
                3 / 16f, 7 / 16f,
                0, 7 / 16f,
                0, 0,
                3 / 16f, 0
            };

            modeldata.Rgba = new byte[4 * 4];
            modeldata.Rgba.Fill((byte)255);
            modeldata.Flags = new int[4 * 4];

            quadModelRef = api.Render.UploadMesh(modeldata);
        }
Пример #16
0
        public BlockEntitySignRenderer(BlockPos pos, ICoreClientAPI api)
        {
            this.api = api;
            this.pos = pos;
            font     = new CairoFont(fontSize, GuiStyle.StandardFontName, new double[] { 0, 0, 0, 0.8 });
            font.LineHeightMultiplier = 0.9f;

            api.Event.RegisterRenderer(this, EnumRenderStage.Opaque, "sign");

            MeshData modeldata = QuadMeshUtil.GetQuad();

            modeldata.Uv = new float[]
            {
                1, 1,
                0, 1,
                0, 0,
                1, 0
            };
            modeldata.Rgba = new byte[4 * 4];
            modeldata.Rgba.Fill((byte)255);
            //modeldata.Rgba2 = null; //= new byte[4 * 4];
            //modeldata.Rgba2.Fill((byte)255);

            quadModelRef = api.Render.UploadMesh(modeldata);

            Block       block  = api.World.BlockAccessor.GetBlock(pos);
            BlockFacing facing = BlockFacing.FromCode(block.LastCodePart());

            if (facing == null)
            {
                return;
            }

            float wallOffset = block.LastCodePart(1) == "wall" ? 0.22f : 0;

            switch (facing.Index)
            {
            case 0:     // N
                translateX = 0.5f;
                translateZ = 1 - 0.71f - wallOffset;
                rotY       = 180;
                break;

            case 1:     // E
                translateX = 0.71f + wallOffset;
                translateZ = 0.5f;
                rotY       = 90;
                break;

            case 2:     // S
                translateX = 0.5f;
                translateZ = 0.71f + wallOffset;

                break;

            case 3:     // W
                translateX = 1 - 0.71f - wallOffset;
                translateZ = 0.5f;
                rotY       = 270;

                break;
            }
        }
        public void RegenMesh()
        {
            ICoreClientAPI capi = api as ICoreClientAPI;

            mesh = new MeshData(24, 36, false).WithTints().WithRenderpasses();


            float subPixelPadding = capi.BlockTextureAtlas.SubPixelPadding;

            MeshData[] meshesByFace = new MeshData[6];



            // North
            meshesByFace[0] = QuadMeshUtil.GetCustomQuad(0, 0, 0, 1 / 16f, 1 / 16f, 255, 255, 255, 255);
            meshesByFace[0].Rotate(new Vec3f(1 / 32f, 1 / 32f, 1 / 32f), 0, GameMath.PI, 0);
            meshesByFace[0].Translate(0, 0, -1 / 16f);

            // East
            meshesByFace[1] = QuadMeshUtil.GetCustomQuad(0, 0, 0, 1 / 16f, 1 / 16f, 255, 255, 255, 255);
            meshesByFace[1].Rotate(new Vec3f(1 / 32f, 1 / 32f, 1 / 32f), 0, GameMath.PIHALF, 0);
            meshesByFace[1].Translate(1 / 16f, 0, 0);

            // South
            meshesByFace[2] = QuadMeshUtil.GetCustomQuad(0, 0, 1 / 16f, 1 / 16f, 1 / 16f, 255, 255, 255, 255);

            // West
            meshesByFace[3] = QuadMeshUtil.GetCustomQuad(0, 0, 0, 1 / 16f, 1 / 16f, 255, 255, 255, 255);
            meshesByFace[3].Rotate(new Vec3f(1 / 32f, 1 / 32f, 1 / 32f), 0, -GameMath.PIHALF, 0);
            meshesByFace[3].Translate(-1 / 16f, 0, 0);

            // Up
            meshesByFace[4] = QuadMeshUtil.GetCustomQuadHorizontal(0, 1 / 16f, 0, 1 / 16f, 1 / 16f, 255, 255, 255, 255);
            meshesByFace[4].Rotate(new Vec3f(1 / 32f, 1 / 32f, 1 / 32f), GameMath.PI, 0, 0);
            meshesByFace[4].Translate(0, 1 / 16f, 0);

            // Down
            meshesByFace[5] = QuadMeshUtil.GetCustomQuadHorizontal(0, 0, 0, 1 / 16f, 1 / 16f, 255, 255, 255, 255);


            float[] sideShadings = CubeMeshUtil.DefaultBlockSideShadingsByFacing;

            for (int i = 0; i < meshesByFace.Length; i++)
            {
                MeshData mesh = meshesByFace[i];
                mesh.Rgba = new byte[16];
                mesh.Rgba.Fill((byte)(255 * sideShadings[i]));

                mesh.rgba2 = new byte[16];
                mesh.rgba2.Fill((byte)(255 * sideShadings[i]));
                mesh.Flags = new int[4];
                mesh.Flags.Fill(0);
                mesh.RenderPasses    = new int[1];
                mesh.RenderPassCount = 1;
                mesh.Tints           = new int[1];
                mesh.TintsCount      = 1;
                mesh.XyzFaces        = new int[] { i };
                mesh.XyzFacesCount   = 1;

                TextureAtlasPosition tpos = capi.BlockTextureAtlas.GetPosition(block, BlockFacing.ALLFACES[i].Code);
                for (int j = 0; j < mesh.Uv.Length; j++)
                {
                    mesh.Uv[j] = (j % 2 > 0 ? tpos.y1 : tpos.x1) + mesh.Uv[j] * 32f / capi.BlockTextureAtlas.Size - subPixelPadding;
                }
            }

            MeshData[] voxelMeshesOffset = new MeshData[6];
            for (int i = 0; i < meshesByFace.Length; i++)
            {
                voxelMeshesOffset[i] = meshesByFace[i].Clone();
            }


            // North: Negative Z
            // East: Positive X
            // South: Positive Z
            // West: Negative X

            bool[] sideVisible = new bool[6];

            int[] coords = new int[3];

            int[][] coordIndexByFace = new int[][] {
                // N
                new int[] { 0, 1 },
                // E
                new int[] { 2, 1 },
                // S
                new int[] { 0, 1 },
                // W
                new int[] { 2, 1 },
                // U
                new int[] { 0, 2 },
                // D
                new int[] { 0, 2 }
            };

            for (int x = 0; x < 16; x++)
            {
                coords[0] = x;

                for (int y = 0; y < 16; y++)
                {
                    coords[1] = y;

                    for (int z = 0; z < 16; z++)
                    {
                        if (!Voxels[x, y, z])
                        {
                            continue;
                        }

                        coords[2] = z;

                        float px = x / 16f;
                        float py = y / 16f;
                        float pz = z / 16f;

                        sideVisible[0] = z == 0 || !Voxels[x, y, z - 1];
                        sideVisible[1] = x == 15 || !Voxels[x + 1, y, z];
                        sideVisible[2] = z == 15 || !Voxels[x, y, z + 1];
                        sideVisible[3] = x == 0 || !Voxels[x - 1, y, z];
                        sideVisible[4] = y == 15 || !Voxels[x, y + 1, z];
                        sideVisible[5] = y == 0 || !Voxels[x, y - 1, z];

                        for (int f = 0; f < 6; f++)
                        {
                            if (!sideVisible[f])
                            {
                                continue;
                            }

                            MeshData facerefmesh    = meshesByFace[f];
                            MeshData faceoffsetmesh = voxelMeshesOffset[f];

                            for (int i = 0; i < facerefmesh.xyz.Length; i += 3)
                            {
                                faceoffsetmesh.xyz[i]     = px + facerefmesh.xyz[i];
                                faceoffsetmesh.xyz[i + 1] = py + facerefmesh.xyz[i + 1];
                                faceoffsetmesh.xyz[i + 2] = pz + facerefmesh.xyz[i + 2];
                            }

                            float offsetX = (coords[coordIndexByFace[f][0]] * 2f) / capi.BlockTextureAtlas.Size;
                            float offsetZ = (coords[coordIndexByFace[f][1]] * 2f) / capi.BlockTextureAtlas.Size;

                            for (int i = 0; i < facerefmesh.Uv.Length; i += 2)
                            {
                                faceoffsetmesh.Uv[i]     = facerefmesh.Uv[i] + offsetX;
                                faceoffsetmesh.Uv[i + 1] = facerefmesh.Uv[i + 1] + offsetZ;
                            }

                            mesh.AddMeshData(faceoffsetmesh);
                        }
                    }
                }
            }
        }
Пример #18
0
 public EntityMapComponent(ICoreClientAPI capi, LoadedTexture texture, Entity entity) : base(capi)
 {
     quadModel    = capi.Render.UploadMesh(QuadMeshUtil.GetQuad());
     this.Texture = texture;
     this.entity  = entity;
 }
        private void genMesh()
        {
            MeshData allMeshes = new MeshData(4, 6);

            int qsigns = 0;

            for (int i = 0; i < 8; i++)
            {
                if (textByCardinal[i].Length == 0)
                {
                    continue;
                }
                qsigns++;
            }

            if (qsigns == 0)
            {
                quadModelRef?.Dispose();
                quadModelRef = null;
                return;
            }


            int snum = 0;

            for (int i = 0; i < 8; i++)
            {
                if (textByCardinal[i].Length == 0)
                {
                    continue;
                }

                Cardinal dir = Cardinal.ALL[i];

                MeshData modeldata = QuadMeshUtil.GetQuad();

                float vStart = snum / (float)qsigns;
                float vEnd   = (snum + 1) / (float)qsigns;
                snum++;

                modeldata.Uv = new float[]
                {
                    1, vEnd,
                    0, vEnd,
                    0, vStart,
                    1, vStart
                };

                modeldata.Rgba = new byte[4 * 4];
                modeldata.Rgba.Fill((byte)255);
                //modeldata.Rgba2 = null;

                Vec3f orig = new Vec3f(0.5f, 0.5f, 0.5f);

                switch (dir.Index)
                {
                case 0:     // N
                    rotY = 90;
                    break;

                case 1:     // NE
                    rotY = 45;
                    break;

                case 2:     // E
                    rotY = 0;
                    break;

                case 3:     // SE
                    rotY = 315;
                    break;

                case 4:     // S
                    rotY = 270;
                    break;

                case 5:     // SW
                    rotY = 225;
                    break;

                case 6:     // W
                    rotY = 180;
                    break;

                case 7:     // NW
                    rotY = 135;
                    break;
                }

                modeldata.Translate(1.6f, 0, 0.375f);

                MeshData front = modeldata.Clone();

                front.Scale(orig, 0.5f * QuadWidth, 0.4f * QuadHeight, 0.5f * QuadWidth);
                front.Rotate(orig, 0, rotY * GameMath.DEG2RAD, 0);
                front.Translate(0, 1.39f, 0);
                allMeshes.AddMeshData(front);


                MeshData back = modeldata;

                back.Uv = new float[]
                {
                    0, vEnd,
                    1, vEnd,
                    1, vStart,
                    0, vStart
                };
                back.Translate(0, 0, 0.26f);
                back.Scale(orig, 0.5f * QuadWidth, 0.4f * QuadHeight, 0.5f * QuadWidth);
                back.Rotate(orig, 0, rotY * GameMath.DEG2RAD, 0);
                back.Translate(0, 1.39f, 0);
                allMeshes.AddMeshData(back);
            }

            quadModelRef?.Dispose();
            quadModelRef = api.Render.UploadMesh(allMeshes);
        }