Q: Procedural physics mesh generation


Copied from below
PHYSICS MESH ISSUE

So I’ve got the visual mesh manipulation working – I can generate them from scratch :slight_smile: However, I can’t get the object to make a new physics mesh.

When I create a new mesh and put it on an object, it seems that the physics mesh isn’t changed. ie. I have two objects sharing the triangle mesh. I make a new mesh for object 1 and turn it into a pyramid. I then use the reinstancePhysicsMesh() function and Both objects’ physics meshes turn into pyramids! Not what I want to happen. I’ve attached the example so you guys can have a look. (made in 2.5 Beta r32738, 68kb)
[ATTACH]131750[/ATTACH]

If any one has any ideas, much thanks :slight_smile:


Hey there blenderheads, I’ve been searching all over the place for a workable way of manipulating meshes within the game engine – to add and alter polygons.

I want to make a procedurally generated landscape, with the ability to have an arbitrary number of polygons at any one time. This means I can’t resort to the method of just starting with a bunch of polygons and moving them around. Nor can I add a series of polygon game objects and manage them into a shape – I need far too many polygons for this to be a useable solution, which is lame :stuck_out_tongue:

Hopefully there’s a simple solution, (or any solution :P) if so I thank you :slight_smile:

Oh, and I’m also trying to figure out a way of manipulating a mesh which is shared by multiple objects at a per-object level. ie, I have three objects sharing a Cube mesh and I want to move one vertex on one of the cubes. I realise the game engine stores its meshes as a collection and each object refers to a single stored mesh object – I assume I have to create a new instance of each mesh for each object I wish to manipulate but I don’t know how :o

I’d really appreciate any assistance, thanks in advance,

Bluesocarrot

Unless you want to use the bpy or Blender module, you can’t create meshes at runtime. If you want to use those modules, check out this video:

As for creating a new instance of a mesh at runtime, you can do that in 2.5 using the LibNew() function. I actually thought that function was rather pointless, but now I guess is has some purpose. You would probably use it something like this:

# Give each object using the 'mesh' mesh a unique data block

import bge

n = 0
for object in bge.logic.getCurrentScene().objects:
    if object.meshes[0].name == 'mesh':
        bge.logic.LibNew('mesh.%03d'%n, 'Mesh', 'mesh')
        object.replaceMesh('mesh.%03d'%n, usePhysicsMesh=True)
        n += 1

You can free these datablocks using the LibFree() function.

If this doesn’t have to be done at runtime you can simply click the number where you enter the data block’s name (should be next to an ‘F’).

The ideasman solution is quite one of the best(i’m going to use it too), your problem is that generating a mesh is computationally eavy, so with python if you want to manage more than 10k vertices i’ll find infinite lags. There is out there, in the net, a project that procedurally creates entire planets.
Maybe you can find something here http://en.wikipedia.org/wiki/Procedural_generation

Thanks andrew, that code was exactly what I needed. Having them as libraries also makes the job of removing the data far easier, too :slight_smile: I’d looked through those methods, but I couldn’t find any explanation for LibNew – I guess everyone else thought it was pointless too :stuck_out_tongue:

I haven’t seen that video before, but I have come across the code shown in it. He uses a mesh.add_geometry(verts, edges, faces) to add polygons to the mesh but I can’t find the function! D:

Later:
Wait… No probs, found the solution – mesh.from_pydata(verts, edges, faces) and then load that as a library. EPIC! Now I have a way of generating new meshes for each object and altering them in their entirety. Awesome :smiley:

Thanks for all the help :smiley: So good. Gonna make some visualisation systems far easier to work with, all the best mate! :slight_smile:

PHYSICS MESH ISSUE

Ok, so I’ve now got a problem with the physics mesh. When I create a new mesh and put it on an object, it seems that the physics mesh isn’t changed. ie. I have two objects sharing the triangle mesh. I make a new mesh for object 1 and turn it into a pyramid. I then use the reinstancePhysicsMesh() function and Both objects’ physics meshes turn into pyramids! Not what I want to happen. I’ve attached the example so you guys can have a look. (made in 2.5 Beta r32738, 68kb)
wrong physics mesh example.blend (67.5 KB)

If any one has any ideas, much thanks :slight_smile:

So, what you’re saying is that the meshes are acting as one, even though they are seperate? Taking on the same properties except for location (am i right so far?).

Guessing the second is sharing meshes. Make sure each object is its own user (they aren’t sharing meshes).

I looked into something similar I think is quite relevant; record in an array the co-ords of each vertex of a low(er than 10k)-poly mesh (64*64), then iterating over each vertex applying to it the co-ords from your array of the vertex (closest to) the movement vector of the camera applied to your current vertex’ position, then saving in these new co-ords to your array. You would need to also have an extra set of values in the array for the vertices at the edge of the grid to use, these would be calculated using any noise algorithm you like, you could even use a random value algorithm, but this may give poor results.

^If this helps, great (remembeeerrr mee when you implement or even release iiiiit), if not, I shall implement it myself when I’ve finished my current project… (this is my plan for procedural grounds on one mesh (no horrible edges or gaps) :D)

@Wefyb: I’m saying that the two meshes’ physics mesh act as the same thing. If I alter it on one, both meshes change, even though they don’t have the same visual mesh.

@Joeman16: They’re both sharing meshes until I make a new, dynamically loaded mesh for one of them. After that, they’re just sharing a physics mesh. Also, I need to do this stuff at run time or else I have to store hundreds of thousands of individual mesh objects so I don’t think I can make them their own user

@Haker23: I’ve already done that a couple of times :stuck_out_tongue: It was too slow, 'specially in python D: The issue I’m having is in making new meshes and physics meshes for objects. This is for more than just use in generating the world. Imagine making one tree model and then applying an algorithm which changes the number of branches, leaves, changes the colour and changes the position and orientation of each of these things. You’d never have two trees the same! A never-repeating forest made of a single tree :smiley: There are many applications, but I can’t get this silly thing to work :frowning:

Reloading the mesh updates the physics mesh.