Esempio n. 1
0
        public void InitializeAnimator(string cacheDictKey, Vec3f rotation = null, Shape shape = null)
        {
            if (api.Side != EnumAppSide.Client)
            {
                throw new NotImplementedException("Server side animation system not implemented yet.");
            }

            ICoreClientAPI capi = api as ICoreClientAPI;

            Block block = api.World.BlockAccessor.GetBlock(be.Pos);

            ITexPositionSource texSource = capi.Tesselator.GetTexSource(block);
            MeshData           meshdata;

            if (shape == null)
            {
                IAsset asset = api.Assets.TryGet(block.Shape.Base.Clone().WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json"));
                shape = asset.ToObject <Shape>();
            }

            shape.ResolveReferences(api.World.Logger, cacheDictKey);
            BlockEntityAnimationUtil.CacheInvTransforms(shape.Elements);
            shape.ResolveAndLoadJoints();

            capi.Tesselator.TesselateShapeWithJointIds("entity", shape, out meshdata, texSource, null, block.Shape.QuantityElements, block.Shape.SelectiveElements);

            //meshdata.Rgba2 = null;

            InitializeAnimator(cacheDictKey, rotation, shape, capi.Render.UploadMesh(meshdata));
        }
Esempio n. 2
0
        public override void GetDecal(IWorldAccessor world, BlockPos pos, ITexPositionSource decalTexSource, ref MeshData decalModelData, ref MeshData blockModelData)
        {
            BlockEntityGenericTypedContainer be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityGenericTypedContainer;

            if (be != null)
            {
                ICoreClientAPI capi      = api as ICoreClientAPI;
                string         shapename = this.Attributes["shape"][be.type].AsString();
                if (shapename == null)
                {
                    base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
                    return;
                }

                blockModelData = GenMesh(capi, be.type, shapename);

                AssetLocation shapeloc = new AssetLocation(shapename).WithPathPrefix("shapes/");
                Shape         shape    = capi.Assets.TryGet(shapeloc + ".json")?.ToObject <Shape>();
                if (shape == null)
                {
                    shape = capi.Assets.TryGet(shapeloc + "1.json").ToObject <Shape>();
                }

                MeshData md;
                capi.Tesselator.TesselateShape("typedcontainer-decal", shape, out md, decalTexSource);
                decalModelData = md;

                decalModelData.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), 0, be.MeshAngle, 0);

                return;
            }

            base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
        }
Esempio n. 3
0
        Dictionary <AssetLocation, MeshData[]> GenMeshes()
        {
            Dictionary <AssetLocation, MeshData[]> meshesByType = new Dictionary <AssetLocation, MeshData[]>();

            tmpBlock         = Api.World.BlockAccessor.GetBlock(Pos);
            tmpTextureSource = ((ICoreClientAPI)Api).Tesselator.GetTexSource(tmpBlock);
            Shape         shape  = Api.Assets.TryGet("shapes/block/metal/platepile.json").ToObject <Shape>();
            MetalProperty metals = Api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();

            for (int i = 0; i < metals.Variants.Length; i++)
            {
                ITesselatorAPI mesher = ((ICoreClientAPI)Api).Tesselator;
                MeshData[]     meshes = new MeshData[17];

                tmpMetal = metals.Variants[i].Code;

                for (int j = 0; j <= 16; j++)
                {
                    mesher.TesselateShape("platePile", shape, out meshes[j], this, null, 0, 0, 0, j);
                }

                meshesByType[tmpMetal] = meshes;
            }

            tmpTextureSource = null;
            tmpMetal         = null;
            tmpBlock         = null;

            return(meshesByType);
        }
Esempio n. 4
0
        public Shape GetShape(ICoreClientAPI capi, string type, string shapename, ITesselatorAPI tesselator = null, int altTexNumber = 0)
        {
            if (shapename == null)
            {
                return(null);
            }
            if (tesselator == null)
            {
                tesselator = capi.Tesselator;
            }

            tmpTextureSource = tesselator.GetTexSource(this, altTexNumber);

            AssetLocation shapeloc = AssetLocation.Create(shapename, Code.Domain).WithPathPrefix("shapes/");
            Shape         shape    = capi.Assets.TryGet(shapeloc + ".json")?.ToObject <Shape>();

            if (shape == null)
            {
                shape = capi.Assets.TryGet(shapeloc + "1.json")?.ToObject <Shape>();
            }

            curType = type;

            return(shape);
        }
Esempio n. 5
0
        public MealTextureSource(ICoreClientAPI capi, Block textureSourceBlock)
        {
            this.capi = capi;

            this.textureSourceBlock = textureSourceBlock;

            blockTextureSource = capi.Tesselator.GetTexSource(textureSourceBlock);
        }
Esempio n. 6
0
        public void GetDecalMesh(ITexPositionSource decalTexSource, out MeshData meshdata)
        {
            int size = Layers * 2;

            Shape shape = capi.TesselatorManager.GetCachedShape(new AssetLocation("block/basic/layers/" + GameMath.Clamp(size, 2, 16) + "voxel"));

            capi.Tesselator.TesselateShape("coalpile", shape, out meshdata, decalTexSource);
        }
Esempio n. 7
0
        internal void EnsureMeshExists()
        {
            if (meshesByType == null)
            {
                meshesByType = new Dictionary <AssetLocation, MeshData[]>();
            }
            if (MetalType == null || meshesByType.ContainsKey(new AssetLocation(MetalType)))
            {
                return;
            }
            if (Api.Side != EnumAppSide.Client)
            {
                return;
            }

            tmpBlock         = Api.World.BlockAccessor.GetBlock(Pos);
            tmpTextureSource = ((ICoreClientAPI)Api).Tesselator.GetTexSource(tmpBlock);
            string        path   = Block.Attributes["pileshapes"]?["*"]?.AsString("shapes/block/metal/ingotpile.json");
            MetalProperty metals = Api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();
            List <MetalPropertyVariant> variants = metals.Variants.ToList();
            var a = Api.Assets.TryGet("config/immersionproperties/customingots.json")?.ToObject <List <MetalPropertyVariant> >();

            if (a != null)
            {
                variants.AddRange(a);
            }

            metals.Variants = variants.ToArray();

            for (int i = 0; i < metals.Variants.Length; i++)
            {
                if (!metals.Variants[i].Code.Path.Equals(MetalType))
                {
                    continue;
                }

                ITesselatorAPI mesher = ((ICoreClientAPI)Api).Tesselator;
                MeshData[]     meshes = new MeshData[65];

                tmpMetal = metals.Variants[i].Code;
                if (tmpMetal != null)
                {
                    path = Block.Attributes["pileshapes"]?[tmpMetal.Path]?.AsString(path);
                }
                Shape shape = Api.Assets.TryGet(path + ".json").ToObject <Shape>();

                for (int j = 0; j <= 64; j++)
                {
                    mesher.TesselateShape("ingotPile", shape, out meshes[j], this, null, 0, 0, j);
                }

                meshesByType[tmpMetal] = meshes;
            }

            tmpTextureSource = null;
            tmpMetal         = null;
            tmpBlock         = null;
        }
Esempio n. 8
0
        public override void GetDecal(IWorldAccessor world, BlockPos pos, ITexPositionSource decalTexSource, ref MeshData decalModelData, ref MeshData blockModelData)
        {
            BlockEntityCoalPile bea = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            if (bea == null)
            {
                base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
                return;
            }

            decalModelData.Clear();
            bea.GetDecalMesh(decalTexSource, out decalModelData);
        }
Esempio n. 9
0
        public override void GetDecal(IWorldAccessor world, BlockPos pos, ITexPositionSource decalTexSource, ref MeshData decalModelData, ref MeshData blockModelData)
        {
            BlockEntityMicroBlock be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityMicroBlock;

            if (be != null)
            {
                blockModelData = be.Mesh;
                decalModelData = be.CreateDecalMesh(decalTexSource);
                return;
            }

            base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
        }
Esempio n. 10
0
        private void GenMeshes()
        {
            meshesByQuantity = new MeshData[2];

            ITexPositionSource tmpTextureSource = ((ICoreClientAPI)api).Tesselator.GetTexSource(block);
            ITesselatorAPI     mesher           = ((ICoreClientAPI)api).Tesselator;

            Shape shape = api.Assets.TryGet("shapes/block/clay/mold/ingot-1middle.json").ToObject <Shape>();

            mesher.TesselateShape("ingotPile", shape, out meshesByQuantity[0], tmpTextureSource);

            shape = api.Assets.TryGet("shapes/block/clay/mold/ingot-2.json").ToObject <Shape>();
            mesher.TesselateShape("ingotPile", shape, out meshesByQuantity[1], tmpTextureSource);
        }
Esempio n. 11
0
        public static ITexPositionSource getContentTexture(ICoreClientAPI capi, ItemStack stack, out float fillHeight)
        {
            ITexPositionSource contentSource = null;

            fillHeight = 0;

            JsonObject obj = stack?.ItemAttributes?["inContainerTexture"];

            if (obj != null && obj.Exists)
            {
                contentSource = new ContainerTextureSource(capi, stack, obj.AsObject <CompositeTexture>());
                fillHeight    = GameMath.Min(10 / 16f, 0.7f * stack.StackSize / stack.Collectible.MaxStackSize);
            }
            else
            {
                if (stack?.Block != null && (stack.Block.DrawType == EnumDrawType.Cube || stack.Block.Shape.Base.Path.Contains("basic/cube")) && capi.BlockTextureAtlas.GetPosition(stack.Block, "up", true) != null)
                {
                    contentSource = new BlockTopTextureSource(capi, stack.Block);
                    fillHeight    = GameMath.Min(10 / 16f, 0.7f * stack.StackSize / stack.Collectible.MaxStackSize);
                }
                else if (stack != null)
                {
                    if (stack.Class == EnumItemClass.Block)
                    {
                        if (stack.Block.Textures.Count > 1)
                        {
                            return(null);
                        }

                        contentSource = new ContainerTextureSource(capi, stack, stack.Block.Textures.FirstOrDefault().Value);
                    }
                    else
                    {
                        if (stack.Item.Textures.Count > 1)
                        {
                            return(null);
                        }

                        contentSource = new ContainerTextureSource(capi, stack, stack.Item.FirstTexture);
                    }


                    fillHeight = GameMath.Min(10 / 16f, 0.7f * stack.StackSize / stack.Collectible.MaxStackSize);
                }
            }

            return(contentSource);
        }
Esempio n. 12
0
        public override void GetDecal(IWorldAccessor world, BlockPos pos, ITexPositionSource decalTexSource, ref MeshData decalModelData, ref MeshData blockModelData)
        {
            BlockEntityChisel be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityChisel;

            if (be != null)
            {
                ICoreClientAPI capi = api as ICoreClientAPI;

                blockModelData = be.Mesh;
                decalModelData = be.CreateDecalMesh(decalTexSource);

                return;
            }

            base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
        }
Esempio n. 13
0
        public Shape GetShape(ICoreClientAPI capi, string type, CompositeShape cshape)
        {
            if (cshape?.Base == null)
            {
                return(null);
            }
            var tesselator = capi.Tesselator;

            tmpTextureSource = tesselator.GetTexSource(this, 0, true);

            AssetLocation shapeloc = cshape.Base.WithPathAppendixOnce(".json").WithPathPrefixOnce("shapes/");
            Shape         shape    = capi.Assets.TryGet(shapeloc)?.ToObject <Shape>();

            curType = type;
            return(shape);
        }
Esempio n. 14
0
        public MeshData GenMesh(ICoreClientAPI capi, string material, string lining, Shape shape = null)
        {
            tmpTextureSource = capi.Tesselator.GetTexSource(this);

            if (shape == null)
            {
                shape = capi.Assets.TryGet("shapes/" + this.Shape.Base.Path + ".json").ToObject <Shape>();
            }

            this.AtlasSize = capi.BlockTextureAtlas.Size;
            curMat         = material;
            curLining      = lining;
            MeshData mesh;

            capi.Tesselator.TesselateShape("blocklantern", shape, out mesh, this, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ));
            return(mesh);
        }
Esempio n. 15
0
        public MeshData GenMesh(ItemStack itemstack, ITextureAtlasAPI targetAtlas, BlockPos forBlockPos = null)
        {
            var capi = api as ICoreClientAPI;

            if (targetAtlas == capi.ItemTextureAtlas)
            {
                ITexPositionSource texSource = capi.Tesselator.GetTextureSource(itemstack.Item);
                return(genMesh(capi, itemstack, texSource));
            }


            curAtlas = targetAtlas;
            MeshData mesh = genMesh(api as ICoreClientAPI, itemstack, this);

            mesh.RenderPassesAndExtraBits.Fill((short)EnumChunkRenderPass.OpaqueNoCull);
            return(mesh);
        }
        public override void GetDecal(IWorldAccessor world, BlockPos pos, ITexPositionSource decalTexSource, ref MeshData decalModelData, ref MeshData blockModelData)
        {
            BlockEntityGenericTypedContainer be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityGenericTypedContainer;

            if (be != null)
            {
                ICoreClientAPI capi      = api as ICoreClientAPI;
                string         shapename = this.Attributes["shape"][be.type].AsString();
                blockModelData = GenMesh(capi, be.type, shapename);

                AssetLocation shapeloc = new AssetLocation(shapename).WithPathPrefix("shapes/");
                Shape         shape    = capi.Assets.TryGet(shapeloc + ".json")?.ToObject <Shape>();
                if (shape == null)
                {
                    shape = capi.Assets.TryGet(shapeloc + "1.json").ToObject <Shape>();
                }

                MeshData md;
                capi.Tesselator.TesselateShape("typedcontainer-decal", shape, out md, decalTexSource, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ));
                decalModelData = md;

                string facing = LastCodePart();
                if (facing == "north")
                {
                    decalModelData.Rotate(new API.MathTools.Vec3f(0.5f, 0.5f, 0.5f), 0, 1 * GameMath.PIHALF, 0);
                }
                if (facing == "east")
                {
                    decalModelData.Rotate(new API.MathTools.Vec3f(0.5f, 0.5f, 0.5f), 0, 0 * GameMath.PIHALF, 0);
                }
                if (facing == "south")
                {
                    decalModelData.Rotate(new API.MathTools.Vec3f(0.5f, 0.5f, 0.5f), 0, 3 * GameMath.PIHALF, 0);
                }
                if (facing == "west")
                {
                    decalModelData.Rotate(new API.MathTools.Vec3f(0.5f, 0.5f, 0.5f), 0, 2 * GameMath.PIHALF, 0);
                }


                return;
            }

            base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
        }
Esempio n. 17
0
        internal MeshData GenMesh()
        {
            if (Block == null || contentCode == "")
            {
                return(null);
            }
            ContentConfig config = contentConfigs.FirstOrDefault(c => c.Code == contentCode);

            if (config == null)
            {
                return(null);
            }

            ICoreClientAPI capi = Api as ICoreClientAPI;

            ItemStack firstStack = inventory[0].Itemstack;

            if (firstStack == null)
            {
                return(null);
            }

            int    fillLevel = Math.Max(0, firstStack.StackSize / config.QuantityPerFillLevel - 1);
            string shapeLoc  = config.ShapesPerFillLevel[Math.Min(config.ShapesPerFillLevel.Length - 1, fillLevel)];

            Vec3f    rotation = new Vec3f(Block.Shape.rotateX, Block.Shape.rotateY, Block.Shape.rotateZ);
            MeshData meshbase;
            MeshData meshadd;

            blockTexPosSource = capi.Tesselator.GetTexSource(Block);
            capi.Tesselator.TesselateShape("betrough", Api.Assets.TryGet("shapes/" + shapeLoc + ".json").ToObject <Shape>(), out meshbase, this, rotation);

            BlockTroughDoubleBlock doubleblock = Block as BlockTroughDoubleBlock;

            if (doubleblock != null)
            {
                // Load only contents and flip 180 degrees
                capi.Tesselator.TesselateShape("betroughcontents", Api.Assets.TryGet("shapes/" + shapeLoc + ".json").ToObject <Shape>(), out meshadd, this, rotation.Add(0, 180, 0), 0, 0, 0, null, new string[] { "Origin point/contents/*" });
                BlockFacing facing = doubleblock.OtherPartPos();
                meshadd.Translate(facing.Normalf);
                meshbase.AddMeshData(meshadd);
            }

            return(meshbase);
        }
Esempio n. 18
0
        public override void GetDecal(IWorldAccessor world, BlockPos pos, ITexPositionSource decalTexSource, ref MeshData decalModelData, ref MeshData blockModelData)
        {
            var      capi = api as ICoreClientAPI;
            BECheese bec  = world.BlockAccessor.GetBlockEntity(pos) as BECheese;

            if (bec != null)
            {
                var shape = capi.TesselatorManager.GetCachedShape(bec.Inventory[0].Itemstack.Item.Shape.Base);

                capi.Tesselator.TesselateShape(this, shape, out blockModelData);
                blockModelData.Scale(new Vec3f(0.5f, 0, 0.5f), 0.75f, 0.75f, 0.75f);

                capi.Tesselator.TesselateShape("cheese decal", shape, out decalModelData, decalTexSource);
                decalModelData.Scale(new Vec3f(0.5f, 0, 0.5f), 0.75f, 0.75f, 0.75f);
            }

            base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
        }
Esempio n. 19
0
        internal void EnsureMeshExists()
        {
            if (meshesByType == null)
            {
                meshesByType = new Dictionary <string, MeshData[]>();
            }
            if (MetalType == null || meshesByType.ContainsKey(MetalType))
            {
                return;
            }
            if (Api.Side != EnumAppSide.Client)
            {
                return;
            }

            tmpBlock         = Api.World.BlockAccessor.GetBlock(Pos);
            tmpTextureSource = ((ICoreClientAPI)Api).Tesselator.GetTexSource(tmpBlock);

            Shape shape = ObjectCacheUtil.GetOrCreate(Api, "ingotpileshape", () => Api.Assets.TryGet("shapes/block/metal/ingotpile.json")?.ToObject <Shape>());

            if (shape == null)
            {
                return;
            }

            foreach (var textureCode in Block.Textures.Keys)
            {
                ITesselatorAPI mesher = ((ICoreClientAPI)Api).Tesselator;
                MeshData[]     meshes = new MeshData[65];

                tmpMetalCode = textureCode;

                for (int j = 0; j <= 64; j++)
                {
                    mesher.TesselateShape("ingotPile", shape, out meshes[j], this, null, 0, 0, 0, j);
                }

                meshesByType[tmpMetalCode] = meshes;
            }

            tmpTextureSource = null;
            tmpMetalCode     = null;
            tmpBlock         = null;
        }
Esempio n. 20
0
        internal void EnsureMeshExists()
        {
            if (meshesByType == null)
            {
                meshesByType = new Dictionary <AssetLocation, MeshData[]>();
            }
            if (MetalType == null || meshesByType.ContainsKey(new AssetLocation(MetalType)))
            {
                return;
            }
            if (api.Side != EnumAppSide.Client)
            {
                return;
            }

            tmpBlock         = api.World.BlockAccessor.GetBlock(pos);
            tmpTextureSource = ((ICoreClientAPI)api).Tesselator.GetTexSource(tmpBlock);
            Shape         shape  = api.Assets.TryGet("shapes/block/metal/ingotpile.json").ToObject <Shape>();
            MetalProperty metals = api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>();

            for (int i = 0; i < metals.Variants.Length; i++)
            {
                if (!metals.Variants[i].Code.Path.Equals(MetalType))
                {
                    continue;
                }

                ITesselatorAPI mesher = ((ICoreClientAPI)api).Tesselator;
                MeshData[]     meshes = new MeshData[65];

                tmpMetal = metals.Variants[i].Code;

                for (int j = 0; j <= 64; j++)
                {
                    mesher.TesselateShape("ingotPile", shape, out meshes[j], this, null, 0, 0, j);
                }

                meshesByType[tmpMetal] = meshes;
            }

            tmpTextureSource = null;
            tmpMetal         = null;
            tmpBlock         = null;
        }
Esempio n. 21
0
        public override bool OnTesselation(ITerrainMeshPool meshdata, ITesselatorAPI tesselator)
        {
            DetermineBuildStages();
            if (mesh == null)
            {
                nowTesselatingKiln = true;
                blockTexPos        = tesselator.GetTexSource(Block);
                tesselator.TesselateShape("pitkiln", shape, out mesh, this, null, 0, 0, 0, null, selectiveElements);
                nowTesselatingKiln = false;
                mesh.Scale(new Vec3f(0.5f, 0.5f, 0.5f), 1.005f, 1.005f, 1.005f);
                mesh.Translate(0, GameMath.MurmurHash3Mod(Pos.X, Pos.Y, Pos.Z, 10) / 500f, 0);
            }

            meshdata.AddMeshData(mesh);

            base.OnTesselation(meshdata, tesselator);

            return(true);
        }
Esempio n. 22
0
        public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
        {
            JsonObject attrObj = itemstack.Collectible.Attributes;

            if (attrObj?["wearableAttachment"].Exists != true)
            {
                return;
            }

            Dictionary <string, MeshRef> armorMeshrefs = ObjectCacheUtil.GetOrCreate(capi, "armorMeshRefs", () => new Dictionary <string, MeshRef>());
            string key = "armorModelRef-" + itemstack.Collectible.Code.ToString();

            if (!armorMeshrefs.TryGetValue(key, out renderinfo.ModelRef))
            {
                ITexPositionSource texSource = capi.Tesselator.GetTextureSource(itemstack.Item);
                var mesh = genMesh(capi, itemstack, texSource);
                renderinfo.ModelRef = armorMeshrefs[key] = mesh == null ? renderinfo.ModelRef : capi.Render.UploadMesh(mesh);
            }
        }
        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);
            }
        }
Esempio n. 24
0
        MeshData[] GenMeshes()
        {
            tmpBlock         = Api.World.BlockAccessor.GetBlock(Pos);
            tmpTextureSource = ((ICoreClientAPI)Api).Tesselator.GetTexSource(tmpBlock);
            Shape shape = Api.Assets.TryGet("shapes/block/peatpile.json").ToObject <Shape>();

            ITesselatorAPI mesher = ((ICoreClientAPI)Api).Tesselator;

            MeshData[] meshes = new MeshData[33];

            for (int j = 0; j <= 32; j++)
            {
                mesher.TesselateShape("peatPile", shape, out meshes[j], this, null, 0, 0, 0, j);
            }

            tmpTextureSource = null;
            tmpBlock         = null;

            return(meshes);
        }
        public MeshData InitializeAnimator(string cacheDictKey, Shape shape, ITexPositionSource texSource, Vec3f rotation)
        {
            if (api.Side != EnumAppSide.Client)
            {
                throw new NotImplementedException("Server side animation system not implemented yet.");
            }

            ICoreClientAPI capi = api as ICoreClientAPI;

            Block block = api.World.BlockAccessor.GetBlock(be.Pos);

            MeshData meshdata;

            if (shape == null)
            {
                AssetLocation shapePath = block.Shape.Base.Clone().WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json");
                shape = Shape.TryGet(api, shapePath);
                if (shape == null)
                {
                    api.World.Logger.Error("Shape for block {0} not found or errored, was supposed to be at {1}. Block animations not loaded!", this.be.Block.Code, shapePath);
                    return(new MeshData());
                }
            }

            shape.ResolveReferences(api.World.Logger, cacheDictKey);
            CacheInvTransforms(shape.Elements);
            shape.ResolveAndLoadJoints();

            capi.Tesselator.TesselateShapeWithJointIds("entity", shape, out meshdata, texSource, null, block.Shape.QuantityElements, block.Shape.SelectiveElements);

            if (api.Side != EnumAppSide.Client)
            {
                throw new NotImplementedException("Server side animation system not implemented yet.");
            }

            InitializeAnimator(cacheDictKey, meshdata, shape, rotation);

            return(meshdata);
        }
        public MeshData GenMesh(ICoreClientAPI capi, string type, string shapename)
        {
            tmpTextureSource = capi.Tesselator.GetTexSource(this);

            AssetLocation shapeloc = new AssetLocation(shapename).WithPathPrefix("shapes/");
            Shape         shape    = capi.Assets.TryGet(shapeloc + ".json")?.ToObject <Shape>();

            if (shape == null)
            {
                shape = capi.Assets.TryGet(shapeloc + "1.json")?.ToObject <Shape>();
            }
            if (shape == null)
            {
                return(new MeshData());
            }

            curType = type;
            MeshData mesh;

            capi.Tesselator.TesselateShape("typedcontainer", shape, out mesh, this, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ));
            return(mesh);
        }
        void RegenMesh()
        {
            if (workItemMeshRef != null)
            {
                capi.Render.DeleteMesh(workItemMeshRef);
                workItemMeshRef = null;
            }
            if (stack == null)
            {
                return;
            }

            Shape shape;

            tmpMetal = stack.Collectible.LastCodePart();

            if (stack.Collectible.FirstCodePart() == "metalplate")
            {
                tmpTextureSource = capi.Tesselator.GetTexSource(capi.World.GetBlock(new AssetLocation("platepile")));
                shape            = capi.Assets.TryGet("shapes/block/stone/forge/platepile.json").ToObject <Shape>();
            }
            else
            {
                tmpTextureSource = capi.Tesselator.GetTexSource(capi.World.GetBlock(new AssetLocation("ingotpile")));
                shape            = capi.Assets.TryGet("shapes/block/stone/forge/ingotpile.json").ToObject <Shape>();
            }

            workItemTexPos = tmpTextureSource[tmpMetal];


            MeshData mesh;

            capi.Tesselator.TesselateShape("block-fcr", shape, out mesh, this, null, 0, 0, stack.StackSize);
            mesh.Rgba2 = null;

            workItemMeshRef = capi.Render.UploadMesh(mesh);
        }
Esempio n. 28
0
        private MeshData[] GenContentMeshes(ITesselatorAPI tesselator)
        {
            ItemStack content = GetContents();

            if (content == null)
            {
                return(null);
            }

            Dictionary <string, MeshData[]> meshes = ObjectCacheUtil.GetOrCreate(Api, "plantContainerContentMeshes", () =>
            {
                return(new Dictionary <string, MeshData[]>());
            });

            MeshData[] meshwithVariants;
            string     containersize = this.ContainerSize;
            string     key           = GetContents()?.ToString() + "-" + containersize;

            if (meshes.TryGetValue(key, out meshwithVariants))
            {
                return(meshwithVariants);
            }

            curContProps = PlantContProps;
            if (curContProps == null)
            {
                return(null);
            }

            CompositeShape compoShape = curContProps.Shape;

            if (compoShape == null)
            {
                compoShape = content.Class == EnumItemClass.Block ? content.Block.Shape : content.Item.Shape;
            }
            ModelTransform transform = curContProps.Transform;

            if (transform == null)
            {
                transform = new ModelTransform().EnsureDefaultValues();
                transform.Translation.Y = Block.Attributes["fillHeight"].AsFloat(0.4f);
            }

            contentTexSource = content.Class == EnumItemClass.Block ? capi.Tesselator.GetTexSource(content.Block) : capi.Tesselator.GetTextureSource(content.Item);
            List <IAsset> assets;

            if (compoShape.Base.Path.EndsWith("*"))
            {
                assets = Api.Assets.GetMany(compoShape.Base.WithPathPrefixOnce("shapes/").Path.Substring(0, compoShape.Base.Path.Length - 1), compoShape.Base.Domain);
            }
            else
            {
                assets = new List <IAsset>();
                assets.Add(Api.Assets.TryGet(compoShape.Base.WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json")));
            }

            if (assets != null && assets.Count > 0)
            {
                meshwithVariants = new MeshData[assets.Count];

                for (int i = 0; i < assets.Count; i++)
                {
                    IAsset asset = assets[i];
                    Shape  shape = asset.ToObject <Shape>();
                    shapeTextures = shape.Textures;
                    MeshData mesh;

                    tesselator.TesselateShape("plant container content shape", shape, out mesh, this);

                    for (int j = 0; j < mesh.RenderPassCount; j++)
                    {
                        mesh.RenderPasses[j] = (int)EnumChunkRenderPass.OpaqueNoCull;
                    }

                    Block       block = GetContents()?.Block;
                    VertexFlags flags = block?.VertexFlags;
                    if (flags != null && flags.GrassWindWave)
                    {
                        int grassWave = VertexFlags.FoliageWindWaveBitMask | VertexFlags.WeakWaveBitMask;

                        for (int vertexNum = 0; vertexNum < mesh.GetVerticesCount(); vertexNum++)
                        {
                            float y = mesh.xyz[vertexNum * 3 + 1];
                            if (y > block.WaveFlagMinY)
                            {
                                mesh.Flags[vertexNum] |= grassWave;
                            }
                        }
                    }

                    mesh.ModelTransform(transform);
                    meshwithVariants[i] = mesh;
                }
            }
            else
            {
                Api.World.Logger.Error("Plant container, content asset {0} not found,", compoShape.Base.WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json"));
            }

            return(meshes[key] = meshwithVariants);
        }
Esempio n. 29
0
        static MeshData genCube(int voxelX, int voxelY, int voxelZ, int width, int height, int length, ICoreClientAPI capi, ITexPositionSource texSource, float subPixelPadding, int renderpass, int renderFlags)
        {
            MeshData mesh = CubeMeshUtil.GetCube(
                width / 32f, height / 32f, length / 32f,
                new Vec3f(voxelX / 16f, voxelY / 16f, voxelZ / 16f)
                );


            float[] sideShadings = CubeMeshUtil.DefaultBlockSideShadingsByFacing;

            for (int i = 0; i < mesh.Rgba.Length; i += 4)
            {
                int faceIndex = i / 4 / 4;  // 4 rgba per vertex, 4 vertices per face

                byte b = (byte)(255 * sideShadings[faceIndex]);
                mesh.Rgba[i + 0] = mesh.Rgba[i + 1] = mesh.Rgba[i + 2] = b;
            }

            mesh.Flags = new int[mesh.VerticesCount];
            mesh.Flags.Fill(renderFlags);
            mesh.RenderPasses    = new int[mesh.VerticesCount / 4];
            mesh.RenderPassCount = mesh.VerticesCount / 4;
            for (int i = 0; i < mesh.RenderPassCount; i++)
            {
                mesh.RenderPasses[i] = renderpass;
            }
            mesh.Tints         = new int[mesh.VerticesCount / 4];
            mesh.TintsCount    = mesh.VerticesCount / 4;
            mesh.XyzFaces      = new int[mesh.VerticesCount / 4];
            mesh.XyzFacesCount = mesh.VerticesCount / 4;


            int k = 0;

            for (int i = 0; i < 6; i++)
            {
                mesh.XyzFaces[i] = i;

                BlockFacing facing = BlockFacing.ALLFACES[i];

                bool isOutside =
                    (
                        (facing == BlockFacing.NORTH && voxelZ == 0) ||
                        (facing == BlockFacing.EAST && voxelX + width == 16) ||
                        (facing == BlockFacing.SOUTH && voxelZ + length == 16) ||
                        (facing == BlockFacing.WEST && voxelX == 0) ||
                        (facing == BlockFacing.UP && voxelY + height == 16) ||
                        (facing == BlockFacing.DOWN && voxelY == 0)
                    )
                ;


                TextureAtlasPosition tpos = isOutside ? texSource[facing.Code] : texSource["inside-" + facing.Code];
                if (tpos == null)
                {
                    tpos = texSource[facing.Code];
                }

                for (int j = 0; j < 2 * 4; j++)
                {
                    mesh.Uv[k] = (j % 2 > 0 ? tpos.y1 : tpos.x1) + mesh.Uv[k] * 32f / texSource.AtlasSize - subPixelPadding;
                    k++;
                }
            }

            return(mesh);
        }
Esempio n. 30
0
        public static MeshData CreateDecalMesh(ICoreClientAPI coreClientAPI, List <uint> voxelCuboids, ITexPositionSource decalTexSource)
        {
            MeshData mesh = new MeshData(24, 36, false).WithTints().WithRenderpasses().WithXyzFaces();

            for (int i = 0; i < voxelCuboids.Count; i++)
            {
                FromUint(voxelCuboids[i], ref tmpCuboid);

                MeshData cuboidmesh = genCube(
                    tmpCuboid.X1, tmpCuboid.Y1, tmpCuboid.Z1,
                    tmpCuboid.X2 - tmpCuboid.X1, tmpCuboid.Y2 - tmpCuboid.Y1, tmpCuboid.Z2 - tmpCuboid.Z1,
                    coreClientAPI,
                    decalTexSource,
                    0,
                    0,
                    0
                    );

                mesh.AddMeshData(cuboidmesh);
            }

            return(mesh);
        }