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() { 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 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 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>("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("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>(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>(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 = 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 void AppendMesh(this BlockMesh blockMesh, string modelName, string meshName, Matrix boneTransform, Matrix tcTransform, Color color) { var model = ContentManager.Get <Model>(modelName); blockMesh.AppendModelMeshPart(model.FindMesh(meshName).MeshParts[0], BlockMesh.GetBoneAbsoluteTransform(model.FindMesh(meshName).ParentBone) * boneTransform, false, false, false, false, color); if (tcTransform != Matrix.Identity) { blockMesh.TransformTextureCoordinates(tcTransform); } }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/FullBucket"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Bucket").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Contents").ParentBone); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Contents").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateRotationY(MathUtils.DegToRad(180f)) * Matrix.CreateTranslation(0f, -0.3f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, new Color(200, 130, 35)); m_standaloneBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(0.0625f, 0.4375f, 0f)); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Bucket").MeshParts[0], boneAbsoluteTransform * Matrix.CreateRotationY(MathUtils.DegToRad(180f)) * Matrix.CreateTranslation(0f, -0.3f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); base.Initialize(); }
public override void Initialize() { int num = 47; Model model = ContentManager.Get <Model>("Models/WoodenClub"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Handle").ParentBone); BlockMesh blockMesh = new BlockMesh(); blockMesh.AppendModelMeshPart(model.FindMesh("Handle").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); blockMesh.TransformTextureCoordinates(Matrix.CreateTranslation((float)(num % 16) / 16f, (float)(num / 16) / 16f, 0f)); m_standaloneBlockMesh.AppendBlockMesh(blockMesh); base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>(m_modelName); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Post").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Planks").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); 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, 0f) * Matrix.CreateRotationY((float)rotation * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f); m_blockMeshes[i] = new BlockMesh(); m_blockMeshes[i].AppendModelMeshPart(model.FindMesh("Post").MeshParts[0], boneAbsoluteTransform * identity, makeEmissive: false, !rightHanded, doubleSided: false, flipNormals: false, m_postColor); m_blockMeshes[i].AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * identity, makeEmissive: false, !rightHanded, doubleSided: false, flipNormals: false, Color.White); if (m_doubleSided) { m_blockMeshes[i].AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * identity, makeEmissive: false, rightHanded, doubleSided: false, flipNormals: true, Color.White); } 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)); BoundingBox boundingBox = m_blockMeshes[i].CalculateBoundingBox(); boundingBox.Min.X = MathUtils.Saturate(boundingBox.Min.X); boundingBox.Min.Y = MathUtils.Saturate(boundingBox.Min.Y); boundingBox.Min.Z = MathUtils.Saturate(boundingBox.Min.Z); boundingBox.Max.X = MathUtils.Saturate(boundingBox.Max.X); boundingBox.Max.Y = MathUtils.Saturate(boundingBox.Max.Y); boundingBox.Max.Z = MathUtils.Saturate(boundingBox.Max.Z); m_collisionBoxes[i] = new BoundingBox[1] { boundingBox }; } m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Post").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, m_postColor); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (m_doubleSided) { m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, 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>(m_modelName); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Sign").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Post").ParentBone); Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Surface").ParentBone); for (int i = 0; i < 16; i++) { bool hanging = GetHanging(i); Matrix m = Matrix.CreateRotationY((float)GetDirection(i) * (float)Math.PI / 4f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f); if (hanging) { m *= Matrix.CreateScale(1f, -1f, 1f) * Matrix.CreateTranslation(0f, 1f, 0f); } m_directions[i] = m.Forward; BlockMesh blockMesh = new BlockMesh(); blockMesh.AppendModelMeshPart(model.FindMesh("Sign").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, hanging, doubleSided: false, flipNormals: false, Color.White); BlockMesh blockMesh2 = new BlockMesh(); blockMesh2.AppendModelMeshPart(model.FindMesh("Post").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: false, hanging, doubleSided: false, flipNormals: false, Color.White); m_blockMeshes[i] = new BlockMesh(); m_blockMeshes[i].AppendBlockMesh(blockMesh); m_blockMeshes[i].AppendBlockMesh(blockMesh2); 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[2]; m_collisionBoxes[i][0] = blockMesh.CalculateBoundingBox(); m_collisionBoxes[i][1] = blockMesh2.CalculateBoundingBox(); m_surfaceMeshes[i] = new BlockMesh(); m_surfaceMeshes[i].AppendModelMeshPart(model.FindMesh("Surface").MeshParts[0], boneAbsoluteTransform3 * m, makeEmissive: false, hanging, doubleSided: false, flipNormals: false, Color.White); m_surfaceNormals[i] = -m.Forward; if (hanging) { for (int j = 0; j < m_surfaceMeshes[i].Vertices.Count; j++) { Vector2 textureCoordinates = m_surfaceMeshes[i].Vertices.Array[j].TextureCoordinates; textureCoordinates.Y = 1f - textureCoordinates.Y; m_surfaceMeshes[i].Vertices.Array[j].TextureCoordinates = textureCoordinates; } } } 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_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Post").MeshParts[0], boneAbsoluteTransform2 * 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() { int num = 63; Model model = ContentManager.Get <Model>("Models/Starfish"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Starfish").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Bottom").ParentBone); for (int i = 0; i < 6; i++) { for (int j = 0; j < 4; j++) { Vector2 zero = Vector2.Zero; if (i < 4) { zero.Y = (float)i * (float)Math.PI / 2f; } else if (i == 4) { zero.X = -(float)Math.PI / 2f; } else { zero.X = (float)Math.PI / 2f; } Matrix m = Matrix.CreateRotationX((float)Math.PI / 2f) * Matrix.CreateRotationZ(0.3f + 2f * (float)j) * Matrix.CreateTranslation(m_offsets[j].X, m_offsets[j].Y, -0.49f) * Matrix.CreateRotationX(zero.X) * Matrix.CreateRotationY(zero.Y) * Matrix.CreateTranslation(0.5f, 0.5f, 0.5f); int num2 = 4 * i + j; m_blockMeshes[num2] = new BlockMesh(); m_blockMeshes[num2].AppendModelMeshPart(model.FindMesh("Starfish").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_blockMeshes[num2].TransformTextureCoordinates(Matrix.CreateTranslation((float)(num % 16) / 16f, (float)(num / 16) / 16f, 0f)); m_collisionBoxes[num2] = new BoundingBox[1] { m_blockMeshes[num2].CalculateBoundingBox() }; } } m_standaloneBlockMesh = new BlockMesh(); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Starfish").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, -0.1f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Bottom").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateTranslation(0f, -0.1f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMesh.TransformTextureCoordinates(Matrix.CreateTranslation((float)(num % 16) / 16f, (float)(num / 16) / 16f, 0f)); base.Initialize(); }
public override void Initialize() { Model model = ContentManager.Get <Model>("Models/Stairs"); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Stairs").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("StairsOuterCorner").ParentBone); Matrix boneAbsoluteTransform3 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("StairsInnerCorner").ParentBone); for (int i = 0; i < 24; i++) { int rotation = GetRotation(i); bool isUpsideDown = GetIsUpsideDown(i); CornerType cornerType = GetCornerType(i); Matrix m = (!isUpsideDown) ? (Matrix.CreateRotationY((float)rotation * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f)) : (Matrix.CreateRotationY((float)rotation * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, -0.5f, 0.5f) * Matrix.CreateScale(1f, -1f, 1f) * Matrix.CreateTranslation(0f, 0.5f, 0f)); BlockMesh blockMesh = new BlockMesh(); switch (cornerType) { case CornerType.None: blockMesh.AppendModelMeshPart(model.FindMesh("Stairs").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, isUpsideDown, doubleSided: false, flipNormals: false, Color.White); break; case CornerType.OneQuarter: blockMesh.AppendModelMeshPart(model.FindMesh("StairsOuterCorner").MeshParts[0], boneAbsoluteTransform2 * m, makeEmissive: false, isUpsideDown, doubleSided: false, flipNormals: false, Color.White); break; case CornerType.ThreeQuarters: blockMesh.AppendModelMeshPart(model.FindMesh("StairsInnerCorner").MeshParts[0], boneAbsoluteTransform3 * m, makeEmissive: false, isUpsideDown, doubleSided: false, flipNormals: false, Color.White); break; } float num = isUpsideDown ? rotation : (-rotation); blockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(-0.03125f, -0.03125f, 0f) * Matrix.CreateRotationZ(num * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.03125f, 0.03125f, 0f), 16); blockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(-0.03125f, -0.03125f, 0f) * Matrix.CreateRotationZ((0f - num) * (float)Math.PI / 2f) * Matrix.CreateTranslation(0.03125f, 0.03125f, 0f), 32); if (isUpsideDown) { blockMesh.TransformTextureCoordinates(Matrix.CreateTranslation(-0.03125f, -0.03125f, 0f) * Matrix.CreateScale(1f, -1f, 1f) * Matrix.CreateTranslation(0.03125f, 0.03125f, 0f)); } m_coloredBlockMeshes[i] = new BlockMesh(); m_coloredBlockMeshes[i].AppendBlockMesh(blockMesh); m_coloredBlockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_coloredTextureSlot % 16) / 16f, (float)(m_coloredTextureSlot / 16) / 16f, 0f)); m_coloredBlockMeshes[i].GenerateSidesData(); m_uncoloredBlockMeshes[i] = new BlockMesh(); m_uncoloredBlockMeshes[i].AppendBlockMesh(blockMesh); m_uncoloredBlockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(DefaultTextureSlot % 16) / 16f, (float)(DefaultTextureSlot / 16) / 16f, 0f)); m_uncoloredBlockMeshes[i].GenerateSidesData(); } m_standaloneUncoloredBlockMesh.AppendModelMeshPart(model.FindMesh("Stairs").MeshParts[0], 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(model.FindMesh("Stairs").MeshParts[0], 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[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0.5f)), new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f)) }; m_collisionBoxes[1] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 1f, 1f)), new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 0.5f, 1f)) }; m_collisionBoxes[2] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f)), new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 1f, 1f)) }; m_collisionBoxes[3] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 1f)), new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 1f, 1f)) }; m_collisionBoxes[4] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 0.5f)), new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f)) }; m_collisionBoxes[5] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 1f, 1f)), new BoundingBox(new Vector3(0.5f, 0.5f, 0f), new Vector3(1f, 1f, 1f)) }; m_collisionBoxes[6] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f)), new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 1f, 1f)) }; m_collisionBoxes[7] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(0.5f, 1f, 1f)), new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 1f, 1f)) }; m_collisionBoxes[8] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0.5f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f)) }; m_collisionBoxes[9] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(0.5f, 1f, 0.5f)) }; m_collisionBoxes[10] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(0.5f, 1f, 1f)) }; m_collisionBoxes[11] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f)) }; m_collisionBoxes[12] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f)) }; m_collisionBoxes[13] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f)) }; m_collisionBoxes[14] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(0.5f, 0.5f, 1f)) }; m_collisionBoxes[15] = new BoundingBox[2] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0.5f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f)) }; m_collisionBoxes[16] = new BoundingBox[3] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f)), new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f)) }; m_collisionBoxes[17] = new BoundingBox[3] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f)), new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(0.5f, 1f, 1f)) }; m_collisionBoxes[18] = new BoundingBox[3] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(0.5f, 1f, 0.5f)) }; m_collisionBoxes[19] = new BoundingBox[3] { new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0f, 0.5f, 0.5f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0.5f, 0.5f, 0f), new Vector3(1f, 1f, 0.5f)) }; m_collisionBoxes[20] = new BoundingBox[3] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f)), new BoundingBox(new Vector3(0.5f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f)) }; m_collisionBoxes[21] = new BoundingBox[3] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f)), new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(0.5f, 0.5f, 1f)) }; m_collisionBoxes[22] = new BoundingBox[3] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(0.5f, 0.5f, 0.5f)) }; m_collisionBoxes[23] = new BoundingBox[3] { new BoundingBox(new Vector3(0f, 0.5f, 0f), new Vector3(1f, 1f, 1f)), new BoundingBox(new Vector3(0f, 0f, 0.5f), new Vector3(1f, 0.5f, 1f)), new BoundingBox(new Vector3(0.5f, 0f, 0f), new Vector3(1f, 0.5f, 0.5f)) }; base.Initialize(); }
public override void Initialize() { base.Initialize(); var mesh = new BlockMesh(); var vertices = new[] { new BlockMeshVertex { Color = Color.White, TextureCoordinates = new Vector2(0, 0.0625f), Position = new Vector3(0, 0.01f, 1) }, new BlockMeshVertex { Color = Color.White, TextureCoordinates = new Vector2(0.0625f, 0.0625f), Position = new Vector3(1, 0.01f, 1) }, new BlockMeshVertex { Color = Color.White, TextureCoordinates = new Vector2(0.0625f, 0), Position = new Vector3(1, 0.01f, 0) }, new BlockMeshVertex { Color = Color.White, TextureCoordinates = new Vector2(0, 0), Position = new Vector3(0, 0.01f, 0) } }; var indices = new ushort[] { 2, 1, 0, 0, 3, 2 }; mesh.Vertices.AddRange(vertices); mesh.Indices.AddRange(indices); var flatMesh = new BlockMesh(); flatMesh.AppendBlockMesh(mesh); flatMesh.TransformTextureCoordinates(Matrix.CreateTranslation(new Vector3(238 % 16 / 16f, 238 / 16 / 16f, 0f))); var center = Matrix.CreateTranslation(new Vector3(0.5f, 0, 0.5f)); var reverseCenter = Matrix.CreateTranslation(new Vector3(-0.5f, 0, -0.5f)); for (int i = 0; i < 4; i++) { m_blockMeshes[i] = new BlockMesh(); m_blockMeshes[i].AppendBlockMesh(flatMesh); m_blockMeshes[i].TransformPositions(reverseCenter * Matrix.CreateRotationY(MathUtils.PI * 0.5f * i) * center); m_blockMeshes[i].GenerateSidesData(); } flatMesh = new BlockMesh(); flatMesh.AppendBlockMesh(mesh); flatMesh.TransformTextureCoordinates(Matrix.CreateTranslation(new Vector3(237 % 16 / 16f, 237 / 16 / 16f, 0f))); m_blockMeshes[4] = new BlockMesh(); m_blockMeshes[4].AppendBlockMesh(flatMesh); m_blockMeshes[4].GenerateSidesData(); m_blockMeshes[5] = new BlockMesh(); m_blockMeshes[5].AppendBlockMesh(flatMesh); m_blockMeshes[5].TransformPositions(reverseCenter * Matrix.CreateRotationY(MathUtils.PI * 0.5f) * center); m_blockMeshes[5].GenerateSidesData(); mesh = new BlockMesh(); vertices = new BlockMeshVertex[] { new BlockMeshVertex { Color = Color.White, TextureCoordinates = new Vector2(0, 0.0625f), Position = new Vector3(0, 0.01f, 1) }, new BlockMeshVertex { Color = Color.White, TextureCoordinates = new Vector2(0.0625f, 0.0625f), Position = new Vector3(1, 0.01f, 1) }, new BlockMeshVertex { Color = Color.White, TextureCoordinates = new Vector2(0.0625f, 0), Position = new Vector3(1, 1.01f, 0) }, new BlockMeshVertex { Color = Color.White, TextureCoordinates = new Vector2(0, 0), Position = new Vector3(0, 1.01f, 0) } }; indices = new ushort[] { 2, 1, 0, 0, 1, 2, 0, 3, 2, 2, 3, 0 }; mesh.Vertices.AddRange(vertices); mesh.Indices.AddRange(indices); mesh.TransformTextureCoordinates(Matrix.CreateTranslation(new Vector3(237 % 16 / 16f, 237 / 16 / 16f, 0f))); for (int i = 6; i < 10; i++) { m_blockMeshes[i] = new BlockMesh(); m_blockMeshes[i].AppendBlockMesh(mesh); m_blockMeshes[i].TransformPositions(reverseCenter * Matrix.CreateRotationY(MathUtils.PI * 0.5f * i) * center); } var boxes = new [] { new BoundingBox(0, 0, 0, 1, 0.01f, 1) }; for (int i = 0; i < 6; i++) { boundingBoxes[i] = boxes; } boundingBoxes[6] = new BoundingBox[] { new BoundingBox(0, 0, 0, 1, 0.01f, 1), new BoundingBox(0, 0, 0.25f, 1, 0.25f, 1), new BoundingBox(0, 0, 0.5f, 1, 0.5f, 1), new BoundingBox(0, 0, 0.75f, 1, 0.75f, 1) }; boundingBoxes[7] = new BoundingBox[] { new BoundingBox(0, 0, 0, 1, 0.01f, 1), new BoundingBox(0.25f, 0, 0, 1, 0.25f, 1), new BoundingBox(0.5f, 0, 0, 1, 0.5f, 1), new BoundingBox(0.75f, 0, 0, 1, 0.75f, 1) }; boundingBoxes[8] = new BoundingBox[] { new BoundingBox(0, 0, 0, 1, 0.01f, 1), new BoundingBox(0, 0, 0, 1, 0.25f, 0.75f), new BoundingBox(0, 0, 0, 1, 0.5f, 0.5f), new BoundingBox(0, 0, 0, 1, 0.75f, 0.25f) }; boundingBoxes[9] = new BoundingBox[] { new BoundingBox(0, 0, 0, 1, 0.01f, 1), new BoundingBox(0, 0, 0, 0.75f, 0.25f, 1), new BoundingBox(0, 0, 0, 0.5f, 0.5f, 1), new BoundingBox(0, 0, 0, 0.25f, 0.75f, 1) }; }
public override void Initialize() { Model model = ContentManager.Get <Model>(m_modelName); Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Post").ParentBone); Matrix boneAbsoluteTransform2 = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Planks").ParentBone); for (int i = 0; i < 16; i++) { bool num = (i & 1) != 0; bool flag = (i & 2) != 0; bool flag2 = (i & 4) != 0; bool flag3 = (i & 8) != 0; List <BoundingBox> list = new List <BoundingBox>(); Matrix m = Matrix.CreateTranslation(0.5f, 0f, 0.5f); BlockMesh blockMesh = new BlockMesh(); blockMesh.AppendModelMeshPart(model.FindMesh("Post").MeshParts[0], boneAbsoluteTransform * m, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); BoundingBox item = blockMesh.CalculateBoundingBox(); item.Min.X -= 0.1f; item.Min.Z -= 0.1f; item.Max.X += 0.1f; item.Max.Z += 0.1f; list.Add(item); BlockMesh blockMesh2 = new BlockMesh(); if (num) { BlockMesh blockMesh3 = new BlockMesh(); Matrix m2 = Matrix.CreateRotationY(0f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f); blockMesh3.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * m2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (m_doubleSidedPlanks) { blockMesh3.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * m2, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, Color.White); } blockMesh2.AppendBlockMesh(blockMesh3); BoundingBox item2 = blockMesh3.CalculateBoundingBox(); list.Add(item2); } if (flag) { BlockMesh blockMesh4 = new BlockMesh(); Matrix m3 = Matrix.CreateRotationY((float)Math.PI) * Matrix.CreateTranslation(0.5f, 0f, 0.5f); blockMesh4.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * m3, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (m_doubleSidedPlanks) { blockMesh4.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * m3, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, Color.White); } blockMesh2.AppendBlockMesh(blockMesh4); BoundingBox item3 = blockMesh4.CalculateBoundingBox(); list.Add(item3); } if (flag2) { BlockMesh blockMesh5 = new BlockMesh(); Matrix m4 = Matrix.CreateRotationY(4.712389f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f); blockMesh5.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * m4, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (m_doubleSidedPlanks) { blockMesh5.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * m4, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, Color.White); } blockMesh2.AppendBlockMesh(blockMesh5); BoundingBox item4 = blockMesh5.CalculateBoundingBox(); list.Add(item4); } if (flag3) { BlockMesh blockMesh6 = new BlockMesh(); Matrix m5 = Matrix.CreateRotationY((float)Math.PI / 2f) * Matrix.CreateTranslation(0.5f, 0f, 0.5f); blockMesh6.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * m5, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (m_doubleSidedPlanks) { blockMesh6.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * m5, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, Color.White); } blockMesh2.AppendBlockMesh(blockMesh6); BoundingBox item5 = blockMesh6.CalculateBoundingBox(); list.Add(item5); } blockMesh.ModulateColor(m_postColor); m_blockMeshes[i] = new BlockMesh(); m_blockMeshes[i].AppendBlockMesh(blockMesh); m_blockMeshes[i].AppendBlockMesh(blockMesh2); m_blockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(DefaultTextureSlot % 16) / 16f, (float)(DefaultTextureSlot / 16) / 16f, 0f)); m_blockMeshes[i].GenerateSidesData(); m_coloredBlockMeshes[i] = new BlockMesh(); m_coloredBlockMeshes[i].AppendBlockMesh(blockMesh); m_coloredBlockMeshes[i].AppendBlockMesh(blockMesh2); m_coloredBlockMeshes[i].TransformTextureCoordinates(Matrix.CreateTranslation((float)(m_coloredTextureSlot % 16) / 16f, (float)(m_coloredTextureSlot / 16) / 16f, 0f)); m_coloredBlockMeshes[i].GenerateSidesData(); m_collisionBoxes[i] = list.ToArray(); } m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Post").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(-0.5f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Post").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0.5f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateRotationY(0f) * Matrix.CreateTranslation(-0.5f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (m_doubleSidedPlanks) { m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateRotationY(0f) * Matrix.CreateTranslation(-0.5f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, Color.White); } m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateRotationY((float)Math.PI) * Matrix.CreateTranslation(0.5f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); if (m_doubleSidedPlanks) { m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Planks").MeshParts[0], boneAbsoluteTransform2 * Matrix.CreateRotationY((float)Math.PI) * Matrix.CreateTranslation(0.5f, -0.5f, 0f), makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, 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(); }