Right settings in Blender to properly export? [And fracturing!]

wagfliz
Ok, funny but this looks dangerously like if I had to create my model using custom meshes in advance. And what I want is cutting the model imported from Blender. I don’t even want to imagine trying to recreate the model from grounds up using coordinates of every vertex. Impossible work.

destrofyer
Well for Years I learn everything by reverse-engineering. Also I kind of thought we’re talking about engine feature here, not creating this feature myself.

2 Likes

Good reply I must admit. Was thinking of posting this Supernatural scene myself :smile:

Anyway I’ll play with cutting some basic stuff and check if this works for me but still - I expected jMe to have such basic feature by default (I mean every modern game have destruction model - and I’d even say “multiple destruction models”)…

Can You at least tell me if there is a way to pull vertex’es (and their positions), meshes, etc. out of imported spatial?

You can use the destruction feature from blender and import it directly.
There is no game engine that makes such thing at run time, and at build time Jm3 works with blender, there is no 3d modeler in Jm3, the official one is the blender, and it has this feature as vanilla.

@necxelos

Can You at least tell me if there is a way to pull vertex’es (and their positions), meshes, etc. out of imported spatial?

Yes. That was literally the first thing I wrote you in this thread:

You can then just traverse the models vertices (no “predestructed” meshes, the original solid model as it comes out of blender or w/e you’re using) and calculate new partmeshes, interpolate the UVs etc. etc.

@wagfeliz

There is no game engine that makes such thing at run time

Of course you can do it at runtime, no problem. See the video, links and discussion above.

There is no game engine that makes such thing at run time

What I want to say here is that “there is no game engine in the world that provides standard functions to do this in run-time” , you have to do it by hand in any game engine.
I am doing it mylself, I know its possible.
Sorry if I was not clear about it.

wagfeliz
Awesome - checking Blender Cell Fracture right now.

destroflyer
I pretty much understand how this Voronoi fracture would work like:
a) Create 2 (for sake of example) Voronoi points to divide the model,
b) Get a list of all vertex coordinates of a model and split it into 2 lists based on the distance from 2 Voronoi points (closer to A in A, closer to B in B),
d) Get a list of the meshes in model (in XYZ, XYZ, XYZ format) and split it into 2 lists based on the number of vertices closer to A or B (list A would have meshes that have 3 vertices closer to A or 2 vertices closer to A and 1 closer to B),
f) Check which vertices are doubles in both mesh lists and make respective copies of them in 2 lists of vertices,
g) Create model 1 out of list A, create model 2 out of list B,

I kinda missed creating new vertices to fill blanks but I hope that’s the idea. Still without direct access to all vertices and meshes (in XYZ, XYZ, XYZ format) of the model I won’t get anywhere.

If it was so simple I wouldn’t bother You would I?

For starters I don’t even have a mesh. All I got is:
Spatial Trollolo = assetManager.loadModel(“TROLLOLO.j3o”)

The topics out there (including the very top one You gave screenshot for) proved to be perfect example of forcing poor guy to something exactly the way he didn’t want it to do (which is attaching stuff to a bone) so he didn’t get the answer ever (at least not to the question he asked).

As for JDocs I couldn’t find something like:
spatial.getchild(geometry).getvertexlist(xyz)
…the only thing I found is:
getVertexCount
…which is useless. If I had list of all vertices I could calculate how many are there. That doesn’t work the other way.

For starters I don’t even have a mesh. All I got is:
Spatial Trollolo = assetManager.loadModel(“TROLLOLO.j3o”)

You have a perfectly fine mesh there. I mean… this is jme basics… Well, not even basics, that’s how jme works - You don’t even know what the single engine classes mean but want to program fracturing?
A spatial is the abstract class of jmes scenegraph tree structure. An example for a spatial would be a geometry which has a mesh. And by your description, your *.j3o contains a geometry.
This is teached in the beginner tutorial #2: http://wiki.jmonkeyengine.org/doku.php/jme3:beginner:hello_node

The topics out there (including the very top one You gave screenshot for) proved to be perfect example of forcing poor guy to something exactly the way he didn’t want it to do (which is attaching stuff to a bone) so he didn’t get the answer ever (at least not to the question he asked).

If you would’ve scrolled past the first three posts in this thread, you would’ve even found this code snippet to… reverse engineer I guess:

VertexBuffer buffer = geom.getMesh().getBuffer(VertexBuffer.Type.Position);

As for JDocs I couldn’t find something like:
spatial.getchild(geometry).getvertexlist(xyz)

Even with this path, you will end up with:

((Geometry) Trollolo).getMesh().getBuffer(VertexBuffer.Type.Position);

I’ll skip the “I know, I know, I know…” for most of Your lines and just get to the part which isn’t like You think it is.

a) My j3o is just an importet cube from blender. If Spatial Trollolo = assetManager.loadModel("TROLLOLO.j3o") has geometry inside (theoretically it should) I have no idea how to reach it. So everything else that refers to geometry itself is awesome if I knew how to refer to this geometry that I didn’t create (at least not directly).

b) Up until now all I cared about was that my Blender model loads and shows on screen and I can do static stuff to it. So I didn’t really care what’s inside. Now that fracturing comes into play I do. So don’t attack me for not knowing stuff that was of no use to me until now…

So again. Spatial name is all I have now (because I made it). And before You suggest it, getChildren don’t work on it.

[EDIT] System.out.println(Trollolo.getClass()); actually says class com.jme3.scene.Geometry. Yet still I can’t do getMesh method on it…

[EDIT 2] Works now. It’s insane. When I copypasted ((Geometry) Trollolo).getMesh().getBuffer(VertexBuffer.Type.Position); it started working but when I wrote the same line myself code completion won’t even let me find those methods. WTF? -.-

There is information in the tutorial on how to do it, you really should do all tutorials to learn this basics.
To help you to start to understand, follow some basic function :

public static Geometry findGeom(Spatial spatial) {
    if (spatial instanceof Node) {
        Node findingnode = (Node) spatial;
        for (int i = 0; i < findingnode.getQuantity(); i++) {
            Spatial child = findingnode.getChild(i);
            Geometry result = findGeom(child);
            if (result != null) { return result; }
        }
    } else if (spatial instanceof Geometry) {
        return (Geometry) spatial;
    }
    return null;
}

Obs: This functon will only get the first geometry, an spatial can have multiple geometries inside, as well multiples spatials, nodes etc. Hope it helps you to learn this, but you really should do all tutorials.

I was able to get all the Vertices and also modify selected (thus deform my model). So I should also be able to duplicate model and eliminate vertices that I want at some point.

VertexBuffer buffer = ((Geometry) Kostka3).getMesh().getBuffer(VertexBuffer.Type.Position);
VertexBuffer buffer2 = buffer; //I created this with hope that I'll set this buffer to
buffer.getNumElements();

for (int i = 0; i < buffer.getNumElements(); i++) {
    System.out.println(buffer.getElementComponent(i, 0) +""+ buffer.getElementComponent(i, 1) +""+ buffer.getElementComponent(i, 2));
    buffer2.setElementComponent(i, 0, (Float)buffer.getElementComponent(i, 0) * 2); //Increase Size
    buffer2.setElementComponent(i, 1, (Float)buffer.getElementComponent(i, 1) * 2); //Increase Size
    buffer2.setElementComponent(i, 2, (Float)buffer.getElementComponent(i, 2) * 2); //Increase Size
}
buffer2.setElementComponent(3, 0, (Float)buffer.getElementComponent(3, 0) * 2); //Deform 1 triangle

BUT:

  • Any changes applied to my VertexBuffer seem to change all instances of my model, not only the one from which I pulled VertexBuffer. Also changes are applied instantly without me doing Mesh.SetBuffer. Why and how to fight this?

  • (Geometry) Kostka3 I didn’t see this expression ever before. In human language - what it does (I mean I know it allowed me to reach geometry of Kostka3 but why in such strange way)? From what I understand relation between Geometry and Spatial is Parent-Children relation so why getChild doesn’t work?.

  • Also if (in Your example, which I’m gratefull for) spatial is instanceof Geometry then in human language IT IS geometry right? So all methods applying to geometry should work by default with such spatial? Can’t jMonkey check “on the fly” if spatial is an instance of node or gemoetry and allow me (or not) to apply corresponding methods directly to it?

As for the (Geometry) part, you should take a look at Casting in Java - How to Program with Java - Java Cast

You should really learn Java properly before trying to develop a game because we are not here to help you to learn Java.

Yes you would

1 Like

In memories.