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());
        }
예제 #2
0
        private void RegenOutlineMesh(KnappingRecipe recipeToOutline, bool[,] Voxels)
        {
            MeshData recipeOutlineMesh = new MeshData(24, 36, false, false, true, false);

            recipeOutlineMesh.SetMode(EnumDrawMode.Lines);

            int greenCol  = (156 << 24) | (100 << 16) | (200 << 8) | (100);
            int orangeCol = (156 << 24) | (226 << 16) | (171 << 8) | (92);

            MeshData greenVoxelMesh  = LineMeshUtil.GetCube(greenCol);
            MeshData orangeVoxelMesh = LineMeshUtil.GetCube(orangeCol);

            for (int i = 0; i < greenVoxelMesh.xyz.Length; i++)
            {
                greenVoxelMesh.xyz[i]  = greenVoxelMesh.xyz[i] / 32f + 1 / 32f;
                orangeVoxelMesh.xyz[i] = orangeVoxelMesh.xyz[i] / 32f + 1 / 32f;
            }
            MeshData voxelMeshOffset = greenVoxelMesh.Clone();

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    bool shouldFill = recipeToOutline.Voxels[x, 0, z];
                    bool didFill    = Voxels[x, z];

                    if (shouldFill == didFill)
                    {
                        continue;
                    }

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

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

                    voxelMeshOffset.Rgba = (shouldFill && !didFill) ? greenVoxelMesh.Rgba : orangeVoxelMesh.Rgba;

                    recipeOutlineMesh.AddMeshData(voxelMeshOffset);
                }
            }

            recipeOutlineMeshRef?.Dispose();
            recipeOutlineMeshRef = null;
            if (recipeOutlineMesh.VerticesCount > 0)
            {
                recipeOutlineMeshRef = api.Render.UploadMesh(recipeOutlineMesh);
            }
        }
        internal void SetChildRenderer(ItemStack contentStack, IInFirepitRenderer renderer)
        {
            this.ContentStack = contentStack;
            if (meshref != null)
            {
                api.Render.DeleteMesh(meshref);
                meshref = null;
            }

            contentStackRenderer = renderer;
        }
        private void SetupFramebuffers(List <FrameBufferRef> mainBuffers)
        {
            if (_frameBuffer != null)
            {
                _platform.DisposeFrameBuffer(_frameBuffer);
                _frameBuffer = null;
            }

            var ssao = ClientSettings.SSAOQuality > 0;

            if (!ssao || !_enabled)
            {
                return;
            }

            var fbPrimary = mainBuffers[(int)EnumFrameBuffer.Primary];

            var fbWidth  = (int)(_platform.window.Width * ClientSettings.SSAA);
            var fbHeight = (int)(_platform.window.Height * ClientSettings.SSAA);

            if (fbWidth == 0 || fbHeight == 0)
            {
                return;
            }

            var fb = new FrameBufferRef
            {
                FboId           = GL.GenFramebuffer(),
                Width           = fbWidth,
                Height          = fbHeight,
                ColorTextureIds = ArrayUtil.CreateFilled(2, _ => GL.GenTexture())
            };

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, fb.FboId);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment,
                                    TextureTarget.Texture2D, fbPrimary.DepthTextureId, 0);
            fb.SetupColorTexture(0);
            fb.SetupColorTexture(1);

            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment2,
                                    TextureTarget.Texture2D, fbPrimary.ColorTextureIds[2], 0);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment3,
                                    TextureTarget.Texture2D, fbPrimary.ColorTextureIds[3], 0);
            GL.DrawBuffers(4, new []
            {
                DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1,
                DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3
            });

            Framebuffers.CheckStatus();
            _frameBuffer = fb;

            _screenQuad = _platform.GetScreenQuad();
        }
예제 #5
0
 public PestleRenderer(ICoreClientAPI coreClientAPI, BlockPos Pos, MeshData mesh)
 {
     Api      = coreClientAPI;
     this.Pos = Pos;
     if (mesh == null)
     {
         return;
     }
     meshref    = coreClientAPI.Render.UploadMesh(mesh);
     CrushSound = Api.World.BlockAccessor.GetBlock(new AssetLocation("game:gravel-andesite")).Sounds.Break;
 }
예제 #6
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);
        }
예제 #7
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());
        }
예제 #8
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");
        }
        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);
        }
예제 #10
0
        public void InitQuads()
        {
            quadTilesRef?.Dispose();
            float height = 200;

            MeshData mesh = new MeshData(4, 6, false, true, true, false);
            float    x = 0, y = 0, z = 0;
            Random   rnd = new Random();

            for (int i = 0; i < 15; i++)
            {
                Vec3f dir = new Vec3f((float)rnd.NextDouble() * 20 - 10, (float)rnd.NextDouble() * 5 - 3, (float)rnd.NextDouble() * 20 - 10);
                dir.Normalize();
                x = (float)rnd.NextDouble() * 800 - 400;
                y = (float)rnd.NextDouble() * 80 - 40;
                z = (float)rnd.NextDouble() * 800 - 400;


                for (int j = 0; j < 100; j++)
                {
                    float lngx = (float)rnd.NextDouble() * 5 + 20;
                    float lngy = (float)rnd.NextDouble() * 4 + 4;
                    float lngz = (float)rnd.NextDouble() * 5 + 20;

                    x += dir.X * lngx;
                    y += dir.Y * lngy;
                    z += dir.Z * lngz;

                    //float width = 20 + (float)rnd.NextDouble() * 5;

                    //MeshData quad = QuadMeshUtil.GetCustomQuad(z, 20, x, x - prevx, height, 255, 255, 255, 255);
                    //mesh.AddMeshData(quad);

                    int lastelement = mesh.VerticesCount;

                    mesh.AddVertex(x, y + height, z, j % 2, 1);
                    mesh.AddVertex(x, y, z, j % 2, 0);

                    if (j > 0 && j < 19)
                    {
                        mesh.AddIndex(lastelement + 0);
                        mesh.AddIndex(lastelement + 1);
                        mesh.AddIndex(lastelement + 2);
                        mesh.AddIndex(lastelement + 1);
                        mesh.AddIndex(lastelement + 3);
                        mesh.AddIndex(lastelement + 2);
                    }
                }
            }

            quadTilesRef = capi.Render.UploadMesh(mesh);
        }
예제 #11
0
 public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
 {
     base.OnBeforeRender(capi, itemstack, target, ref renderinfo);
     if (itemstack.Attributes.GetOrAddTreeAttribute("toolparts").Count > 0)
     {
         MeshRef meshRef = MeshManager.GetMesh(api.World as ClientMain, itemstack);
         System.Console.WriteLine("MeshRef exists: {0}", meshRef != null);
         if (meshRef != null)
         {
             renderinfo.ModelRef = meshRef;
         }
     }
 }
예제 #12
0
        public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
        {
            if (meshCache == null)
            {
                meshCache = capi.ModLoader.GetModSystem <MealMeshCache>();
            }

            MeshRef meshref = meshCache.GetOrCreateMealInContainerMeshRef(this, GetCookingRecipe(capi.World, itemstack), GetNonEmptyContents(capi.World, itemstack));

            if (meshref != null)
            {
                renderinfo.ModelRef = meshref;
            }
        }
        public TransmissionBlockRenderer(ICoreClientAPI capi, MechanicalPowerMod mechanicalPowerMod, Block textureSoureBlock, CompositeShape shapeLoc) : base(capi, mechanicalPowerMod)
        {
            MeshData blockMesh1;
            MeshData blockMesh2 = null;

            AssetLocation loc = shapeLoc.Base.Clone().WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json");

            Shape shape = capi.Assets.TryGet(loc).ToObject <Shape>();
            Vec3f rot   = new Vec3f(shapeLoc.rotateX, shapeLoc.rotateY, shapeLoc.rotateZ);

            capi.Tesselator.TesselateShape(textureSoureBlock, shape, out blockMesh1, rot);

            CompositeShape ovShapeCmp = new CompositeShape()
            {
                Base = new AssetLocation("shapes/block/wood/mechanics/transmission-rightgear.json")
            };

            //rot = new Vec3f(ovShapeCmp.rotateX, ovShapeCmp.rotateY, ovShapeCmp.rotateZ);
            rot = new Vec3f(shapeLoc.rotateX, shapeLoc.rotateY, shapeLoc.rotateZ);
            Shape ovshape = capi.Assets.TryGet(ovShapeCmp.Base.Clone().WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json")).ToObject <Shape>();

            capi.Tesselator.TesselateShape(textureSoureBlock, ovshape, out blockMesh2, rot);

            //blockMesh1.Rgba2 = null;
            //blockMesh2.Rgba2 = null;

            // 16 floats matrix, 4 floats light rgbs
            blockMesh1.CustomFloats = matrixAndLightFloats1 = 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,
            };
            blockMesh1.CustomFloats.SetAllocationSize((16 + 4) * 10100);
            blockMesh2.CustomFloats = matrixAndLightFloats2 = 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,
            };
            blockMesh2.CustomFloats.SetAllocationSize((16 + 4) * 10100);

            this.blockMeshRef1 = capi.Render.UploadMesh(blockMesh1);
            this.blockMeshRef2 = capi.Render.UploadMesh(blockMesh2);
        }
예제 #14
0
        public FallingTreeRenderer(ICoreClientAPI capi, BlockPos pos, bool isLeaves, MeshData treeMesh, float fallTime, BlockFacing fallDirection, EnumRenderStage pass)
        {
            if (pos == null || treeMesh == null)
            {
                return;
            }

            this.capi          = capi;
            this.pos           = pos;
            this.treeMesh      = capi.Render.UploadMesh(treeMesh);
            this.fallDirection = fallDirection;
            this.isLeaves      = isLeaves;
            startFallTime      = this.fallTime = fallTime;
            capi.Event.RegisterRenderer(this, pass);
        }
예제 #15
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());
        }
예제 #16
0
        public override void Dispose()
        {
            if (meshRefOpaque != null)
            {
                meshRefOpaque.Dispose();
                meshRefOpaque = null;
            }

            if (meshRefOit != null)
            {
                meshRefOit.Dispose();
                meshRefOit = null;
            }

            if (nameTagTexture != null)
            {
                nameTagTexture.Dispose();
                nameTagTexture = null;
            }

            if (debugTagTexture != null)
            {
                debugTagTexture.Dispose();
                debugTagTexture = null;
            }

            capi.Event.ReloadShapes -= TesselateShape;

            if (DisplayChatMessages)
            {
                capi.Event.ChatMessage -= OnChatMessage;
            }


            if (eagent?.GearInventory != null)
            {
                eagent.GearInventory.SlotModified -= gearSlotModified;
            }

            if (entity is EntityPlayer eplr)
            {
                IInventory inv = eplr.Player?.InventoryManager.GetOwnInventory(GlobalConstants.backpackInvClassName);
                if (inv != null)
                {
                    inv.SlotModified -= backPackSlotModified;
                }
            }
        }
예제 #17
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());
            }
        }
예제 #18
0
파일: Door.cs 프로젝트: Nylash/LD47
 protected override void EditorUpdate()
 {
     if (WallToConvertToDoor != PreviousDirection)
     {
         if (MeshRef)
         {
             MeshRef.sharedMaterial = GetOwner().WallDefaultMaterial;
             MeshRef.GetComponent <MeshFilter>().sharedMesh = GetOwner().WallModel.GetComponentInChildren <MeshFilter>().sharedMesh;
             MeshRef.gameObject.tag = "Untagged";
             Destroy(frameLeftRef);
             Destroy(frameRightRef);
         }
         EditorStart();
     }
     LanternMaterialHandler();
 }
예제 #19
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>();
        }
예제 #20
0
        public BEAnimatableRenderer(ICoreClientAPI capi, BlockPos pos, Vec3f rotation, AnimatorBase animator, Dictionary <string, AnimationMetaData> activeAnimationsByAnimCode, MeshRef meshref)
        {
            this.pos      = pos;
            this.capi     = capi;
            this.animator = animator;
            this.activeAnimationsByAnimCode = activeAnimationsByAnimCode;
            this.meshref  = meshref;
            this.rotation = rotation;
            if (rotation == null)
            {
                rotation = new Vec3f();
            }

            textureId = capi.BlockTextureAtlas.GetPosition(capi.World.BlockAccessor.GetBlock(pos), "rusty").atlasTextureId;

            capi.Event.RegisterRenderer(this, EnumRenderStage.Opaque, "beanimatable");
        }
        internal void UpdateMeshes(MeshData needleMesh, MeshData discMesh)
        {
            Dispose();
            needleMeshRef = null;
            discMeshRef   = null;

            if (needleMesh != null)
            {
                needleMeshRef = api.Render.UploadMesh(needleMesh);
            }
            if (discMesh != null)
            {
                discMeshRef = api.Render.UploadMesh(discMesh);
            }

            updatedTotalMs = api.World.ElapsedMilliseconds;
        }
예제 #22
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();
            }
        }
예제 #23
0
        public CreativeRotorRenderer(ICoreClientAPI capi, MechanicalPowerMod mechanicalPowerMod, Block textureSoureBlock, CompositeShape shapeLoc) : base(capi, mechanicalPowerMod)
        {
            MeshData blockMesh1;
            MeshData blockMesh2 = null;
            MeshData blockMesh3 = null;
            MeshData blockMesh4 = null;

            AssetLocation loc = new AssetLocation("shapes/block/metal/mechanics/creativerotor-axle.json");

            Shape shape = capi.Assets.TryGet(loc).ToObject <Shape>();
            Vec3f rot   = new Vec3f(shapeLoc.rotateX, shapeLoc.rotateY, shapeLoc.rotateZ);

            capi.Tesselator.TesselateShape(textureSoureBlock, shape, out blockMesh1, rot);

            rot = new Vec3f(shapeLoc.rotateX, shapeLoc.rotateY, shapeLoc.rotateZ);
            Shape ovshape = capi.Assets.TryGet(new AssetLocation("shapes/block/metal/mechanics/creativerotor-contra.json")).ToObject <Shape>();

            capi.Tesselator.TesselateShape(textureSoureBlock, ovshape, out blockMesh2, rot);
            Shape ovshape2 = capi.Assets.TryGet(new AssetLocation("shapes/block/metal/mechanics/creativerotor-spinbar.json")).ToObject <Shape>();

            capi.Tesselator.TesselateShape(textureSoureBlock, ovshape2, out blockMesh3, rot);
            Shape ovshape3 = capi.Assets.TryGet(new AssetLocation("shapes/block/metal/mechanics/creativerotor-spinball.json")).ToObject <Shape>();

            capi.Tesselator.TesselateShape(textureSoureBlock, ovshape3, out blockMesh4, rot);

            //blockMesh1.Rgba2 = null;
            //blockMesh2.Rgba2 = null;
            //blockMesh3.Rgba2 = null;
            //blockMesh4.Rgba2 = null;

            int count = (16 + 4) * 2100;

            // 16 floats matrix, 4 floats light rgbs
            blockMesh1.CustomFloats = matrixAndLightFloats1 = createCustomFloats(count);
            blockMesh2.CustomFloats = matrixAndLightFloats2 = createCustomFloats(count);
            blockMesh3.CustomFloats = matrixAndLightFloats3 = createCustomFloats(count);
            blockMesh4.CustomFloats = matrixAndLightFloats4 = createCustomFloats(count);
            matrixAndLightFloats5   = createCustomFloats(count);

            this.blockMeshRef1 = capi.Render.UploadMesh(blockMesh1);
            this.blockMeshRef2 = capi.Render.UploadMesh(blockMesh2);
            this.blockMeshRef3 = capi.Render.UploadMesh(blockMesh3);
            this.blockMeshRef4 = capi.Render.UploadMesh(blockMesh4);
        }
예제 #24
0
파일: Door.cs 프로젝트: Nylash/LD47
    protected override void EditorStart()
    {
        ObjectRef = GetObjectRef();
        if (ObjectRef)
        {
            MeshRef = ObjectRef.GetComponentInChildren <MeshRenderer>();
        }

        PreviousDirection = WallToConvertToDoor;

        if (MeshRef)
        {
            MeshRef.gameObject.tag = "Door";
            MeshRef.GetComponent <MeshFilter>().mesh = GetOwner().DoorModel;

            SpawnFrames();
            LanternMaterialHandler();
        }
    }
예제 #25
0
        private void RegenOutlineMesh(SmithingRecipe recipeToOutline)
        {
            recipeOutlineMeshRef?.Dispose();

            MeshData recipeOutlineMesh = new MeshData(24, 36, false, false, true, false, false);

            recipeOutlineMesh.SetMode(EnumDrawMode.Lines);

            MeshData voxelMesh = LineMeshUtil.GetCube((180 << 24) | (100 << 16) | (200 << 8) | (200));

            for (int i = 0; i < voxelMesh.xyz.Length; i++)
            {
                voxelMesh.xyz[i] = voxelMesh.xyz[i] / 32f + 1 / 32f;
            }
            MeshData voxelMeshOffset = voxelMesh.Clone();

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

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

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

                    recipeOutlineMesh.AddMeshData(voxelMeshOffset);
                }
            }

            recipeOutlineMeshRef = api.Render.UploadMesh(recipeOutlineMesh);
        }
예제 #26
0
        public PulverizerRenderer(ICoreClientAPI capi, MechanicalPowerMod mechanicalPowerMod, Block textureSoureBlock, CompositeShape shapeLoc) : base(capi, mechanicalPowerMod)
        {
            MeshData toggleMesh, lPounderMesh, rPounderMesh;

            // 16 floats matrix, 4 floats light rgbs
            int count = (16 + 4) * 200;


            AssetLocation loc   = new AssetLocation("shapes/block/wood/mechanics/pulverizer-moving.json");
            Shape         shape = capi.Assets.TryGet(loc).ToObject <Shape>();
            Vec3f         rot   = new Vec3f(shapeLoc.rotateX, shapeLoc.rotateY + 90F, shapeLoc.rotateZ);

            capi.Tesselator.TesselateShape(textureSoureBlock, shape, out toggleMesh, rot);
            toggleMesh.CustomFloats = matrixAndLightFloatsAxle = createCustomFloats(count);
            toggleMeshref           = capi.Render.UploadMesh(toggleMesh);


            AssetLocation locPounderL = new AssetLocation("shapes/block/wood/mechanics/pulverizer-pounder-l.json");
            AssetLocation locPounderR = new AssetLocation("shapes/block/wood/mechanics/pulverizer-pounder-r.json");

            Shape shapel = capi.Assets.TryGet(locPounderL).ToObject <Shape>();
            Shape shaper = capi.Assets.TryGet(locPounderR).ToObject <Shape>();

            texSource = capi.Tesselator.GetTexSource(textureSoureBlock);



            for (int i = 0; i < metals.Length; i++)
            {
                metal = metals[i];

                matrixAndLightFloatsLPounder[i] = createCustomFloats(count);
                matrixAndLightFloatsRPounder[i] = createCustomFloats(count);

                capi.Tesselator.TesselateShape("pulverizer-pounder-l", shapel, out lPounderMesh, this, rot);
                capi.Tesselator.TesselateShape("pulverizer-pounder-r", shaper, out rPounderMesh, this, rot);
                lPounderMesh.CustomFloats = matrixAndLightFloatsLPounder[i];
                rPounderMesh.CustomFloats = matrixAndLightFloatsRPounder[i];
                lPoundMeshrefs[i]         = capi.Render.UploadMesh(lPounderMesh);
                rPounderMeshrefs[i]       = capi.Render.UploadMesh(rPounderMesh);
            }
        }
예제 #27
0
        public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
        {
            if (meshCache == null)
            {
                meshCache = capi.ModLoader.GetModSystem <MealMeshCache>();
            }

            CookingRecipe recipe = GetCookingRecipe(capi.World, itemstack);

            ItemStack[] contents = GetContents(capi.World, itemstack);

            float yoff = 2.5f; // itemstack.Attributes.GetInt("servings");

            MeshRef meshref = meshCache.GetOrCreateMealMeshRef(this.Shape, recipe, contents, new Vec3f(0, yoff / 16f, 0));

            if (meshref != null)
            {
                renderinfo.ModelRef = meshref;
            }
        }
예제 #28
0
        public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
        {
            if (Code.Path.Contains("clay"))
            {
                return;
            }
            Dictionary <string, MeshRef> meshrefs = null;

            object obj;

            if (capi.ObjectCache.TryGetValue(meshRefsCacheKey, out obj))
            {
                meshrefs = obj as Dictionary <string, MeshRef>;
            }
            else
            {
                capi.ObjectCache[meshRefsCacheKey] = meshrefs = new Dictionary <string, MeshRef>();
            }

            ItemStack contentStack = GetContent(itemstack);

            if (contentStack == null)
            {
                return;
            }

            MeshRef meshRef = null;

            if (!meshrefs.TryGetValue(contentStack.Collectible.Code.Path + Code.Path + contentStack.StackSize, out meshRef))
            {
                MeshData meshdata = GenMesh(capi, contentStack);
                if (meshdata == null)
                {
                    return;
                }

                meshrefs[contentStack.Collectible.Code.Path + Code.Path + contentStack.StackSize] = meshRef = capi.Render.UploadMesh(meshdata);
            }

            renderinfo.ModelRef = meshRef;
        }
        public MeshRef GetOrCreateMeshRef(ItemStack forStack)
        {
            long meshid = forStack.Attributes.GetLong("meshId", 0);


            if (!cachedModels.ContainsKey(meshid))
            {
                MeshRef meshref = CreateModel(forStack);
                forStack.Attributes.SetLong("meshId", nextMeshId);
                cachedModels[nextMeshId++] = new CachedModel()
                {
                    MeshRef = meshref, Age = 0
                };
                return(meshref);
            }
            else
            {
                cachedModels[meshid].Age = 0;
                return(cachedModels[meshid].MeshRef);
            }
        }
예제 #30
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);
        }