• Editor
  • BB position like in SPINE

Hi

I have another problem with BB. It's supposed to look like in spine:

Image removed due to the lack of support for HTTPS. | Show Anyway

But after loading into libgdx its look like this:

Image removed due to the lack of support for HTTPS. | Show Anyway

The polygon is not in place and it's not even look like polygon from SPINE.

Here is code what I'm using:

 for (Slot slot : skeleton.getSlots()) {
                	if (slot.getAttachment() != null){
                	String s = slot.getAttachment().getName();

            	if ( s .equals("bbnoga")){
            	     testB = (BoundingBoxAttachment)slot.getAttachment();
            	     testB.getVertices();
 		   
            	     boxPoly = new PolygonShape();
                         boxPoly.set(testB.getVertices());
                     
                     BodyDef boxBodyDef = new BodyDef();
                     boxBodyDef.type = BodyType.StaticBody;
               
                     test = swiat.createBody(boxBodyDef);
                     test.createFixture(boxPoly, 0);

                     boxPoly.dispose();                      
            	}
            	}
            	
            }

It's very simple with no position of BodyDef. I have tryied to set it up but also with no luck.

Related Discussions
...

PolygonShape may be limited to convex polygons. How does the debug renderer look? See how SkeletonBounds uses BoundingBoxAttachment#computeWorldVertices.

Yes you have right it must to be convex polygons.
For the position of polygons I still have a problem. I have tried to do it in this way:

                    for (Slot slot : skeleton.getSlots()) {
                	if (slot.getAttachment() != null){
                	String s = slot.getAttachment().getName();

            	if ( s .equals("bbnoga")){
            		 testB =	(BoundingBoxAttachment)slot.getAttachment();
            	         testB.getVertices();

                    float[] polygon = new float[testB.getVertices().length];
                    testB.computeWorldVertices(skeleton.getX(), skeleton.getY(), slot.getBone(), polygon);
                    
                     boxPoly = new PolygonShape();
                     boxPoly.set(testB.getVertices());
                     
                     BodyDef boxBodyDef = new BodyDef();
                     boxBodyDef.type = BodyType.StaticBody;
             
                   //  EVEN i TRY TO POSITION BodyDef IT'S STILl wrong
                  // boxBodyDef.position.x = skeleton.getX() + slot.getBone().getWorldX() ;
                  //  boxBodyDef.position.y = skeleton.getY() + slot.getBone().getWorldY() ;
         
                     test = swiat.createBody(boxBodyDef);
                     test.createFixture(boxPoly, 0);
                     boxPoly.dispose();
                    
            	}
            	}
            	
            }

what do you mean

How does the debug renderer look?

How to turn it on?

My polygon after computeWorldVertices is set to:

Image removed due to the lack of support for HTTPS. | Show Anyway

debugRenderer.draw(skeleton); // Draw debug lines.
It was my firs shot, but I got this:

Image removed due to the lack of support for HTTPS. | Show Anyway

I got it! My mistake 🙁 I didn't have skeleton.updateWorld Transform(); before my code only in the render metod.

Still don't know what is going on with the debug renderer

Nice! 🙂

SkeletonRendererDebug has a ShapeRenderer. You'll need to configure it to draw like your SpriteBatch. You can do this:

debugRenderer.getShapeRenderer().setProjectionMatrix(batch.getProjectionMatrix());

Ok. I have tried both ways:

 debugRenderer2.getShapeRenderer().getProjectionMatrix().set(camera.combined);
 debugRenderer2.getShapeRenderer().setProjectionMatrix(kartka.getProjectionMatrix());

My debugRenderer2 have the same ProjectionMatrix as SpriteBatch but Result is still the same 🙁

Translation matrix too? I'm not sure. It works in SkeletonTest..

Translation matrix? did you mean TransformMatrix? Transform is also the same.

Here you can see the sprite batch and SkeletonRendererDebug have the same projectionMatrix

Image removed due to the lack of support for HTTPS. | Show Anyway

to me it looks like it's drawing the debug mesh multiple times.

I have found where is the problem. After loading .Json I set the Scale and the scale causing the problem. The green dots are not scale properly:

Image removed due to the lack of support for HTTPS. | Show Anyway

Is there any workaround from this?

 atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy.atlas"));
 SkeletonJson json = new SkeletonJson(atlas); 
  json.setScale(0.02f); // scale

I added setScale to the debug renderer.

Thanks Nate! it's working perfectly 🙂

Image removed due to the lack of support for HTTPS. | Show Anyway

Nate I still need your help to position the BB in the right place in the render metod. After I setTransform of the body the BB is offset a lot:

           	
state.update(Gdx.graphics.getDeltaTime());
state.apply(skeleton); 
skeleton.updateWorldTransform();
.
. /// get the slot of BB
.
                float x = skeleton.getX() + slot.getBone().getWorldX();
           	float y = skeleton.getY() + slot.getBone().getWorldY();
           	float rotation = slot.getBone().getWorldRotation()  ;
           	test1.setTransform(x, y, rotation * MathUtils.degRad);

Image removed due to the lack of support for HTTPS. | Show Anyway

Like region attachments, the origin of the bounding box vertices is the bone position. Ie, when the bounding box vertices are rotated or scaled, the do so around the bone position. What is the origin you are using?

I've read and re-read your comment a couple of times and I don't understood what you mean about the "What is the origin you are using?". Also search the forum for similar problems with no explanation or how to do it right. Nate can you give an example?

I assumed that if I get the right bone then it's suppose to be simple like:

float x = skeleton.getX() + slot.getBone().getWorldX();

I've get the slot of BB then for that slot I get the bone and his WorldX

The WorldX and WorldY of the bone is orgin?
For the body (com.badlogic.gdx.physics.box2d.Body) I can only use set transform. Do I must to rewrite it's all vertices or made new polygon fixture?

Say you have a bone with a bb. The bb is positioned relative to the bone, we'll say at 10,10. Now the bone rotates 45 degrees. The bb needs to rotate 45 degrees, but the origin of the rotation is the bone, which is 0,0 in bone's local coordinates.

My question was, when you rotate the body, around what point does the rotation occur (this is the origin). It looks like the position specified in setTransform is the origin for the rotation.
http://www.learn-cocos2d.com/api-ref/1. ... 9c706eca11
If that is true then it should be ok. You could check it by increasing the rotation each frame and see what point the bb spins around. 🙂

It can be difficult since if you don't have things exactly right, you have them completely wrong. Try a simpler example. Create a skeleton with one bone that has a region attachment and a bb attachment. Set the bone's rotation to 0 and scale to 1,1. Run it in your app and make sure the bb is in the right place. Next, rotate the bone 30 degrees and see if it is in the right place. If it isn't, try to figure out why. Is it rotating the wrong way? Is it off by 90 degrees? Is it rotating around the wrong point?

It's rotating around yellow dot from the picture and I think this is the origin. The position i wrong see the pic.

Image removed due to the lack of support for HTTPS. | Show Anyway