public static void AddStaticMesh(StaticMesh mesh) { if (mesh != null) { SimulationSpace.Add(mesh); } }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { mesh = entryA as StaticMesh; convex = entryB as ConvexCollidable; if (mesh == null || convex == null) { mesh = entryB as StaticMesh; convex = entryA as ConvexCollidable; if (mesh == null || convex == null) throw new Exception("Inappropriate types used to initialize pair."); } //Contact normal goes from A to B. broadPhaseOverlap.entryA = convex; broadPhaseOverlap.entryB = mesh; UpdateMaterialProperties(convex.entity != null ? convex.entity.material : null, mesh.material); base.Initialize(entryA, entryB); }
/// <summary> /// Creates a new instance /// </summary> /// <param name="collisionObject">The ParentObject this instance will be associated with</param> /// <param name="vertices">The Model vertices used to compute the BEPUPgysics StaticMesh</param> /// <param name="indices">The Model indices used to compute the BEPUPgysics StaticMesh</param> public StaticMeshCollisionMove(ICollisionObject collisionObject, Vector3[] vertices, int[] indices) : base(collisionObject) { ParentObject.World.Decompose(out _collisionObjectScale, out _collisionObjectRotation, out _collisionObjectTranslation); SpaceObject = new StaticMesh(vertices, indices, new AffineTransform(_collisionObjectScale, _collisionObjectRotation, _collisionObjectTranslation)); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public PrimitiveSceneBugDemo(DemosGame game) : base(game) { character = new BugShowerCharacterController(Space, game.Camera, game); Space.ForceUpdater.Gravity = new Vector3(0, -16, 0); game.Camera.Position = new Vector3(5, 0.85f, 4); game.Camera.ViewDirection = new Vector3(0, 0, 1); //Since this is the character playground, turn on the character by default. character.Activate(); //Having the character body visible would be a bit distracting. character.CharacterController.Body.Tag = "noDisplayObject"; //Load in mesh data for the environment. Vector3[] staticTriangleVertices; int[] staticTriangleIndices; var playgroundModel = game.Content.Load <Model>("bugPrimitiveRoom"); //This is a little convenience method used to extract vertices and indices from a model. //It doesn't do anything special; any approach that gets valid vertices and indices will work. ModelDataExtractor.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices); var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(new Vector3(1, 1, 1), Quaternion.Identity, new Vector3(0, 0, 0))); staticMesh.Sidedness = TriangleSidedness.Counterclockwise; Space.Add(staticMesh); game.ModelDrawer.Add(staticMesh); }
public static void RemoveStaticMesh(StaticMesh mesh) { if (mesh != null) { SimulationSpace.Remove(mesh); } }
public void UpdateCollider(Transform transform, Mesh mesh) { if (mesh != null) { Mesh _mesh = mesh; if (MeshHandler != null) { Physics.Remove(MeshHandler); MeshHandler = null; } BEPUutilities.Vector3[] points = new BEPUutilities.Vector3[_mesh._vertices.Length]; for (int i = 0; i < _mesh._vertices.Length; i++) { if (i < _mesh._vertices.Length) { points[i] = new BEPUutilities.Vector3(_mesh._vertices[i].X, _mesh._vertices[i].Y, _mesh._vertices[i].Z); } } MeshHandler = new StaticMesh(points, _mesh._indices, new BEPUutilities.AffineTransform(new BEPUutilities.Vector3(transform.Position.X, transform.Position.Y, transform.Position.Z))); Physics.Add(MeshHandler); _mesh = null; } }
///<summary> /// Cleans up the pair handler. ///</summary> public override void CleanUp() { base.CleanUp(); mesh = null; convex = null; }
private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e) { int n = listBox1.SelectedIndex; if (n == -1) { return; } n = Objects[n]; lODToolStripMenuItem.Visible = false; UnCheckLODs(); stm = null; skm = null; skmold = null; Preview3D.SkelMesh = null; Preview3D.StatMesh = null; if (pcc.getExport(n).ClassName == "StaticMesh") { LoadStaticMesh(n); } if (pcc.getExport(n).ClassName == "SkeletalMesh") { LoadSkeletalMesh(n); } }
private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e) { int n = listBox1.SelectedIndex; if (n == -1) { return; } n = Objects[n]; lODToolStripMenuItem.Visible = false; UnCheckLODs(); stm = null; skm = null; preview?.Dispose(); preview = null; MaterialBox.Visible = false; MaterialApplyButton.Visible = false; MaterialIndexBox.Visible = false; MaterialIndexApplyButton.Visible = false; if (Pcc.getExport(n).ClassName == "StaticMesh") { LoadStaticMesh(n); } if (Pcc.getExport(n).ClassName == "SkeletalMesh") { LoadSkeletalMesh(n); } }
static void CreateEntitiesWhichNotSynchronizedViaNetwork() { //ground { StaticMesh staticMesh = (StaticMesh)Entities.Instance.Create( "StaticMesh", Map.Instance); staticMesh.SplitGeometry = true; staticMesh.SplitGeometryPieceSize = new Vec3(10, 10, 10); staticMesh.MeshName = "Models\\DefaultBox\\DefaultBox.mesh"; staticMesh.ForceMaterial = "Ball"; staticMesh.Position = new Vec3(0, 0, -.5f); staticMesh.Scale = new Vec3(50, 50, 1); staticMesh.CastDynamicShadows = false; staticMesh.PostCreate(); } //SkyBox { Entity skyBox = Entities.Instance.Create("SkyBox", Map.Instance); skyBox.PostCreate(); } //Light { Light light = (Light)Entities.Instance.Create("Light", Map.Instance); light.LightType = RenderLightType.Directional; light.SpecularColor = new ColorValue(1, 1, 1); light.Position = new Vec3(0, 0, 10); light.Rotation = new Angles(120, 50, 330).ToQuat(); light.PostCreate(); } }
static Stream ProcessCCMesh(IPackfileEntry oldFile, string oldName, string newName) { MemoryStream outStream = new MemoryStream(); using (Stream inStream = oldFile.GetStream()) { VFile.VFile vFile = new VFile.VFile(inStream); StaticMesh mesh = new StaticMesh(inStream); for (int i = 0; i < vFile.References.Count; i++) { string reference = vFile.References[i]; if (textureNameMap.ContainsKey(reference)) { vFile.References[i] = textureNameMap[reference]; } } string[] textureNames = new string[mesh.TextureNames.Count]; mesh.TextureNames.Keys.CopyTo(textureNames, 0); foreach (string textureName in textureNames) { if (textureNameMap.ContainsKey(textureName)) { mesh.RenameTexture(textureName, textureNameMap[textureName]); } } vFile.Save(outStream); mesh.Save(outStream); } return(outStream); }
internal static unsafe void Invoke(IntPtr obj, StaticMesh NewDisplayMesh) { long* p = stackalloc long[] {0L,0L}; byte* b = (byte*) p; *((IntPtr*)(b+0)) = NewDisplayMesh; Main.GetProcessEvent(obj, SetCustomDisplayMesh_ptr, new IntPtr(p)); ; } }
//grab static mesh instances for entities void GetDrawObject(string archPath, string instPath, out object draw, out BoundingBox box) { draw = null; box = mPMob.GetBounds(); //whateva if (archPath == null || archPath == "") { return; } if (instPath == null || instPath == "") { return; } if (!mStatics.ContainsKey(archPath)) { return; } StaticMesh sm = new StaticMesh(mStatics[archPath]); sm.ReadFromFile(mGameRootDir + "\\Statics\\" + instPath); sm.SetMatLib(mStaticMats); draw = sm; box = sm.GetBoxBound(); if (box.Size.IsZero) { //no bounds saved in the mesh? Gen sm.UpdateBounds(); box = sm.GetBoxBound(); } }
public StaticMeshColliderComponent(object tag, List <Microsoft.Xna.Framework.Vector3> verts, int[] indices) { if (tag != null) { Tag = tag; } ParentObject = tag as GameObject; List <BEPUutilities.Vector3> bepuVerts = MathConverter.Convert(verts.ToArray()) .ToList(); staticMesh = new StaticMesh(bepuVerts.ToArray(), indices, AffineTransform.Identity); offset = staticMesh.WorldTransform.Translation.ToXNAVector(); staticMesh.Tag = this.Tag; if (!SystemCore.PhysicsOnBackgroundThread) { SystemCore.PhysicsSimulation.Add(staticMesh); } else { SystemCore.PhysicsSimulation.SpaceObjectBuffer.Add(staticMesh); } }
/// <summary> /// Initializes a new instance of the <see cref="TriangleMeshObject"/> class. /// </summary> /// <param name="model">The model.</param> /// <param name="pos">The pos.</param> /// <param name="rotation">The rotation.</param> /// <param name="scale">The scale.</param> /// <param name="materialDescription">The material description.</param> public TriangleMeshObject(IModelo model, Vector3 pos, Matrix?rotation = null, Vector3?scale = null, MaterialDescription materialDescription = null) { if (materialDescription == null) { materialDescription = MaterialDescription.DefaultBepuMaterial(); } if (!rotation.HasValue) { rotation = Matrix.Identity; } if (!scale.HasValue) { scale = Vector3.One; } System.Diagnostics.Debug.Assert(model != null); System.Diagnostics.Debug.Assert(scale != Vector3.Zero); this.rotation = rotation.Value; this.scale = scale.Value; this.position = pos; Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); triangleGroup = new StaticMesh(vertices, indices, new AffineTransform(scale.Value, Quaternion.CreateFromRotationMatrix(rotation.Value), position)); faceVector = Vector3.Transform(Vector3.Forward, triangleGroup.WorldTransform.Matrix); triangleGroup.Material = new BEPUphysics.Materials.Material(materialDescription.StaticFriction, materialDescription.DynamicFriction, materialDescription.Bounciness); }
public void Preview() { int n = listBox1.SelectedIndex; if (n == -1) { return; } int idx = objects[n]; hb1.ByteProvider = new DynamicByteProvider(udk.Exports[idx].data); treeView1.Nodes.Clear(); if (udk.GetClass(udk.Exports[idx].clas) == "SkeletalMesh") { STM = null; SKM = new SkeletalMesh(udk, idx); treeView1.Nodes.Add(SKM.ToTree()); } if (udk.GetClass(udk.Exports[idx].clas) == "StaticMesh") { SKM = null; STM = new StaticMesh(udk, idx); treeView1.Nodes.Add(STM.ToTree()); } }
/// <summary>USE "GetModel" UNLESS YOU KNOW WHAT YOU ARE DOING!!!</summary> /// <param name="staticMeshId">The name id of the mesh you wish to obtain.</param> /// <returns>The desired static mesh if it exists.</returns> public static StaticMesh GetMesh(string staticMeshId) { StaticMesh mesh = _staticMeshDatabase.Get <string>(staticMeshId, StaticMesh.CompareTo); mesh.ExistingReferences++; return(mesh); }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public AddRemoveStressDemo(DemosGame game) : base(game) { Space.Remove(vehicle.Vehicle); var compoundShape = new CompoundShape(new List <CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape(1, 1, 1), new Vector3(0, 1, 0), 1), new CompoundShapeEntry(new BoxShape(2, 1, 2), new Vector3(), 1), new CompoundShapeEntry(new BoxShape(1, 1, 1), new Vector3(0, -1, 0), 1) }); for (int i = 0; i < 300; ++i) { var toAdd = new Entity(compoundShape, 10); addedEntities.Add(toAdd); } var boxShape = new BoxShape(1, 1, 1); for (int i = 0; i < 300; ++i) { var toAdd = new Entity(boxShape, 10); addedEntities.Add(toAdd); } Vector3[] vertices; int[] indices; ModelDataExtractor.GetVerticesAndIndicesFromModel(game.Content.Load <Model>("cube"), out vertices, out indices); var mobileMeshShape = new MobileMeshShape(vertices, indices, new AffineTransform(Matrix3x3.CreateScale(1, 2, 1), new Vector3()), MobileMeshSolidity.Counterclockwise); for (int i = 0; i < 300; ++i) { var toAdd = new Entity(mobileMeshShape, 10); addedEntities.Add(toAdd); } for (int i = 0; i < addedEntities.Count; ++i) { var entity = addedEntities[i]; entity.Gravity = new Vector3(); entity.Position = GetRandomPosition(random); entity.LinearVelocity = 3 * Vector3.Normalize(entity.Position); Space.Add(entity); } var playgroundModel = game.Content.Load <Model>("playground"); ModelDataExtractor.GetVerticesAndIndicesFromModel(playgroundModel, out vertices, out indices); var staticMesh = new StaticMesh(vertices, indices, new AffineTransform(Matrix3x3.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), new Vector3(0, -30, 0))); staticMesh.Sidedness = TriangleSidedness.Counterclockwise; Space.Add(staticMesh); game.ModelDrawer.Add(staticMesh); game.Camera.Position = new Vector3(0, 6, 15); }
static void CreateEntitiesWhichNotSynchronizedViaNetwork() { //ground { //create materials from the code ShaderBaseMaterial[] materials = new ShaderBaseMaterial[7]; { for (int n = 0; n < materials.Length; n++) { string materialName = HighLevelMaterialManager.Instance.GetUniqueMaterialName( "ExampleOfProceduralMapCreation_Ground"); ShaderBaseMaterial material = (ShaderBaseMaterial)HighLevelMaterialManager.Instance.CreateMaterial( materialName, "ShaderBaseMaterial"); material.Diffuse1Map.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A.dds", n + 1); material.NormalMap.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A_N.dds", n + 1); material.SpecularColor = new ColorValue(1, 1, 1); material.SpecularMap.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A_S.dds", n + 1); material.PostCreate(); materials[n] = material; } } //create objects with collision body EngineRandom random = new EngineRandom(0); for (float y = -35; y < 35; y += 5) { for (float x = -35; x < 35; x += 2.5f) { StaticMesh staticMesh = (StaticMesh)Entities.Instance.Create("StaticMesh", Map.Instance); staticMesh.MeshName = "Base\\Simple Models\\Box.mesh"; ShaderBaseMaterial material = materials[random.Next(0, 6)]; staticMesh.ForceMaterial = material.Name; //"DarkGray"; staticMesh.Position = new Vec3(x, y, -1.0f); staticMesh.Scale = new Vec3(2.5f, 5, 2); staticMesh.CastDynamicShadows = false; staticMesh.PostCreate(); } } } //SkyBox { Entity skyBox = Entities.Instance.Create("SkyBox", Map.Instance); skyBox.PostCreate(); } //Light { Light light = (Light)Entities.Instance.Create("Light", Map.Instance); light.LightType = RenderLightType.Directional; light.SpecularColor = new ColorValue(1, 1, 1); light.Position = new Vec3(0, 0, 10); light.Rotation = new Angles(120, 50, 330).ToQuat(); light.PostCreate(); } }
///<summary> /// Cleans up the pair handler. ///</summary> public override void CleanUp() { base.CleanUp(); mesh = null; }
public A3DMeshTintOnDamage(ICombatant parent, StaticMesh parentMesh, int tintDuration, Color colorToTint) : base(parent as Drawable3D, 1000) { this.tintDuration = tintDuration; this.colorToTint = colorToTint; this.parentMesh = parentMesh; parentCombatant = parent; }
public void Dispose() { if (MeshHandler != null) { Physics.Remove(MeshHandler); MeshHandler = null; } }
internal void Render(DeviceContext dc) { foreach (Character c in mCharacters) { c.Draw(dc, mCharMats); } foreach (StaticMesh sm in mMeshes) { sm.Draw(dc, mStaticMats); } for (int i = 0; i < mCharacters.Count; i++) { foreach (KeyValuePair <int, Matrix> bone in mCBones[i]) { Matrix boneTrans = bone.Value; if (bone.Key == mCBone[i]) { mCPrims.DrawBox(dc, bone.Key, boneTrans * mCharacters[i].GetTransform(), mHitColor); } else { mCPrims.DrawBox(dc, bone.Key, boneTrans * mCharacters[i].GetTransform(), Vector4.One * 0.5f); } } } int idx = 10000; for (int i = 0; i < mMeshes.Count; i++) { StaticMesh sm = mMeshes[i]; Matrix mat = sm.GetTransform(); Dictionary <Mesh, BoundingBox> bnd = mMeshBounds[i]; foreach (KeyValuePair <Mesh, BoundingBox> b in bnd) { if (b.Key == mPartHit && mMeshHit == sm) { mCPrims.DrawBox(dc, idx++, b.Key.GetTransform() * mat, mHitColor); } else { mCPrims.DrawBox(dc, idx++, b.Key.GetTransform() * mat, Vector4.One * 0.5f); } } } mCPrims.DrawAxis(dc); mSUI.Draw(dc, Matrix.Identity, mTextProj); mST.Draw(dc, Matrix.Identity, mTextProj); }
internal static unsafe bool Invoke(IntPtr obj, StaticMesh NewMesh) { long *p = stackalloc long[] { 0L, 0L, 0L }; byte *b = (byte *)p; *((IntPtr *)(b + 0)) = NewMesh; Main.GetProcessEvent(obj, SetStaticMesh_ptr, new IntPtr(p));; return(*((bool *)(b + 8))); } }
public void LoadStaticMesh(int index) { stm = new StaticMesh(pcc, index); Preview3D.StatMesh = stm; //Preview3D.SkelMesh = null; Preview3D.CamOffset = new Vector3(0, 0, 0); treeView1.Nodes.Clear(); treeView1.Nodes.Add(stm.ToTree()); treeView1.Nodes[0].Expand(); }
/// <summary> /// Creates a new instance /// </summary> /// <param name="collisionObject">The ParentObject this instance will be associated with</param> /// <param name="model">The Model used to compute the BEPUPgysics StaticMesh</param> public StaticMeshCollisionMove(ICollisionObject collisionObject, Model model) : base(collisionObject) { Vector3[] vertices; int[] indices; TriangleMesh.GetVerticesAndIndicesFromModel(model, out vertices, out indices); ParentObject.World.Decompose(out _collisionObjectScale, out _collisionObjectRotation, out _collisionObjectTranslation); SpaceObject = new StaticMesh(vertices, indices, new AffineTransform(_collisionObjectScale, _collisionObjectRotation, _collisionObjectTranslation)); }
public async Task <IActionResult> Post([FromBody] StaticMesh value) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } value = await repo.CreateAsync(AuthMan.GetAccountId(this), value); return(CreatedAtAction("Get", value)); }
internal static unsafe int Invoke(UObject WorldContextObject, StaticMesh StaticMesh, Box Box) { long *p = stackalloc long[] { 0L, 0L, 0L, 0L, 0L, 0L, 0L }; byte *b = (byte *)p; *((IntPtr *)(b + 0)) = WorldContextObject; *((IntPtr *)(b + 8)) = StaticMesh; *((Box *)(b + 16)) = Box; Main.GetProcessEvent(FoliageStatistics.DefaultObject, FoliageOverlappingBoxCount_ptr, new IntPtr(p));; return(*((int *)(b + 44))); } }
//an attempt to recreate the assembling process in MaxScript similar to unreal t3d //Rotation is buggy, doesn't properly for now public static void ExportT3D_MS(StaticMesh STM, string Filename, Matrix m, Vector3 IncScale3D) { StreamWriter Writer = new StreamWriter(Filename, true); Vector3 Rotator = new Vector3((float)Math.Atan2(m.M32, m.M33), (float)Math.Asin(-1 * m.M31), (float)Math.Atan2(-1 * m.M21, m.M11)); float RotatorX = Rotator.X; RotatorX = RadianToDegrees(RotatorX); float RotatorY = Rotator.Y; RotatorY = RadianToDegrees(RotatorY); float RotatorZ = Rotator.Z; RotatorZ = RadianToDegrees(RotatorZ); Vector3 Location = new Vector3(m.M41, m.M42, m.M43); if (STM != null) { Writer.WriteLine($"{STM.Export.ObjectName} = instance ${STM.Export.ObjectName}"); Writer.WriteLine($"{STM.Export.ObjectName}.name = \"{STM.Export.ObjectName}\" --name the copy as \"{STM.Export.ObjectName}\""); Writer.WriteLine("$" + STM.Export.ObjectName + ".Position=[" + Location.X.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + ", " + Location.Y.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + ", " + Location.Z.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + "]"); Writer.WriteLine("$" + STM.Export.ObjectName + ".scale=[" + IncScale3D.X.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + ", " + IncScale3D.Y.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + ", " + IncScale3D.Z.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + "]"); Writer.WriteLine("--Setting the rotation"); Writer.WriteLine("fn SetObjectRotation obj rx ry rz ="); Writer.WriteLine("("); Writer.WriteLine("-- Reset the object's transformation matrix so that"); Writer.WriteLine("-- it only includes position and scale information."); Writer.WriteLine("-- Doing this clears out any previous object rotation."); Writer.WriteLine("local translateMat = transMatrix obj.transform.pos"); Writer.WriteLine("local scaleMat = scaleMatrix obj.transform.scale"); Writer.WriteLine("obj.transform = scaleMat * translateMat"); Writer.WriteLine("-- Perform each axis rotation individually"); Writer.WriteLine("rotate obj (angleaxis rx [1,0,0])"); Writer.WriteLine("rotate obj (angleaxis ry [0,1,0])"); Writer.WriteLine("rotate obj (angleaxis rz [0,0,1])"); Writer.WriteLine(")"); Writer.WriteLine("-- Set currently selected Object's rotation to " + RotatorX.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + " " + RotatorY.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + " " + RotatorZ.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US"))); Writer.WriteLine("SetObjectRotation $" + STM.Export.ObjectName + " " + RotatorX.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + " " + RotatorY.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + " " + RotatorZ.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US"))); Writer.WriteLine("-------------------------------------------------------"); Writer.WriteLine("-------------------------------------------------------"); } Writer.Close(); }
public new void Load(ContentManager content, String path) { base.Load(content, path); Vector3[] vertices; int[] indices; TriangleMesh.GetVerticesAndIndicesFromModel(Model, out vertices, out indices); mesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(width, height, length), Quaternion.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z), World.Translation)); mesh.ImproveBoundaryBehavior = false; mesh.IgnoreShapeChanges = true; mesh.Tag = this; }
public MeshCollider(Transform transform, Vector3[] vertices, int[] indices) { BEPUutilities.Vector3[] points = new BEPUutilities.Vector3[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { points[i] = new BEPUutilities.Vector3(vertices[i].X, vertices[i].Y, vertices[i].Z); } MeshHandler = new StaticMesh(points, indices, new BEPUutilities.AffineTransform(new BEPUutilities.Vector3(transform.Position.X, transform.Position.Y, transform.Position.Z))); Physics.Add(MeshHandler); }
//UDK version, need to figure out how to apply rotation properly public static void ExportT3D_UDK(StaticMesh STM, string Filename, Matrix m, Vector3 IncScale3D) { StreamWriter Writer = new StreamWriter(Filename, true); Vector3 Rotator = new Vector3((float)Math.Atan2(m.M32, m.M33), (float)Math.Asin(-1 * m.M31), (float)Math.Atan2(-1 * m.M21, m.M11)); float RotatorX = Rotator.X; RotatorX = RadianToUnrealDegrees(RotatorX); float RotatorY = Rotator.Y; RotatorY = RadianToUnrealDegrees(RotatorY); float RotatorZ = Rotator.Z; RotatorZ = RadianToUnrealDegrees(RotatorZ); Vector3 Location = new Vector3(m.M41, m.M42, m.M43); if (STM != null) { Writer.WriteLine(" Begin Actor Class=StaticMeshActor Name=STMC_" + STM.Export.ObjectName.Number + " Archetype=StaticMeshActor'Engine.Default__StaticMeshActor'"); Writer.WriteLine(" Begin Object Class=StaticMeshComponent Name=STMC_" + STM.Export.ObjectName.Number + " ObjName=" + STM.Export.ObjectName.Instanced + " Archetype=StaticMeshComponent'Engine.Default__StaticMeshActor:StaticMeshComponent0'"); Writer.WriteLine(" StaticMesh=StaticMesh'A_Cathedral.Static." + STM.Export.ObjectName + "'"); Writer.WriteLine(" LODData(0)="); Writer.WriteLine(" VertexPositionVersionNumber=1"); Writer.WriteLine(" ReplacementPrimitive=None"); Writer.WriteLine(" bAllowApproximateOcclusion=True"); Writer.WriteLine(" bForceDirectLightMap=True"); Writer.WriteLine(" bUsePrecomputedShadows=True"); Writer.WriteLine(" LightingChannels=(bInitialized=True,Static=True)"); Writer.WriteLine(" Name=\"" + STM.Export.ObjectName + "_" + STM.Export.ObjectName.Number + "\""); Writer.WriteLine(" ObjectArchetype=StaticMeshComponent'Engine.Default__StaticMeshActor:StaticMeshComponent0'"); Writer.WriteLine(" End Object"); Writer.WriteLine(" StaticMeshComponent=StaticMeshComponent'" + STM.Export.ObjectName.Instanced + "'"); Writer.WriteLine(" Components(0)=StaticMeshComponent'" + STM.Export.ObjectName.Instanced + "'"); Writer.WriteLine(" Location=(X=" + Location.X.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + "," + "Y=" + Location.Y.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + "," + "Z=" + Location.Z.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US"))); Writer.WriteLine(" Rotation=(Pitch=" + RotatorY.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + "Yaw=" + RotatorZ.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + "," + "Roll=" + RotatorX.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + ")"); Writer.WriteLine(" DrawScale=(X=" + IncScale3D.X.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + "," + "Y=" + IncScale3D.Y.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + "," + "Z=" + IncScale3D.Z.ToString("F3", System.Globalization.CultureInfo.GetCultureInfo("en-US")) + ")"); Writer.WriteLine(" CreationTime=1.462282"); Writer.WriteLine(" Tag=\"StaticMeshActor\""); Writer.WriteLine(" CollisionComponent=StaticMeshComponent'" + STM.Export.ObjectName + "'"); Writer.WriteLine(" Name=\"STMC_" + STM.Export.ObjectName.Number.ToString("D") + "\""); Writer.WriteLine(" ObjectArchetype=StaticMeshActor'Engine.Default__StaticMeshActor'"); Writer.WriteLine(" End Actor"); } Writer.Close(); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { mesh = entryA as StaticMesh; if (mesh == null) { mesh = entryB as StaticMesh; if (mesh == null) { throw new Exception("Inappropriate types used to initialize pair."); } } base.Initialize(entryA, entryB); }
public void LoadContent(ContentManager contentManager) { // Set up static mesh VertexPositionTexture[] vertices = new VertexPositionTexture[4]; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { vertices[General.GetIndex(i, j, 2)] = new VertexPositionTexture(new Vector3(i - 0.5f, j - 0.5f, 0), new Vector2(i, 1 - j)); } } int[] indices = { 0, 1, 3, 0, 3, 2 }; StaticMesh = new StaticMeshTexture(contentManager, textureName, vertices, indices); }
public void LoadContent(ContentManager contentManager) { for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { GridPiece gridPiece = new GridPiece(); gridPiece.HighLighted = false; gridPiece.CheckerPiece = null; Grid[i, j] = gridPiece; } } int[] indices = { 0, 1, 3, 0, 3, 2 }; VertexPositionColor[] gridVertices = new VertexPositionColor[4]; for (int k = 0; k < 2; ++k) { for (int m = 0; m < 2; ++m) { gridVertices[General.GetIndex(k, m, 2)] = new VertexPositionColor(new Vector3(-0.5f + k, -0.5f + m, 0), new Color(0, 0, 128, 256)); } } GridStaticMesh = new StaticMeshColor(gridVertices, indices); // Load the static mesh VertexPositionTexture[] vertices=new VertexPositionTexture[4]; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { vertices[General.GetIndex(i, j, 2)] = new VertexPositionTexture(new Vector3(8*i-4, 8*j-4, 0), new Vector2(i, 1-j)); } } StaticMesh = new StaticMeshTexture(contentManager, textureName, vertices, indices); }
public static void Res_SetStaticMeshProperties(StaticMesh r_static) { var tmp = EngineLua.Call("getStaticMeshProperties", r_static.ObjectID); var collisionType = (COLLISION_TYPE) tmp[0]; if(collisionType > 0) { var collisionShape = (COLLISION_SHAPE)tmp[1]; var hide = (bool)tmp[2]; r_static.Self.CollisionType = collisionType; r_static.Self.CollisionShape = collisionShape; r_static.Hide = hide; } }
public static void TR_GenRoom(int roomIndex, Room room, World world, Level tr) { var trRoom = tr.Rooms[roomIndex]; #region Room properties room.ID = (uint) roomIndex; room.Active = true; room.Frustum = new List<Frustum>(); room.Flags = trRoom.Flags; room.LightMode = trRoom.LightMode; room.ReverbInfo = (byte) trRoom.ReverbInfo; room.WaterScheme = trRoom.WaterScheme; room.AlternateGroup = (byte) trRoom.AlternateGroup; room.Transform = new Transform(); room.Transform.SetIdentity(); room.Transform.Origin = trRoom.Offset.ToVector3(); room.AmbientLighting = new float[3]; room.AmbientLighting[0] = trRoom.LightColor.R * 2; room.AmbientLighting[1] = trRoom.LightColor.G * 2; room.AmbientLighting[2] = trRoom.LightColor.B * 2; room.Self = new EngineContainer(); room.Self.Room = room; room.Self.Object = room; room.Self.ObjectType = OBJECT_TYPE.RoomBase; room.NearRoomList = new List<Room>(); room.OverlappedRoomList = new List<Room>(); room.GenMesh(world, (uint) roomIndex, tr); room.BtBody = null; // let's load static room meshes room.StaticMesh = new List<StaticMesh>(); #endregion #region Static meshes Loader.StaticMesh trStatic; for (var i = 0; i < trRoom.StaticMeshes.Length; i++) { var trsm = trRoom.StaticMeshes[i]; trStatic = tr.FindStaticMeshById(trsm.ObjectID); if (trStatic.Equals(default(Loader.StaticMesh))) { continue; } var rStatic = new StaticMesh(); rStatic.Self = new EngineContainer(); rStatic.Self.Room = room; rStatic.Self.Object = rStatic; rStatic.Self.ObjectType = OBJECT_TYPE.StaticMesh; rStatic.ObjectID = trsm.ObjectID; rStatic.Mesh = world.Meshes[(int) tr.MeshIndices[trStatic.Mesh]]; rStatic.Position = trsm.Position.ToVector3(); rStatic.Rotation = new Vector3(trsm.Rotation, 0.0f, 0.0f); rStatic.Tint[0] = trsm.Tint.R * 2; rStatic.Tint[1] = trsm.Tint.G * 2; rStatic.Tint[2] = trsm.Tint.B * 2; rStatic.Tint[3] = trsm.Tint.A * 2; rStatic.CBBMin.X = trStatic.CollisionBox[0].X; rStatic.CBBMin.Y = -trStatic.CollisionBox[0].Z; rStatic.CBBMin.Z = trStatic.CollisionBox[1].Y; rStatic.CBBMax.X = trStatic.CollisionBox[1].X; rStatic.CBBMax.Y = -trStatic.CollisionBox[1].Z; rStatic.CBBMax.Z = trStatic.CollisionBox[0].Y; rStatic.VBBMin.X = trStatic.VisibilityBox[0].X; rStatic.VBBMin.Y = -trStatic.VisibilityBox[0].Z; rStatic.VBBMin.Z = trStatic.VisibilityBox[1].Y; rStatic.VBBMax.X = trStatic.VisibilityBox[1].X; rStatic.VBBMax.Y = -trStatic.VisibilityBox[1].Z; rStatic.VBBMax.Z = trStatic.VisibilityBox[0].Y; rStatic.OBB.Transform = rStatic.Transform; rStatic.OBB.Radius = rStatic.Mesh.Radius; rStatic.Transform.SetIdentity(); VMath.Mat4_Translate(rStatic.Transform, rStatic.Position); VMath.Mat4_RotateZ(rStatic.Transform, rStatic.Rotation.X); rStatic.WasRendered = 0; rStatic.OBB.Rebuild(rStatic.VBBMin, rStatic.VBBMax); rStatic.OBB.DoTransform(); rStatic.BtBody = null; rStatic.Hide = false; // Disable static mesh collision, if flag value is 3 (TR1) or all bounding box // coordinates are equal (TR2-5). if (trStatic.Flags == 3 || trStatic.CollisionBox[0].X == -trStatic.CollisionBox[0].Y && trStatic.CollisionBox[0].Y == trStatic.CollisionBox[0].Z && trStatic.CollisionBox[1].X == -trStatic.CollisionBox[1].Y && trStatic.CollisionBox[1].Y == trStatic.CollisionBox[1].Z) { rStatic.Self.CollisionType = COLLISION_TYPE.None; } else { rStatic.Self.CollisionType = COLLISION_TYPE.Static; rStatic.Self.CollisionShape = COLLISION_SHAPE.Box; } // Set additional static mesh properties from level script override. Res_SetStaticMeshProperties(rStatic); // Set static mesh collision. if (rStatic.Self.CollisionType != COLLISION_TYPE.None) { CollisionShape cshape; switch (rStatic.Self.CollisionShape) { case COLLISION_SHAPE.Box: cshape = BT_CSfromBBox(rStatic.CBBMin, rStatic.CBBMax, true, true); break; case COLLISION_SHAPE.BoxBase: cshape = BT_CSfromBBox(rStatic.Mesh.BBMin, rStatic.Mesh.BBMax, true, true); break; case COLLISION_SHAPE.Trimesh: cshape = BT_CSfromMesh(rStatic.Mesh, true, true, true); break; case COLLISION_SHAPE.TrimeshConvex: cshape = BT_CSfromMesh(rStatic.Mesh, true, true, true); break; default: cshape = null; break; } if (cshape != null) { var startTransform = rStatic.Transform; var motionState = new DefaultMotionState(((Matrix4) startTransform).ToBullet()); var localInertia = Vector3.Zero; rStatic.BtBody = new RigidBody(new RigidBodyConstructionInfo(0.0f, motionState, cshape, localInertia.ToBullet())); BtEngineDynamicsWorld.AddRigidBody(rStatic.BtBody, CollisionFilterGroups.AllFilter, CollisionFilterGroups.AllFilter); rStatic.BtBody.UserObject = rStatic.Self; } } room.StaticMesh.Add(rStatic); } #endregion #region Sprites foreach (var trs in trRoom.Sprites) { var rs = new RoomSprite(); if (trs.Texture.IsBetween(0, world.Sprites.Count, IB.aIbE)) { rs.Sprite = world.Sprites[trs.Texture]; rs.Position = trRoom.Vertices[trs.Vertex].Vertex.ToVector3() + room.Transform.Origin; } room.Sprites.Add(rs); } #endregion #region Sectors room.SectorsX = trRoom.Num_X_Sectors; room.SectorsY = trRoom.Num_Z_Sectors; room.Sectors = new List<RoomSector>(); room.Sectors.Resize(room.SectorsX * room.SectorsY, () => new RoomSector()); // base sectors information loading and collisional mesh creation // To avoid manipulating with unnecessary information, we declare simple // heightmap here, which will be operated with sector and floordata parsing, // then vertical inbetween polys will be constructed, and Bullet collisional // object will be created. Afterwards, this heightmap also can be used to // quickly detect slopes for pushable blocks and other entities that rely on // floor level. for (var i = 0; i < room.Sectors.Count; i++) { var sector = room.Sectors[i]; // Filling base sectors information. sector.IndexX = (short) (i / room.SectorsY); sector.IndexY = (short) (i % room.SectorsY); sector.Position.X = room.Transform.Origin.X + (sector.IndexX + 0.5f) * TR_METERING_SECTORSIZE; sector.Position.Y = room.Transform.Origin.Y + (sector.IndexY + 0.5f) * TR_METERING_SECTORSIZE; sector.Position.Z = 0.5f * (trRoom.Y_Bottom + trRoom.Y_Top); sector.OwnerRoom = room; if (tr.GameVersion < TRGame.TR3) { sector.BoxIndex = trRoom.Sectors[i].Box_Index; sector.Material = SectorMaterial.Stone; } else { sector.BoxIndex = (trRoom.Sectors[i].Box_Index & 0xFFF0) >> 4; sector.Material = (SectorMaterial)((uint) trRoom.Sectors[i].Box_Index & 0x000F); } if (sector.BoxIndex == 0xFFFF) sector.BoxIndex = -1; sector.Flags = 0; // Clear sector flags sector.Floor = (int) -TR_METERING_STEP * trRoom.Sectors[i].Floor; sector.Ceiling = (int) -TR_METERING_STEP * trRoom.Sectors[i].Ceiling; sector.TrigIndex = trRoom.Sectors[i].FD_Index; // BUILDING CEILING HEIGHTMAP. // Penetration config is used later to build inbetween vertical collision polys. // If sector's penetration config is a wall, we simply build a vertical plane to // isolate this sector from top to bottom. Also, this allows to trick out wall // sectors inside another wall sectors to be ignored completely when building // collisional mesh. // Door penetration config means that we should either ignore sector collision // completely (classic door) or ignore one of the triangular sector parts (TR3+). if (sector.Ceiling == TR_METERING_WALLHEIGHT) { sector.CeilingPenetrationConfig = TR_PENETRATION_CONFIG.Wall; } else if (trRoom.Sectors[i].RoomAbove != 0xFF) { sector.CeilingPenetrationConfig = TR_PENETRATION_CONFIG.Ghost; } else { sector.CeilingPenetrationConfig = TR_PENETRATION_CONFIG.Solid; } // Reset some sector parameters to avoid garbaged memory issues. sector.PortalToRoom = -1; sector.CeilingDiagonalType = TR_SECTOR_DIAGONAL_TYPE.None; sector.FloorDiagonalType = TR_SECTOR_DIAGONAL_TYPE.None; // Now, we define heightmap cells position and draft (flat) height. // Draft height is derived from sector's floor and ceiling values, which are // copied into heightmap cells Y coordinates. As result, we receive flat // heightmap cell, which will be operated later with floordata. sector.CeilingCorners[0][0] = sector.IndexX * TR_METERING_SECTORSIZE; sector.CeilingCorners[0][1] = sector.IndexY * TR_METERING_SECTORSIZE + TR_METERING_SECTORSIZE; sector.CeilingCorners[0][2] = sector.Ceiling; sector.CeilingCorners[1][0] = sector.IndexX * TR_METERING_SECTORSIZE + TR_METERING_SECTORSIZE; sector.CeilingCorners[1][1] = sector.IndexY * TR_METERING_SECTORSIZE + TR_METERING_SECTORSIZE; sector.CeilingCorners[1][2] = sector.Ceiling; sector.CeilingCorners[2][0] = sector.IndexX * TR_METERING_SECTORSIZE + TR_METERING_SECTORSIZE; sector.CeilingCorners[2][1] = sector.IndexY * TR_METERING_SECTORSIZE; sector.CeilingCorners[2][2] = sector.Ceiling; sector.CeilingCorners[3][0] = sector.IndexX * TR_METERING_SECTORSIZE; sector.CeilingCorners[3][1] = sector.IndexY * TR_METERING_SECTORSIZE; sector.CeilingCorners[3][2] = sector.Ceiling; // BUILDING FLOOR HEIGHTMAP. // Features same steps as for the ceiling. if (sector.Floor == TR_METERING_WALLHEIGHT) { sector.FloorPenetrationConfig = TR_PENETRATION_CONFIG.Wall; } else if (trRoom.Sectors[i].RoomBelow != 0xFF) { sector.FloorPenetrationConfig = TR_PENETRATION_CONFIG.Ghost; } else { sector.FloorPenetrationConfig = TR_PENETRATION_CONFIG.Solid; } sector.FloorCorners[0][0] = sector.IndexX * TR_METERING_SECTORSIZE; sector.FloorCorners[0][1] = sector.IndexY * TR_METERING_SECTORSIZE + TR_METERING_SECTORSIZE; sector.FloorCorners[0][2] = sector.Floor; sector.FloorCorners[1][0] = sector.IndexX * TR_METERING_SECTORSIZE + TR_METERING_SECTORSIZE; sector.FloorCorners[1][1] = sector.IndexY * TR_METERING_SECTORSIZE + TR_METERING_SECTORSIZE; sector.FloorCorners[1][2] = sector.Floor; sector.FloorCorners[2][0] = sector.IndexX * TR_METERING_SECTORSIZE + TR_METERING_SECTORSIZE; sector.FloorCorners[2][1] = sector.IndexY * TR_METERING_SECTORSIZE; sector.FloorCorners[2][2] = sector.Floor; sector.FloorCorners[3][0] = sector.IndexX * TR_METERING_SECTORSIZE; sector.FloorCorners[3][1] = sector.IndexY * TR_METERING_SECTORSIZE; sector.FloorCorners[3][2] = sector.Floor; } #endregion #region Lights room.Lights.Resize(trRoom.Lights.Length, () => new Light()); for (var i = 0; i < trRoom.Lights.Length; i++) { var l = room.Lights[i]; var tl = trRoom.Lights[i]; l.LightType = tl.LightType; l.Position = tl.Position.ToVector3(); if (l.LightType == LightType.Shadow) { l.Colour[0] = -(tl.Color.R / 255.0f) * tl.Intensity; l.Colour[1] = -(tl.Color.G / 255.0f) * tl.Intensity; l.Colour[2] = -(tl.Color.B / 255.0f) * tl.Intensity; l.Colour[3] = 1.0f; } else { l.Colour[0] = tl.Color.R / 255.0f * tl.Intensity; l.Colour[1] = tl.Color.G / 255.0f * tl.Intensity; l.Colour[2] = tl.Color.B / 255.0f * tl.Intensity; l.Colour[3] = 1.0f; } l.Inner = tl.R_Inner; l.Outer = tl.R_Outer; l.Length = tl.Length; l.Cutoff = tl.Cutoff; l.Falloff = 0.001f / l.Outer; } #endregion #region Portals room.Portals.Resize(trRoom.Portals.Length, () => new Portal()); for (var i = 0; i < room.Portals.Count; i++) { var trp = trRoom.Portals[i]; var p = room.Portals[i]; var rDest = world.Rooms[trp.AdjoiningRoom]; p.Vertices.Resize(4); // in original TR all portals are axis aligned rectangles p.DestRoom = rDest; p.CurrentRoom = room; p.Vertices = trp.Vertices.Reverse().Select(x => x.ToVector3() + room.Transform.Origin).ToList(); p.Centre = p.Vertices.Sum() / p.Vertices.Count; p.GenNormal(); // Portal position fix // X_MIN if(p.Normal.Normal.X > 0.999f && (int)p.Centre.X % 2 != 0) { p.Move(Vector3.UnitX); } // Y_MIN if (p.Normal.Normal.Y > 0.999f && (int)p.Centre.Y % 2 != 0) { p.Move(Vector3.UnitY); } // Z_MAX if (p.Normal.Normal.Z < -0.999f && (int)p.Centre.Z % 2 != 0) { p.Move(-Vector3.UnitZ); } } #endregion #region Room borders room.BBMin.Z = trRoom.Y_Bottom; room.BBMax.Z = trRoom.Y_Top; room.BBMin.X = room.Transform.Origin.X + TR_METERING_SECTORSIZE; room.BBMin.Y = room.Transform.Origin.Y + TR_METERING_SECTORSIZE; room.BBMax.X = room.Transform.Origin.X + TR_METERING_SECTORSIZE * room.SectorsX - TR_METERING_SECTORSIZE; room.BBMax.Y = room.Transform.Origin.Y + TR_METERING_SECTORSIZE * room.SectorsY - TR_METERING_SECTORSIZE; #endregion #region Alternate room // alternate room pointer calculation if one exists. room.AlternateRoom = null; room.BaseRoom = null; if(trRoom.AlternateRoom.IsBetween(0, tr.Rooms.Length, IB.aIbE)) { room.AlternateRoom = world.Rooms[trRoom.AlternateRoom]; } #endregion }