Monogame wp8 + Bepu

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
XaMMaX
Posts: 5
Joined: Sun Aug 04, 2013 7:31 pm

Monogame wp8 + Bepu

Post by XaMMaX »

Hi!

I'm trying to port my xna game to monogame but can't add Bepu dlls and no luck with nuget command. All I have is visual studio express 2013 for windows phone. It seems I need specific dll for wp8 platform but where can I find it? I also found monogame fork but can't get my head around how to use it. I tryed just add all source files from BEPUphysics(from the fork) folder to my project but I got a lot of errors and there is no BEPUutilities source files in fork. There should be some people who compiled bepu for wp8 platform in dll from fork or something, no? Sorry if i'm not understanding it's correctly.

Thanks!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Monogame wp8 + Bepu

Post by Norbo »

My precompiled/nuget releases are pretty lazy; I just put up the primary desktop version and rely on compiling from source for the corner cases. Further, The "monogame" fork is unofficial and actually just appears to be a snapshot of a version from over 2 years ago. I would recommend starting from the main source: https://bepuphysics.codeplex.com/SourceControl/latest

That said, the BEPUphysics, BEPUutilities, and BEPUik projects in the latest source are independent from XNA and can mostly be carried over to other platforms as-is.

There may be some issues related to threading, depending on the available platform threading apis. This came up a few times with WinRT attempts. Worst case scenario, you can just delete the incompatible IParallelLooper implementations and either supply your own IParallelLooper for multithreaded execution (e.g. using some standard threadpool) or just run it single threaded. I don't know off the top of my head what other incompatibilities you might run into going to wp8, but they should be pretty minor. If you run into a specific one, I can probably provide recommendations on how to deal with it.
XaMMaX
Posts: 5
Joined: Sun Aug 04, 2013 7:31 pm

Re: Monogame wp8 + Bepu

Post by XaMMaX »

Thank you Norbo!

I just add both folders to my project, add some namespaces to few variables and it compiles! But I got error on ModelDataExtractor which I got from GettingStartedDemo. I get "Unsupported vertex type in mesh." and I'm loding same mesh from my xna project (same xnb) which worked perfectly with old TriangleMesh.GetVerticesAndIndicesFromModel in xna project. What can I do about it?
XaMMaX
Posts: 5
Joined: Sun Aug 04, 2013 7:31 pm

Re: Monogame wp8 + Bepu

Post by XaMMaX »

Ok, it seems my model had 4 elements(vec3, vec3, vec2, color), so I add another else to extract method but it works. But it doesn't work how it should. I use this model as collusion for firstperson 3d game but I can go through walls right now. Is there a big difference in old GetVerticesAndIndicesFromModel vs new one?

Code: Select all

else if (elements.Length == 4 &&
                    elements[0].VertexElementUsage == VertexElementUsage.Position &&
                    elements[0].VertexElementFormat == VertexElementFormat.Vector3 &&
                    elements[1].VertexElementUsage == VertexElementUsage.Normal &&
                    elements[1].VertexElementFormat == VertexElementFormat.Vector3 &&
                    elements[2].VertexElementUsage == VertexElementUsage.TextureCoordinate &&
                    elements[2].VertexElementFormat == VertexElementFormat.Vector2)
                {
                    var verts = new VertexPositionNormalTexture[meshPart.VertexBuffer.VertexCount];
                    meshPart.VertexBuffer.GetData(verts);
                    for (int i = meshPart.VertexOffset; i < meshPart.VertexOffset + meshPart.NumVertices; i++)
                    {
                        Vector3.Transform(ref verts[i].Position, ref transform, out meshPartVertices[i - meshPart.VertexOffset]);
                    }
                }
XaMMaX
Posts: 5
Joined: Sun Aug 04, 2013 7:31 pm

Re: Monogame wp8 + Bepu

Post by XaMMaX »

In looks like space don't even have my model. I look at space entities count with break points

Code: Select all

space.Add(cameraCapsule); space entities 0
space.Add(AddLevel(scene.geometry.Model)); space entities 1
... space entities 1
In add level I got:

Code: Select all

public StaticMesh AddLevel(Model level)
        {
            Vector3[] vertices;
            int[] indices;
            //TriangleMesh.GetVerticesAndIndicesFromModel(tmp, out vertices, out indices);
            
            ModelDataExtractor.GetVerticesAndIndicesFromModel((Microsoft.Xna.Framework.Graphics.Model)level, out vertices, out indices);
            BEPUutilities.Vector3[] verticesBEPU = new BEPUutilities.Vector3[vertices.Length];
            for (int i = 0; i < vertices.Length; i++)
                verticesBEPU[i] = new BEPUutilities.Vector3(vertices[i].X, vertices[i].Y, vertices[i].Z);
            StaticMesh mesh_level = new StaticMesh(verticesBEPU, indices, new BEPUutilities.AffineTransform(new BEPUutilities.Vector3(0, 0, 0)));
            mesh_level.Sidedness = BEPUutilities.TriangleSidedness.Counterclockwise;
            mesh_level.Material.KineticFriction = 0;
            mesh_level.Material.StaticFriction = 0;
            return mesh_level;
        }
There is no error, nothing.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Monogame wp8 + Bepu

Post by Norbo »

In looks like space don't even have my model. I look at space entities count with break points
A StaticMesh is not an Entity. Entity objects are those which can undergo simulated motion. A StaticMesh can't move; it has no concept of velocity and can't be pushed. It's just a raw Collidable sitting there waiting for stuff to undergo collision detection with it. It's not explicitly stored in any visible list because the engine doesn't make use of any such list.
Is there a big difference in old GetVerticesAndIndicesFromModel vs new one?
Nope; it's pretty similar. Also, that helper function is also not a core part of the engine or anything- you could load things however you'd like, so long as the data is in the right form to give to the engine at the end.

The other issues of being able to go through walls sounds like the graphics don't match the physics. You may want to set up a similar test in the BEPUphysicsDemos using its debug drawer. This would help in determining where things actually are, and what needs to be done to fix the other renderer.
Post Reply