Changes to the particle monkey code

I made some changes to the particle monkey code to get the desired effect

I read most of the particle monkey code to get a rudimentary understanding of particle monkey.

I made the following modifications to Particle Monkey to make Particle monkey more suitable for me.

	/**
	 * Set the current particle emission face to the specified faces index
	 * @param triangleIndex The index of the face to set as the particle emission point
	 */
	public void setNext(int triangleIndex) {
		Mesh m = mesh.getMesh();
                
//		Transform transform = emitFromWorldSpace ? mesh.getWorldTransform()
//				                                     : mesh.getLocalTransform();
//		m.getTriangle(triangleIndex, p1, p2, p3);
//		transform.transformVector(p1, triStore.get1());
//		transform.transformVector(p2, triStore.get2());
//		transform.transformVector(p3, triStore.get3());
//		triStore.calculateCenter();
//		triStore.calculateNormal();
                if(emitFromWorldSpace){
               //mesh.setIgnoreTransform(false);
                Transform transform = mesh.getWorldTransform();
                m.getTriangle(triangleIndex, p1, p2, p3);
		transform.transformVector(p1, triStore.get1());
		transform.transformVector(p2, triStore.get2());
		transform.transformVector(p3, triStore.get3());
                }else if(!emitFromWorldSpace){
             // mesh.setIgnoreTransform(true);
                Transform transform = mesh.getWorldTransform();//mesh.getLocalTransform();
                
                transform.setRotation(mesh.getLocalTransform().getRotation());
                transform.setTranslation(mesh.getLocalTransform().getTranslation());
                
                m.getTriangle(triangleIndex, p1, p2, p3);
		transform.transformVector(p1, triStore.get1());
		transform.transformVector(p2, triStore.get2());
		transform.transformVector(p3, triStore.get3());
                
                }
                triStore.calculateCenter();
		triStore.calculateNormal();
	}

I found that the particle’s Transform completely follows the EmitterMesh.
My EmitterMesh is a model.

The model was loaded in a node which caused the particle generation to be somewhat different from what was expected.

Can I submit my changes to Particle Monkey?

What do I do to get the EmitterMesh’s Transform to appear in the right place if I can’t commit a change?

(If you have any questions about my questions, please point them out)

(I hope the administrator can help me classify correctly. Thank you very much)

Thanks to yaRnMcDonuts for their help

1 Like

What are you trying to fix? All my test cases show this working correctly right now.

2 Likes

On the Transform problem of EmitterMesh

If emitterMesh setEmitFromWorldSpace (false) Then the particle will be in the wrong place,
I described the problem here.

emitterMesh setEmitFromWorldSpace (false)
The particles were in the wrong place ,You can see it in the video
So I changed the code.

My English is not very good, I seem to have failed to make you understand very sorry :sleepy:

This video is the modified code

So it looks like it is a scaling issue?

1 Like

It should be :face_with_raised_eyebrow:

I don’t know how to translate it to make my description seem professional and easy to understand…

But I think so, as you understand it

Okay, I just tested this out in my examples project and the model scaling seems to be working fine so it’s something about your model’s hierarchy. Could you give me the layout of the nodes / spatial / geometry in your character model and the transforms for each?

model = ((Node)((Node)((Node)simpleApp.getRootNode().getChild("character")).getChild("Scene")).getChild("Bip001"));
    Geometry geometry=(Geometry)model.getChild("网格.004");

    emitterMesh=new EmitterMesh(geometry);

I use this code to get the EmitterMesh

((Node)((Node)((Node)simpleApp.getRootNode().getChild("character")))).attachChild(emitter);

Add emitter through this code

image
Structure in scene

I added the scene to the character Node

For the scene structure, could you give me the scale for each of those nodes?

That file doesn’t work correctly for me and it won’t properly extract.

What about gltf files?

This j3o file is converted from gltf to j3o, via the sdk

That would be fine. I can convert it myself and look at the structure.

I guess that’s what you want

There should be complete content in gltf

Yup, that helps! So the correct thing to do here is probably just to add the emitter to Bip001 instead of Scene. That way particle monkey picks up the scale correctly.

1 Like

So if I put emitter in Bip001 it looks like this


I don’t understand why the emitter I added to Bip001 is not aligned with the model?

The code to place the debug emitter shape isn’t correct and doesn’t update over time at the moment.

1 Like

I looked at the particles and they didn’t seem to be coming out in the right places.


Normally, particles should be generated around the emitter rather than at a single point.
Is that the expected error?
These are the problems I had when I added the transmitter to Bip001.
If I put emitter in character(Node) then everything would be fine.

No, I was talking just about the debug shape. I didn’t even see the particles in the first screenshot. There is something about the hierarchy of the model which is causing a problem but I don’t know what it is without being able to open the actual model.

1 Like

What do I need to provide? model file? Or something else?

	public Spatial getDebugShape(Material mat, boolean ignoreTransforms) {
		Geometry geometry = new Geometry("DebugShape", mesh.getMesh());
		geometry.setMaterial(mat);
		//geometry.setLocalTransform(mesh.getWorldTransform().clone());
		//geometry.setIgnoreTransform(ignoreTransforms);
		return geometry;
	}

//geometry.setLocalTransform(mesh.getWorldTransform().clone());
I removed this code emitter debug seems to be working…

I don’t know if this makes sense
Because I don’t know why you want to add geometry. setLocalTransform (mesh. getWorldTransform(). clone ()) in getDebugShape; This code