Exemplo n.º 1
0
        public MechNetworkRenderer(ICoreClientAPI capi, MechanicalPowerMod mechanicalPowerMod)
        {
            calcs[0] = UpdateGearbox;
            calcs[1] = UpdateAxle;
            calcs[2] = UpdateWindmillRotor;

            this.mechanicalPowerMod = mechanicalPowerMod;
            this.capi = capi;

            Block block = capi.World.GetBlock(new AssetLocation("gearbox-wood"));

            if (block == null)
            {
                return;
            }

            capi.Event.RegisterRenderer(this, EnumRenderStage.Opaque);
            capi.Event.ReloadShader += LoadShader;
            LoadShader();

            MeshData gearboxCageMesh;
            MeshData gearboxPegMesh;
            MeshData axleMesh;
            MeshData windmillRotorMesh;

            capi.Tesselator.TesselateShape(block, capi.Assets.TryGet("shapes/block/wood/angledgearbox-cage.json").ToObject <Shape>(), out gearboxCageMesh);
            capi.Tesselator.TesselateShape(block, capi.Assets.TryGet("shapes/block/wood/angledgearbox-peg.json").ToObject <Shape>(), out gearboxPegMesh);
            capi.Tesselator.TesselateShape(block, capi.Assets.TryGet("shapes/block/wood/axle.json").ToObject <Shape>(), out axleMesh);
            capi.Tesselator.TesselateShape(block, capi.Assets.TryGet("shapes/block/wood/windmillrotor.json").ToObject <Shape>(), out windmillRotorMesh);

            gearboxPegMesh.Rgba2    = null;
            gearboxCageMesh.Rgba2   = null;
            axleMesh.Rgba2          = null;
            windmillRotorMesh.Rgba2 = null;


            // 16 floats matrix, 4 floats light rgbs
            gearboxPegMesh.CustomFloats = floatsPeg = new CustomMeshDataPartFloat((16 + 4) * 10100)
            {
                Instanced         = true,
                InterleaveOffsets = new int[] { 0, 16, 32, 48, 64 },
                InterleaveSizes   = new int[] { 4, 4, 4, 4, 4 },
                InterleaveStride  = 16 + 4 * 16,
                StaticDraw        = false,
            };
            gearboxPegMesh.CustomFloats.SetAllocationSize((16 + 4) * 10100);

            gearboxCageMesh.CustomFloats   = floatsCage = floatsPeg.Clone();
            axleMesh.CustomFloats          = floatsAxle = floatsPeg.Clone();
            windmillRotorMesh.CustomFloats = floatsWindmillRotor = floatsPeg.Clone();



            this.gearboxPeg    = capi.Render.UploadMesh(gearboxPegMesh);
            this.gearboxCage   = capi.Render.UploadMesh(gearboxCageMesh);
            this.axle          = capi.Render.UploadMesh(axleMesh);
            this.windmillRotor = capi.Render.UploadMesh(windmillRotorMesh);
        }
        public AngledGearsBlockRenderer(ICoreClientAPI capi, MechanicalPowerMod mechanicalPowerMod, Block textureSoureBlock, CompositeShape shapeLoc) : base(capi, mechanicalPowerMod)
        {
            Vec3f rot = new Vec3f(shapeLoc.rotateX, shapeLoc.rotateY, shapeLoc.rotateZ);

            MeshData gearboxCageMesh;
            MeshData gearboxPegMesh;

            capi.Tesselator.TesselateShape(textureSoureBlock, capi.Assets.TryGet("shapes/block/wood/mechanics/angledgearbox-cage.json").ToObject <Shape>(), out gearboxCageMesh, rot);
            capi.Tesselator.TesselateShape(textureSoureBlock, capi.Assets.TryGet("shapes/block/wood/mechanics/angledgearbox-peg.json").ToObject <Shape>(), out gearboxPegMesh, rot);


            // 16 floats matrix, 4 floats light rgbs
            gearboxPegMesh.CustomFloats = floatsPeg = new CustomMeshDataPartFloat((16 + 4) * 10100)
            {
                Instanced         = true,
                InterleaveOffsets = new int[] { 0, 16, 32, 48, 64 },
                InterleaveSizes   = new int[] { 4, 4, 4, 4, 4 },
                InterleaveStride  = 16 + 4 * 16,
                StaticDraw        = false,
            };
            gearboxPegMesh.CustomFloats.SetAllocationSize((16 + 4) * 10100);

            gearboxCageMesh.CustomFloats = floatsCage = floatsPeg.Clone();

            this.gearboxPeg  = capi.Render.UploadMesh(gearboxPegMesh);
            this.gearboxCage = capi.Render.UploadMesh(gearboxCageMesh);
        }