Questions concerning Block Terrain. Physics, animation and mesh creation

Hello,

I’m starting this new topic because I guess it does not fit to the topic where I posted my first question (http://hub.jmonkeyengine.org/groups/general-2/forum/topic/generating-3-d-ridged-multifractual-noise/?topic_page=2&num=15#post-161046)


At first glance, it looks like you are creating faces even when they are never shown (ie: between two solid blocks). That’s a pretty big performance loss since somewhere around half the faces (at least) are hidden in this way.

A relatively straight-forward approach would be to iterate over all of the empty blocks and then the immediate neighbors. Only output faces in the direction of solid neighbors.

Also, collisions on a block world are much less expensive to just do right on the original array data structure. The JME generated collision data will be pretty expensive (creation time and size-wise) in comparison.


I thought a lot about how to improve this espeacially because I just need the surface (no digging in my game). This is really a good advice :)
(Although this method could lose some strength when I hollow the structure out in a way that all blocks that are not next to an air block will be removed. This way I still save the faces between the surface blocks but the face inside the structure where I removed the blocks still stays).

To the collision: Is it relativly easy to combine "normal" collision detection (e.g for the player or monsters)? Although I could imagine to create theire collisionshape as a combination of several boxes. With easy I mean: Is it reasonable for me to do without having to fully understand how the bullet system works?

I really appreciate your (all JMonkey Experts) advices here because I'm still missing the overview how the engine works in collision and animation.

PS: Sry for the late "reply". I seem to have missed your new post in the "latest topics" overview.

Oh, one more question:

If I create just visible faces I don’t know in advance how large my buffers have to be…

Is it possible to shrink them afterwards or how should one solve this problem?

Check out the physics tutorials, it works with any meshes really, self-created ones or loaded.

1 Like

I had the idea whether its possible to use my own mesh for collision, too because they looked exactly the same but I did not remember MeshCollisionShape (Reading the Tutorials is 7 months ago^^). Taht already speeds up everything a LOT. Thank you.



But I am interested especially about how this would work?

Also, collisions on a block world are much less expensive to just do right on the original array data structure.

Also, collisions on a block world are much less expensive to just do right on the original array data structure.


It does depend on the types of collisions that you are doing. For phyiscs, you are probably better of letting JME generate the redundant data than trying to do something fancy.

For things like ray-based picking, etc. you can trivially do that right on the 3D array that denotes your blocks without ever generating a mesh at all.
1 Like

Although I was busy the last days I did what you recommended and my terrain generation including adding it to physics is now much faster :slight_smile:

And @pspeed I guess I would have done that either way because for me the fancy physics stuff like raycasting is still a bit unfamiliar. But thanks for pointing out that this is not dump but in this case maybe the best way to go^^ :wink:



Before I’ll now start digging into generating good looking terrain, I have a wide question about animation (a topic that I did not think much about in the past):



Is it possible to create sth. animated in a program like blender and just import this animation (and the required bones) into JME, with the intention to use it with a collision capsule like in the ragdoll-examples (these cylinders that make arms and maybe a box as chest)?

This way I want to create the limbs-models out of a couple of smaller blocks that form something that looks like the said parts of the body and animate a whole lot of different creatures with the same animation. (Best would be, if that where scalable, so that I could make one entity look stronger than another)



I would be grateful if you could point a tutorial where I can read about that or give me a hint what JME classes to look at. Please keep in mind that my understanding of JME Animations is limited to what the tutorials told me^^

I usually don’t like pushing topics, but maybe my question was overlooked^^



If my question would have been easy to avoid with using google then I will appreciat if you proof me wrong. Sadly I did not found anything specific to JME :frowning:

you were mentioning the exact example that shows what you want to do oO So you were basically asking “i see this working here, but does it work?”

Thank you, your post gave me the right hint although that what was done in TestRagDoll.java is not exactly what I wanted. If someone else should read this, I’ll add my result. If I will get animation properly exported from blender to a skeleton.xml I will probably having another question concerning this topic but I want to increase my knowledge beforehand^^



Code is a little messy from playing around but should be self explaining.

[java]public class SkeletonTest extends SimpleApplication implements ActionListener, AnimEventListener {



private BulletAppState bulletAppState = new BulletAppState();



private Node ragDoll = new Node();

AnimData oto;



private Skeleton skel;

CharacterControl cc;



private CompoundCollisionShape ccs = new CompoundCollisionShape();

private AnimControl animationControl;

private AnimChannel animationChannel;



public static void main(String[] args) {

SkeletonTest app = new SkeletonTest();

app.start();

}



@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(10);

bulletAppState = new BulletAppState();

stateManager.attach(bulletAppState);

bulletAppState.getPhysicsSpace().enableDebug(assetManager);

PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());

setUp();

}



public void setUp() {

oto = (AnimData) assetManager.loadAsset(“assets/models/otos.skeleton.xml”);

skel = oto.skeleton;



animationControl = new AnimControl(skel);

for(Animation a : oto.anims) {

System.out.println(a.getName());

animationControl.addAnim(a);

}

ragDoll.addControl(animationControl);



Bone b;



for(int i = 0; i < animationControl.getSkeleton().getBoneCount(); i++) {

b = animationControl.getSkeleton().getBone(i);

Box bo = new Box(0.1f, 0.3f, 0.1f);

Geometry box = new Geometry(“Box”, bo);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Red);

box.setMaterial(mat);

b.getAttachmentsNode().attachChild(box);

ragDoll.attachChild(b.getAttachmentsNode());

}



cc = new CharacterControl(new CapsuleCollisionShape(3f, 4f), 0.5f);

ragDoll.addControl(cc);



rootNode.attachChild(ragDoll);

bulletAppState.getPhysicsSpace().addAll(ragDoll);



animationChannel = animationControl.createChannel();



}



public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

}



public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {

}



@Override

public void simpleUpdate(float tpf) {

cc.setWalkDirection(new Vector3f(0f, 0, 0.1f));

if(animationChannel != null) {

if(!“Walk”.equals(animationChannel.getAnimationName())) {

animationChannel.setAnim(“Walk”, 0.7f);

animationChannel.setLoopMode(LoopMode.Loop);

}

}

System.out.println(animationChannel.getAnimationName());

}



@Override

public void onAction(String arg0, boolean arg1, float arg2) {

// TODO Auto-generated method stub



}

}[/java]