public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Graves"); for (int i = 0; i < 16; i++) { int variant = GetVariant(i); float radians = (GetRotation(i) == 0) ? 0f : ((float)Math.PI / 2f); string name = "Grave" + (variant % 4 + 1).ToString(CultureInfo.InvariantCulture); bool num = variant >= 4; Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(name).ParentBone); m_blockMeshes[i] = new BlockMesh(); m_blockMeshes[i].AppendModelMeshPart(model.FindMesh(name).MeshParts[0], boneAbsoluteTransform * Matrix.CreateRotationY(radians) * Matrix.CreateTranslation(0.5f, 0f, 0.5f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMeshes[i] = new BlockMesh(); m_standaloneBlockMeshes[i].AppendModelMeshPart(model.FindMesh(name).MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (num) { Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Plinth").ParentBone); m_blockMeshes[i].AppendModelMeshPart(model.FindMesh("Plinth").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateRotationY(radians) * Matrix.CreateTranslation(0.5f, 0f, 0.5f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMeshes[i].AppendModelMeshPart(model.FindMesh("Plinth").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); } m_collisionBoxes[i] = new BoundingBox[1] { m_blockMeshes[i].CalculateBoundingBox() }; } base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Arrows"); foreach (int enumValue in EnumUtils.GetEnumValues(typeof(ArrowType))) { if (enumValue > 15) { throw new InvalidOperationException("Too many arrow types."); } Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(m_shaftNames[enumValue]).ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(m_stabilizerNames[enumValue]).ParentBone); Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(m_tipNames[enumValue]).ParentBone); BlockMesh blockMesh = new BlockMesh(); blockMesh.AppendModelMeshPart(model.FindMesh(m_tipNames[enumValue]).MeshParts[0], boneAbsoluteTransform3 * Matrix.CreateTranslation(0f, m_offsets[enumValue], 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); blockMesh.TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_tipTextureSlots[enumValue] % 16) / 16f, (float)(m_tipTextureSlots[enumValue] / 16) / 16f, 0f)); BlockMesh blockMesh2 = new BlockMesh(); blockMesh2.AppendModelMeshPart(model.FindMesh(m_shaftNames[enumValue]).MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, m_offsets[enumValue], 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); blockMesh2.TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_shaftTextureSlots[enumValue] % 16) / 16f, (float)(m_shaftTextureSlots[enumValue] / 16) / 16f, 0f)); BlockMesh blockMesh3 = new BlockMesh(); blockMesh3.AppendModelMeshPart(model.FindMesh(m_stabilizerNames[enumValue]).MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, m_offsets[enumValue], 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White); blockMesh3.TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_stabilizerTextureSlots[enumValue] % 16) / 16f, (float)(m_stabilizerTextureSlots[enumValue] / 16) / 16f, 0f)); BlockMesh blockMesh4 = new BlockMesh(); blockMesh4.AppendBlockMesh(blockMesh); blockMesh4.AppendBlockMesh(blockMesh2); blockMesh4.AppendBlockMesh(blockMesh3); m_standaloneBlockMeshes.Add(blockMesh4); } base.Initialize(); }
public override void Initialize() { for (int i = 0; i < m_blockMeshesByVariant.Length; i++) { m_blockMeshesByVariant[i] = new BlockMesh(); } Model model = ContentManager.Get <Model>("Models/Torch"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Torch").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Flame").ParentBone); Matrix m = Matrix.CreateRotationX(0.6f) * Matrix.CreateRotationY(0f) * Matrix.CreateTranslation(0.5f, 0.15f, -0.05f); m_blockMeshesByVariant[0].AppendModelMeshPart(model.FindMesh("Torch").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByVariant[0].AppendModelMeshPart(model.FindMesh("Flame").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: true, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m = Matrix.CreateRotationX(0.6f) * Matrix.CreateRotationY((float)Math.PI / 2f) * Matrix.CreateTranslation(-0.05f, 0.15f, 0.5f); m_blockMeshesByVariant[1].AppendModelMeshPart(model.FindMesh("Torch").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByVariant[1].AppendModelMeshPart(model.FindMesh("Flame").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: true, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m = Matrix.CreateRotationX(0.6f) * Matrix.CreateRotationY((float)Math.PI) * Matrix.CreateTranslation(0.5f, 0.15f, 1.05f); m_blockMeshesByVariant[2].AppendModelMeshPart(model.FindMesh("Torch").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByVariant[2].AppendModelMeshPart(model.FindMesh("Flame").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: true, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m = Matrix.CreateRotationX(0.6f) * Matrix.CreateRotationY(4.712389f) * Matrix.CreateTranslation(1.05f, 0.15f, 0.5f); m_blockMeshesByVariant[3].AppendModelMeshPart(model.FindMesh("Torch").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByVariant[3].AppendModelMeshPart(model.FindMesh("Flame").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: true, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m = Matrix.CreateTranslation(0.5f, 0f, 0.5f); m_blockMeshesByVariant[4].AppendModelMeshPart(model.FindMesh("Torch").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByVariant[4].AppendModelMeshPart(model.FindMesh("Flame").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: true, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Torch").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.25f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); for (int j = 0; j < 5; j++) { m_collisionBoxes[j] = new BoundingBox[1] { m_blockMeshesByVariant[j].CalculateBoundingBox() }; } base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Lightbulbs"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Top").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Sides").ParentBone); for (int i = 0; i < 6; i++) { Matrix m = (i >= 4) ? ((i != 4) ? (Matrix.CreateRotationX((float)Math.PI) * Matrix.CreateTranslation(0.5f, 1f, 0.5f)) : Matrix.CreateTranslation(0.5f, 0f, 0.5f)) : (Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0f, 0f, -0.5f) * Matrix.CreateRotationY((float)i * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)); m_bulbBlockMeshes[i] = new BlockMesh(); m_bulbBlockMeshes[i].AppendModelMeshPart(model.FindMesh("Top").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_bulbBlockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation(0.1875f, 0.25f, 0f)); m_bulbBlockMeshesLit[i] = new BlockMesh(); m_bulbBlockMeshesLit[i].AppendModelMeshPart(model.FindMesh("Top").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: true, flipWindingOrder: false, doubleSided: false, flipNormals: false, new Color(255, 255, 230)); m_bulbBlockMeshesLit[i].TransformTextureCoordinates(Matrix.CreateTranslation(0.9375f, 0f, 0f)); m_sidesBlockMeshes[i] = new BlockMesh(); m_sidesBlockMeshes[i].AppendModelMeshPart(model.FindMesh("Sides").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: false, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White); m_sidesBlockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation(0.9375f, 0.1875f, 0f)); m_collisionBoxes[i] = new BoundingBox[1] { m_sidesBlockMeshes[i].CalculateBoundingBox() }; } Matrix m2 = Matrix.CreateRotationY(-(float)Math.PI / 2f) * Matrix.CreateRotationZ((float)Math.PI / 2f); m_standaloneBulbBlockMesh.AppendModelMeshPart(model.FindMesh("Top").MeshParts[0], boneAbsoluteTransform * m2, makeEmissive: false, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White); m_standaloneBulbBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(0.1875f, 0.25f, 0f)); m_standaloneSidesBlockMesh.AppendModelMeshPart(model.FindMesh("Sides").MeshParts[0], boneAbsoluteTransform2 * m2, makeEmissive: false, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White); m_standaloneSidesBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(0.9375f, 0.1875f, 0f)); }
public override void Initialize() { Model model = ContentManager.Get <Model>(m_modelName); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Trapdoor").ParentBone); for (int i = 0; i < 16; i++) { int rotation = GetRotation(i); bool open = GetOpen(i); bool upsideDown = GetUpsideDown(i); m_blockMeshesByData[i] = new BlockMesh(); Matrix identity = Matrix.Identity; identity *= Matrix.CreateTranslation(0f, -0.0625f, 0.4375f) * Matrix.CreateRotationX(open ? (-(float)Math.PI / 2f) : 0f) * Matrix.CreateTranslation(0f, 0.0625f, -0.4375f); identity *= Matrix.CreateRotationZ(upsideDown ? ((float)Math.PI) : 0f); identity *= Matrix.CreateRotationY((float)rotation * (float)Math.PI / 2f); identity *= Matrix.CreateTranslation(new Vector3(0.5f, upsideDown ? 1 : 0, 0.5f)); m_blockMeshesByData[i].AppendModelMeshPart(model.FindMesh("Trapdoor").MeshParts[0], boneAbsoluteTransform * identity, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByData[i].GenerateSidesData(); m_collisionBoxesByData[i] = new BoundingBox[1] { m_blockMeshesByData[i].CalculateBoundingBox() }; } m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Trapdoor").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Musket"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Musket").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Hammer").ParentBone); m_standaloneBlockMeshUnloaded = new BlockMesh(); BlockMesh standaloneBlockMeshUnloaded = m_standaloneBlockMeshUnloaded; ReadOnlyList <ModelMeshPart> meshParts = model.FindMesh("Musket").MeshParts; standaloneBlockMeshUnloaded.AppendModelMeshPart(meshParts[0], boneAbsoluteTransform, false, false, false, false, Color.Gray); BlockMesh standaloneBlockMeshUnloaded2 = m_standaloneBlockMeshUnloaded; meshParts = model.FindMesh("Hammer").MeshParts; standaloneBlockMeshUnloaded2.AppendModelMeshPart(meshParts[0], boneAbsoluteTransform2, false, false, false, false, Color.Gray); m_standaloneBlockMeshLoaded = new BlockMesh(); BlockMesh standaloneBlockMeshLoaded = m_standaloneBlockMeshLoaded; meshParts = model.FindMesh("Musket").MeshParts; standaloneBlockMeshLoaded.AppendModelMeshPart(meshParts[0], boneAbsoluteTransform, false, false, false, false, Color.Gray); BlockMesh standaloneBlockMeshLoaded2 = m_standaloneBlockMeshLoaded; meshParts = model.FindMesh("Hammer").MeshParts; standaloneBlockMeshLoaded2.AppendModelMeshPart(meshParts[0], Matrix.CreateRotationX(0.7f) * boneAbsoluteTransform2, false, false, false, false, Color.Gray); base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Pistons"); for (int i = 0; i < 2; i++) { string name = (i == 0) ? "PistonHead" : "PistonShaft"; Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(name).ParentBone); for (PistonMode pistonMode = PistonMode.Pushing; pistonMode <= PistonMode.StrictPulling; pistonMode++) { for (int j = 0; j < 6; j++) { int num = SetFace(SetMode(SetIsShaft(0, i != 0), pistonMode), j); Matrix m = (j < 4) ? (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationY((float)j * (float)Math.PI / 2f + (float)Math.PI) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)) : ((j != 4) ? (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationX(-(float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)) : (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f))); m_blockMeshesByData[num] = new BlockMesh(); m_blockMeshesByData[num].AppendModelMeshPart(model.FindMesh(name).MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); switch (pistonMode) { case PistonMode.Pulling: m_blockMeshesByData[num].TransformTextureCoordinates(Matrix.CreateTranslation(0f, 0.0625f, 0f), 1 << j); break; case PistonMode.StrictPulling: m_blockMeshesByData[num].TransformTextureCoordinates(Matrix.CreateTranslation(0f, 0.125f, 0f), 1 << j); break; } } } } }
public override void Initialize() { Model model = ContentManager.Get <Model>(m_modelName); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Keg").ParentBone); FuseOffset = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Fuse").ParentBone).Translation + new Vector3(0.5f, 0f, 0.5f); BlockMesh blockMesh = new BlockMesh(); blockMesh.AppendModelMeshPart(model.FindMesh("Keg").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0.5f, 0f, 0.5f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMesh.AppendBlockMesh(blockMesh); if (m_isIncendiary) { m_blockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(-0.25f, 0f, 0f)); } m_collisionBoxes = new BoundingBox[1] { blockMesh.CalculateBoundingBox() }; m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Keg").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (m_isIncendiary) { m_standaloneBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(-0.25f, 0f, 0f)); } base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Switch"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Body").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Lever").ParentBone); for (int i = 0; i < 6; i++) { for (int j = 0; j < 2; j++) { int num = (i << 1) | j; Matrix m = (i >= 4) ? ((i != 4) ? (Matrix.CreateRotationX((float)Math.PI) * Matrix.CreateTranslation(0.5f, 1f, 0.5f)) : Matrix.CreateTranslation(0.5f, 0f, 0.5f)) : (Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0f, 0f, -0.5f) * Matrix.CreateRotationY((float)i * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)); Matrix m2 = Matrix.CreateRotationX((j == 0) ? MathUtils.DegToRad(30f) : MathUtils.DegToRad(-30f)); m_blockMeshesByData[num] = new BlockMesh(); m_blockMeshesByData[num].AppendModelMeshPart(model.FindMesh("Body").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByData[num].AppendModelMeshPart(model.FindMesh("Lever").MeshParts[0], boneAbsoluteTransform2 * m2 * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_collisionBoxesByData[num] = new BoundingBox[1] { m_blockMeshesByData[num].CalculateBoundingBox() }; } } Matrix m3 = Matrix.CreateRotationY(-(float)Math.PI / 2f) * Matrix.CreateRotationZ((float)Math.PI / 2f); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Body").MeshParts[0], boneAbsoluteTransform * m3, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Lever").MeshParts[0], boneAbsoluteTransform2 * m3, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/SpikedPlanks"); string[] array = new string[2] { "SpikedPlankRetracted", "SpikedPlank" }; for (int i = 0; i < 2; i++) { string name = array[i]; Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(name).ParentBone); for (int j = 0; j < 6; j++) { int num = SetMountingFace(SetSpikesState(0, i != 0), j); Matrix m = (j >= 4) ? ((j != 4) ? (Matrix.CreateRotationX((float)Math.PI) * Matrix.CreateTranslation(0.5f, 1f, 0.5f)) : Matrix.CreateTranslation(0.5f, 0f, 0.5f)) : (Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0f, 0f, -0.5f) * Matrix.CreateRotationY((float)j * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)); m_blockMeshesByData[num] = new BlockMesh(); m_blockMeshesByData[num].AppendModelMeshPart(model.FindMesh(name).MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_collisionBoxesByData[num] = new BoundingBox[1] { m_blockMeshesByData[num].CalculateBoundingBox() }; } Matrix identity = Matrix.Identity; m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh(name).MeshParts[0], boneAbsoluteTransform * identity, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); } }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Leds"); ModelMesh modelMesh = model.FindMesh("Led"); ModelMesh modelMesh2 = model.FindMesh("LedBulb"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(modelMesh.ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(modelMesh2.ParentBone); for (int i = 0; i < 8; i++) { Color color = LedColors[i]; color *= 0.5f; color.A = byte.MaxValue; Matrix m = Matrix.CreateRotationY(-(float)Math.PI / 2f) * Matrix.CreateRotationZ((float)Math.PI / 2f); m_standaloneBlockMeshesByColor[i] = new BlockMesh(); m_standaloneBlockMeshesByColor[i].AppendModelMeshPart(modelMesh.MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMeshesByColor[i].AppendModelMeshPart(modelMesh2.MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, color); for (int j = 0; j < 6; j++) { int num = SetMountingFace(SetColor(0, i), j); Matrix m2 = (j >= 4) ? ((j != 4) ? (Matrix.CreateRotationX((float)Math.PI) * Matrix.CreateTranslation(0.5f, 1f, 0.5f)) : Matrix.CreateTranslation(0.5f, 0f, 0.5f)) : (Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0f, 0f, -0.5f) * Matrix.CreateRotationY((float)j * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)); m_blockMeshesByData[num] = new BlockMesh(); m_blockMeshesByData[num].AppendModelMeshPart(modelMesh.MeshParts[0], boneAbsoluteTransform * m2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByData[num].AppendModelMeshPart(modelMesh2.MeshParts[0], boneAbsoluteTransform2 * m2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, color); m_collisionBoxesByData[num] = new BoundingBox[1] { m_blockMeshesByData[num].CalculateBoundingBox() }; } } }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Wire"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Wire").ParentBone); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Wire").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(0.9375f, 0f, 0f)); for (int i = 0; i < 6; i++) { Vector3 v = CellFace.FaceToVector3(i); Vector3 v2 = new Vector3(0.5f, 0.5f, 0.5f) - 0.5f * v; Vector3 v3; Vector3 v4; if (v.X != 0f) { v3 = new Vector3(0f, 1f, 0f); v4 = new Vector3(0f, 0f, 1f); } else if (v.Y != 0f) { v3 = new Vector3(1f, 0f, 0f); v4 = new Vector3(0f, 0f, 1f); } else { v3 = new Vector3(1f, 0f, 0f); v4 = new Vector3(0f, 1f, 0f); } Vector3 v5 = v2 - 0.5f * v3 - 0.5f * v4; Vector3 v6 = v2 + 0.5f * v3 + 0.5f * v4 + 0.05f * v; m_collisionBoxesByFace[i] = new BoundingBox(Vector3.Min(v5, v6), Vector3.Max(v5, v6)); } }
public Pipe(int id = 0) : base("Pipe" + id.ToString()) { var model = ContentManager.Get <Model>("Models/Battery"); var meshes = new BlockMesh[6]; int i; BlockMesh blockMesh; ModelMeshPart meshPart = model.FindMesh("Battery").MeshParts[0]; Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Battery").ParentBone); for (i = 0; i < 6; i++) { blockMesh = new BlockMesh(); var vector = CellFace.FaceToVector3(i); blockMesh.AppendModelMeshPart(meshPart, boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.2f, 0f) * Matrix.CreateScale(1f, 0.66f, 1f) * ((i < 4) ? (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationX(i * 3.14159274f / 2f + 3.14159274f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)) : ((i != 4) ? (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationZ(-1.57079637f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)) : (Matrix.CreateTranslation(0f, -0.5f, 0f) * Matrix.CreateRotationZ(1.57079637f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)))), false, false, false, false, Color.LightGray); blockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(-2f / 16f, 4f / 16f, 0f)); blockMesh.TransformPositions(Matrix.CreateTranslation(new Vector3(0.5f))); meshes[i] = blockMesh; } for (i = 0; i < 63; i++) { Meshes[i] = new BlockMesh(); for (int j = 0; j < 6; j++) { if (((i + 1) >> j & 1) != 0) { Meshes[i].AppendBlockMesh(meshes[j]); } } } }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Fireworks"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Body").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Fins").ParentBone); for (int i = 0; i < 64; i++) { int num = i / 8; int num2 = i % 8; Color color = FireworksColors[num2]; color *= 0.75f; color.A = byte.MaxValue; Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(HeadNames[num]).ParentBone); m_headBlockMeshes[i] = new BlockMesh(); m_headBlockMeshes[i].AppendModelMeshPart(model.FindMesh(HeadNames[num]).MeshParts[0], boneAbsoluteTransform3 * Matrix.CreateTranslation(0f, -0.25f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, color); } for (int j = 0; j < 2; j++) { float num3 = 0.5f + (float)j * 0.5f; Matrix m = Matrix.CreateScale(new Vector3(num3, 1f, num3)); m_bodyBlockMeshes[j] = new BlockMesh(); m_bodyBlockMeshes[j].AppendModelMeshPart(model.FindMesh("Body").MeshParts[0], boneAbsoluteTransform * m * Matrix.CreateTranslation(0f, -0.25f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); } for (int k = 0; k < 2; k++) { m_finsBlockMeshes[k] = new BlockMesh(); m_finsBlockMeshes[k].AppendModelMeshPart(model.FindMesh("Fins").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, -0.25f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, (k == 0) ? Color.White : new Color(224, 0, 0)); } base.Initialize(); }
public static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData) { environmentData = (environmentData ?? m_defaultEnvironmentData); Texture2D texture = (environmentData.SubsystemTerrain != null) ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture : BlocksTexturesManager.DefaultBlocksTexture; DrawMeshBlock(primitivesRenderer, blockMesh, texture, color, size, ref matrix, environmentData); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Campfire"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Wood").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Ashes").ParentBone); for (int i = 0; i < 16; i++) { m_meshesByData[i] = new BlockMesh(); if (i == 0) { m_meshesByData[i].AppendModelMeshPart(model.FindMesh("Ashes").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateScale(3f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); } else { float scale = MathUtils.Lerp(1.5f, 4f, (float)i / 15f); float radians = (float)i * (float)Math.PI / 2f; m_meshesByData[i].AppendModelMeshPart(model.FindMesh("Wood").MeshParts[0], boneAbsoluteTransform * Matrix.CreateScale(scale) * Matrix.CreateRotationY(radians) * Matrix.CreateTranslation(0.5f, 0f, 0.5f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_meshesByData[i].AppendModelMeshPart(model.FindMesh("Ashes").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateScale(scale) * Matrix.CreateRotationY(radians) * Matrix.CreateTranslation(0.5f, 0f, 0.5f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); } BoundingBox boundingBox = m_meshesByData[i].CalculateBoundingBox(); boundingBox.Min.X = 0f; boundingBox.Min.Z = 0f; boundingBox.Max.X = 1f; boundingBox.Max.Z = 1f; m_collisionBoxesByData[i] = new BoundingBox[1] { boundingBox }; } m_standaloneMesh.AppendModelMeshPart(model.FindMesh("Wood").MeshParts[0], boneAbsoluteTransform * Matrix.CreateScale(3f) * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White); m_standaloneMesh.AppendModelMeshPart(model.FindMesh("Ashes").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateScale(3f) * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White); base.Initialize(); }
public RottenEgg() : base(Utils.Get("腐蛋,不能吃。")) { DefaultDisplayName = "Rotten Egg"; var meshes = ContentManager.Get <Model>("Models/RottenEgg").Meshes; m_standaloneBlockMesh.AppendModelMeshPart(meshes[0].MeshParts[0], BlockMesh.GetBoneAbsoluteTransform(meshes[0].ParentBone), false, false, false, false, Color.White); }
public OreChunk(Matrix transform, Matrix tcTransform, Color color, bool smooth, Materials type) { string name = type.ToStr(); Id = type.ToString() + "OreChunk"; DefaultDisplayName = name + Utils.Get("矿石块"); var sb = new StringBuilder(Utils.Get("一块")); if (type == Materials.Mercury) { sb.Append(Utils.Get("氧化")); } name = char.ToLower(name[0], CultureInfo.CurrentCulture) + name.Substring(1); sb.Append(name).Append(" ore. When smelted in the furnace will turn into pure "); if (type == Materials.Mercury) { sb.Append(Utils.Get("液态")); } sb.Append(name).Append('.'); DefaultDescription = sb.ToString(); Color = color; var model = ContentManager.Get <Model>(smooth ? "Models/ChunkSmooth" : "Models/Chunk"); m_standaloneBlockMesh.AppendModelMeshPart(model.Meshes[0].MeshParts[0], BlockMesh.GetBoneAbsoluteTransform(model.Meshes[0].ParentBone) * transform, false, false, false, false, color); m_standaloneBlockMesh.TransformTextureCoordinates(tcTransform); }
public override void Initialize() { Model model = ContentManager.Get <Model>(m_modelName); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Sign").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Surface").ParentBone); for (int i = 0; i < 4; i++) { float radians = (float)Math.PI / 2f * (float)i; Matrix m = Matrix.CreateTranslation(0f, 0f, -15f / 32f) * Matrix.CreateRotationY(radians) * Matrix.CreateTranslation(0.5f, -0.3125f, 0.5f); BlockMesh blockMesh = new BlockMesh(); blockMesh.AppendModelMeshPart(model.FindMesh("Sign").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshes[i] = new BlockMesh(); m_blockMeshes[i].AppendBlockMesh(blockMesh); m_coloredBlockMeshes[i] = new BlockMesh(); m_coloredBlockMeshes[i].AppendBlockMesh(m_blockMeshes[i]); m_blockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(DefaultTextureSlot % 16) / 16f, (float)(DefaultTextureSlot / 16) / 16f, 0f)); m_coloredBlockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_coloredTextureSlot % 16) / 16f, (float)(m_coloredTextureSlot / 16) / 16f, 0f)); m_collisionBoxes[i] = new BoundingBox[1]; m_collisionBoxes[i][0] = blockMesh.CalculateBoundingBox(); m_surfaceMeshes[i] = new BlockMesh(); m_surfaceMeshes[i].AppendModelMeshPart(model.FindMesh("Surface").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_surfaceNormals[i] = -m.Forward; } m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Sign").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.6f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneColoredBlockMesh.AppendBlockMesh(m_standaloneBlockMesh); m_standaloneBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation((float)(DefaultTextureSlot % 16) / 16f, (float)(DefaultTextureSlot / 16) / 16f, 0f)); m_standaloneColoredBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_coloredTextureSlot % 16) / 16f, (float)(m_coloredTextureSlot / 16) / 16f, 0f)); base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Crossbows"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Body").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("BowRelaxed").ParentBone); Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("StringRelaxed").ParentBone); Matrix boneAbsoluteTransform4 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("BowTensed").ParentBone); Matrix boneAbsoluteTransform5 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("StringTensed").ParentBone); BlockMesh blockMesh = new BlockMesh(); blockMesh.AppendModelMeshPart(model.FindMesh("Body").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); blockMesh.AppendModelMeshPart(model.FindMesh("BowRelaxed").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); blockMesh.AppendModelMeshPart(model.FindMesh("StringRelaxed").MeshParts[0], boneAbsoluteTransform3 * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); BlockMesh blockMesh2 = new BlockMesh(); blockMesh2.AppendModelMeshPart(model.FindMesh("Body").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); blockMesh2.AppendModelMeshPart(model.FindMesh("BowTensed").MeshParts[0], boneAbsoluteTransform4 * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); blockMesh2.AppendModelMeshPart(model.FindMesh("StringTensed").MeshParts[0], boneAbsoluteTransform5 * Matrix.CreateTranslation(0f, 0f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); for (int i = 0; i < 16; i++) { float factor = (float)i / 15f; m_standaloneBlockMeshes[i] = new BlockMesh(); m_standaloneBlockMeshes[i].AppendBlockMesh(blockMesh); m_standaloneBlockMeshes[i].BlendBlockMesh(blockMesh2, factor); } base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/PressurePlate"); for (int i = 0; i < 2; i++) { Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("PressurePlate").ParentBone); int num = m_textureSlotsByMaterial[i]; for (int j = 0; j < 6; j++) { int num2 = SetMountingFace(SetMaterial(0, i), j); Matrix matrix = (j >= 4) ? ((j != 4) ? (Matrix.CreateRotationX((float)Math.PI) * Matrix.CreateTranslation(0.5f, 1f, 0.5f)) : Matrix.CreateTranslation(0.5f, 0f, 0.5f)) : (Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateTranslation(0f, 0f, -0.5f) * Matrix.CreateRotationY((float)j * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f)); m_blockMeshesByData[num2] = new BlockMesh(); m_blockMeshesByData[num2].AppendModelMeshPart(model.FindMesh("PressurePlate").MeshParts[0], boneAbsoluteTransform * matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshesByData[num2].TransformTextureCoordinates(Matrix.CreateTranslation((float)(num % 16) / 16f, (float)(num / 16) / 16f, 0f)); m_blockMeshesByData[num2].GenerateSidesData(); Vector3 vector = Vector3.Transform(new Vector3(-0.5f, 0f, -0.5f), matrix); Vector3 vector2 = Vector3.Transform(new Vector3(0.5f, 0.0625f, 0.5f), matrix); vector.X = MathUtils.Round(vector.X * 100f) / 100f; vector.Y = MathUtils.Round(vector.Y * 100f) / 100f; vector.Z = MathUtils.Round(vector.Z * 100f) / 100f; vector2.X = MathUtils.Round(vector2.X * 100f) / 100f; vector2.Y = MathUtils.Round(vector2.Y * 100f) / 100f; vector2.Z = MathUtils.Round(vector2.Z * 100f) / 100f; m_collisionBoxesByData[num2] = new BoundingBox[1] { new BoundingBox(new Vector3(MathUtils.Min(vector.X, vector2.X), MathUtils.Min(vector.Y, vector2.Y), MathUtils.Min(vector.Z, vector2.Z)), new Vector3(MathUtils.Max(vector.X, vector2.X), MathUtils.Max(vector.Y, vector2.Y), MathUtils.Max(vector.Z, vector2.Z))) }; } Matrix identity = Matrix.Identity; m_standaloneBlockMeshesByMaterial[i] = new BlockMesh(); m_standaloneBlockMeshesByMaterial[i].AppendModelMeshPart(model.FindMesh("PressurePlate").MeshParts[0], boneAbsoluteTransform * identity, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMeshesByMaterial[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(num % 16) / 16f, (float)(num / 16) / 16f, 0f)); } }
public override void Initialize() { Model model = ContentManager.Get <Model>(m_modelName); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Door").ParentBone); for (int i = 0; i < 16; i++) { int rotation = GetRotation(i); bool open = GetOpen(i); bool rightHanded = GetRightHanded(i); float num = (!rightHanded) ? 1 : (-1); m_blockMeshesByData[i] = new BlockMesh(); Matrix identity = Matrix.Identity; identity *= Matrix.CreateScale(0f - num, 1f, 1f); identity *= Matrix.CreateTranslation((0.5f - m_pivotDistance) * num, 0f, 0f) * Matrix.CreateRotationY(open ? (num * (float)Math.PI / 2f) : 0f) * Matrix.CreateTranslation((0f - (0.5f - m_pivotDistance)) * num, 0f, 0f); identity *= Matrix.CreateTranslation(0f, 0f, 0.5f - m_pivotDistance) * Matrix.CreateRotationY((float)rotation * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f); m_blockMeshesByData[i].AppendModelMeshPart(model.FindMesh("Door").MeshParts[0], boneAbsoluteTransform * identity, makeEmissive: false, !rightHanded, doubleSided: false, flipNormals: false, Color.White); BoundingBox boundingBox = m_blockMeshesByData[i].CalculateBoundingBox(); boundingBox.Max.Y = 1f; m_collisionBoxesByData[i] = new BoundingBox[1] { boundingBox }; } m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Door").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -1f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Slab"); ModelMeshPart meshPart = model.FindMesh("Slab").MeshParts[0]; Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Slab").ParentBone); for (int i = 0; i < 2; i++) { Matrix matrix = boneAbsoluteTransform * Matrix.CreateTranslation(0.5f, (i == 0) ? 0f : 0.5f, 0.5f); m_uncoloredBlockMeshes[i] = new BlockMesh(); m_uncoloredBlockMeshes[i].AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_uncoloredBlockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(DefaultTextureSlot % 16) / 16f, (float)(DefaultTextureSlot / 16) / 16f, 0f)); m_uncoloredBlockMeshes[i].GenerateSidesData(); m_coloredBlockMeshes[i] = new BlockMesh(); m_coloredBlockMeshes[i].AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_coloredBlockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_coloredTextureSlot % 16) / 16f, (float)(m_coloredTextureSlot / 16) / 16f, 0f)); m_coloredBlockMeshes[i].GenerateSidesData(); } m_standaloneUncoloredBlockMesh.AppendModelMeshPart(meshPart, boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneUncoloredBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation((float)(DefaultTextureSlot % 16) / 16f, (float)(DefaultTextureSlot / 16) / 16f, 0f)); m_standaloneColoredBlockMesh.AppendModelMeshPart(meshPart, boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneColoredBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_coloredTextureSlot % 16) / 16f, (float)(m_coloredTextureSlot / 16) / 16f, 0f)); m_collisionBoxes[0] = new BoundingBox[1] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)) }; m_collisionBoxes[1] = new BoundingBox[1] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)) }; base.Initialize(); }
public void DrawSigns(Camera camera) { if (m_nearTexts.Count > 0) { TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(m_renderTarget, useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp); foreach (TextData nearText in m_nearTexts) { if (nearText.TextureLocation.HasValue) { int cellValue = m_subsystemTerrain.Terrain.GetCellValue(nearText.Point.X, nearText.Point.Y, nearText.Point.Z); int num = Terrain.ExtractContents(cellValue); SignBlock signBlock = BlocksManager.Blocks[num] as SignBlock; if (signBlock != null) { int data = Terrain.ExtractData(cellValue); BlockMesh signSurfaceBlockMesh = signBlock.GetSignSurfaceBlockMesh(data); if (signSurfaceBlockMesh != null) { TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(nearText.Point.X, nearText.Point.Z); if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1) { nearText.Light = Terrain.ExtractLight(cellValue); } float num2 = LightingManager.LightIntensityByLightValue[nearText.Light]; Color color = new Color(num2, num2, num2); float x = 0f; float x2 = nearText.UsedTextureWidth / 128f; float x3 = (float)nearText.TextureLocation.Value / 32f; float x4 = ((float)nearText.TextureLocation.Value + nearText.UsedTextureHeight / 32f) / 32f; Vector3 signSurfaceNormal = signBlock.GetSignSurfaceNormal(data); Vector3 vector = new Vector3(nearText.Point.X, nearText.Point.Y, nearText.Point.Z); float num3 = Vector3.Dot(camera.ViewPosition - (vector + new Vector3(0.5f)), signSurfaceNormal); Vector3 v = MathUtils.Max(0.01f * num3, 0.005f) * signSurfaceNormal; for (int i = 0; i < signSurfaceBlockMesh.Indices.Count / 3; i++) { BlockMeshVertex blockMeshVertex = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3]]; BlockMeshVertex blockMeshVertex2 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 1]]; BlockMeshVertex blockMeshVertex3 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 2]]; Vector3 p = blockMeshVertex.Position + vector + v; Vector3 p2 = blockMeshVertex2.Position + vector + v; Vector3 p3 = blockMeshVertex3.Position + vector + v; Vector2 textureCoordinates = blockMeshVertex.TextureCoordinates; Vector2 textureCoordinates2 = blockMeshVertex2.TextureCoordinates; Vector2 textureCoordinates3 = blockMeshVertex3.TextureCoordinates; textureCoordinates.X = MathUtils.Lerp(x, x2, textureCoordinates.X); textureCoordinates2.X = MathUtils.Lerp(x, x2, textureCoordinates2.X); textureCoordinates3.X = MathUtils.Lerp(x, x2, textureCoordinates3.X); textureCoordinates.Y = MathUtils.Lerp(x3, x4, textureCoordinates.Y); textureCoordinates2.Y = MathUtils.Lerp(x3, x4, textureCoordinates2.Y); textureCoordinates3.Y = MathUtils.Lerp(x3, x4, textureCoordinates3.Y); texturedBatch3D.QueueTriangle(p, p2, p3, textureCoordinates, textureCoordinates2, textureCoordinates3, color); } } } } } m_primitivesRenderer3D.Flush(camera.ViewProjectionMatrix); } }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Rod"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("IronRod").ParentBone); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("IronRod").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Pumpkins"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Pumpkin").ParentBone); for (int i = 0; i < 8; i++) { float num = MathUtils.Lerp(0.2f, 1f, (float)i / 7f); float num2 = MathUtils.Min(0.3f * num, 0.7f * (1f - num)); Color color; if (m_isRotten) { color = Color.White; } else { color = Color.Lerp(new Color(0, 128, 128), new Color(80, 255, 255), (float)i / 7f); if (i == 7) { color.R = byte.MaxValue; } } m_blockMeshesBySize[i] = new BlockMesh(); if (i >= 1) { m_blockMeshesBySize[i].AppendModelMeshPart(model.FindMesh("Pumpkin").MeshParts[0], boneAbsoluteTransform * Matrix.CreateScale(num) * Matrix.CreateTranslation(0.5f + num2, 0f, 0.5f + num2), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, color); } if (m_isRotten) { m_blockMeshesBySize[i].TransformTextureCoordinates(Matrix.CreateTranslation(-0.375f, 0.25f, 0f)); } m_standaloneBlockMeshesBySize[i] = new BlockMesh(); m_standaloneBlockMeshesBySize[i].AppendModelMeshPart(model.FindMesh("Pumpkin").MeshParts[0], boneAbsoluteTransform * Matrix.CreateScale(num) * Matrix.CreateTranslation(0f, -0.23f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, color); if (m_isRotten) { m_standaloneBlockMeshesBySize[i].TransformTextureCoordinates(Matrix.CreateTranslation(-0.375f, 0.25f, 0f)); } } for (int j = 0; j < 8; j++) { BoundingBox boundingBox = (m_blockMeshesBySize[j].Vertices.Count > 0) ? m_blockMeshesBySize[j].CalculateBoundingBox() : new BoundingBox(new Vector3(0.5f, 0f, 0.5f), new Vector3(0.5f, 0f, 0.5f)); float num3 = boundingBox.Max.X - boundingBox.Min.X; if (num3 < 0.8f) { float num4 = (0.8f - num3) / 2f; boundingBox.Min.X -= num4; boundingBox.Min.Z -= num4; boundingBox.Max.X += num4; boundingBox.Max.Y = 0.4f; boundingBox.Max.Z += num4; } m_collisionBoxesBySize[j] = new BoundingBox[1] { boundingBox }; } base.Initialize(); }
public override void Initialize() { Model model = m_smooth ? ContentManager.Get <Model>("Models/ChunkSmooth") : ContentManager.Get <Model>("Models/Chunk"); Matrix matrix = BlockMesh.GetBoneAbsoluteTransform(model.Meshes[0].ParentBone) * m_transform; m_standaloneBlockMesh.AppendModelMeshPart(model.Meshes[0].MeshParts[0], matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, m_color); m_standaloneBlockMesh.TransformTextureCoordinates(m_tcTransform); base.Initialize(); }
public static InstancedModelData CreateInstancedModelData(Model model, int[] meshDrawOrders) { DynamicArray <InstancedVertex> dynamicArray = new DynamicArray <InstancedVertex>(); DynamicArray <ushort> dynamicArray2 = new DynamicArray <ushort>(); for (int i = 0; i < meshDrawOrders.Length; i++) { ModelMesh modelMesh = model.Meshes[meshDrawOrders[i]]; foreach (ModelMeshPart meshPart in modelMesh.MeshParts) { _ = dynamicArray.Count; VertexBuffer vertexBuffer = meshPart.VertexBuffer; IndexBuffer indexBuffer = meshPart.IndexBuffer; ReadOnlyList <VertexElement> vertexElements = vertexBuffer.VertexDeclaration.VertexElements; ushort[] indexData = BlockMesh.GetIndexData <ushort>(indexBuffer); Dictionary <ushort, ushort> dictionary = new Dictionary <ushort, ushort>(); if (vertexElements.Count != 3 || vertexElements[0].Offset != 0 || !(vertexElements[0].Semantic == VertexElementSemantic.Position.GetSemanticString()) || vertexElements[1].Offset != 12 || !(vertexElements[1].Semantic == VertexElementSemantic.Normal.GetSemanticString()) || vertexElements[2].Offset != 24 || !(vertexElements[2].Semantic == VertexElementSemantic.TextureCoordinate.GetSemanticString())) { throw new InvalidOperationException("Unsupported vertex format."); } SourceModelVertex[] vertexData = BlockMesh.GetVertexData <SourceModelVertex>(vertexBuffer); for (int j = meshPart.StartIndex; j < meshPart.StartIndex + meshPart.IndicesCount; j++) { ushort num = indexData[j]; if (!dictionary.ContainsKey(num)) { dictionary.Add(num, (ushort)dynamicArray.Count); InstancedVertex item = default(InstancedVertex); SourceModelVertex sourceModelVertex = vertexData[num]; item.X = sourceModelVertex.X; item.Y = sourceModelVertex.Y; item.Z = sourceModelVertex.Z; item.Nx = sourceModelVertex.Nx; item.Ny = sourceModelVertex.Ny; item.Nz = sourceModelVertex.Nz; item.Tx = sourceModelVertex.Tx; item.Ty = sourceModelVertex.Ty; item.Instance = modelMesh.ParentBone.Index; dynamicArray.Add(item); } } for (int k = 0; k < meshPart.IndicesCount / 3; k++) { dynamicArray2.Add(dictionary[indexData[meshPart.StartIndex + 3 * k]]); dynamicArray2.Add(dictionary[indexData[meshPart.StartIndex + 3 * k + 1]]); dynamicArray2.Add(dictionary[indexData[meshPart.StartIndex + 3 * k + 2]]); } } } InstancedModelData instancedModelData = new InstancedModelData(); instancedModelData.VertexBuffer = new VertexBuffer(InstancedModelData.VertexDeclaration, dynamicArray.Count); instancedModelData.IndexBuffer = new IndexBuffer(IndexFormat.SixteenBits, dynamicArray2.Count); instancedModelData.VertexBuffer.SetData(dynamicArray.Array, 0, dynamicArray.Count); instancedModelData.IndexBuffer.SetData(dynamicArray2.Array, 0, dynamicArray2.Count); return(instancedModelData); }
public override void Initialize() { Model model = ContentManager.Get <Model>(m_modelName); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.Meshes[0].ParentBone); m_standaloneBlockMesh.AppendModelMeshPart(model.Meshes[0].MeshParts[0], boneAbsoluteTransform, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, m_color); m_standaloneBlockMesh.TransformTextureCoordinates(m_tcTransform); base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/BoatItem"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Boat").ParentBone); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Boat").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.4f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, new Color(96, 96, 96)); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Boat").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.4f, 0f), makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: false, new Color(255, 255, 255)); base.Initialize(); }