Nate

Your lines should not all come from 0,0. The lines show where the bones are. It should look like this:

I think it makes sense to draw your lines before working about the images.
Аватара пользователя
Nate

Nate
  • Сообщения: 9853

evs

@terrymisu

In Gideros it was just:
image:setAnchorPoint(0.5, 0.5)
I suppose in Python would be something like:
anchorX = slot.attachment.u2 - slot.attachment.width / 2
anchorY = slot.attachment.v2 - slot.attachment.height / 2

screen.blit(slot.attachment.texture, (anchorX, anchorY))
cheers

evs
Аватара пользователя
evs
  • Сообщения: 27

terrymisu

So, I got a little frustrated with the bone/slot/rotation stuff, and I went ahead and got the color processing working. I had a few things that I missed, and I wasn't properly extracting the colors from the animation file.

Now I'm back to working on Shiu's suggestion of getting the slot/bone stuff working first, however, I think I've got everything right but the rotation (could be wrong, but it's worth asking, right?).

So, two questions:

* Does this skeleton look right, sans rotation? I noticed that his eyes and head are actually properly textured... and when the eyes blink, they're in the correct spot. Everything else also looks like it's in the proper location, including the root bone, legs, arms, etc... they're just not rotated properly?

* Any ideas why the hair is pink instead of orange, or whatever? Thoughts on debugging this?

His torso is missing here, but it shows up sometimes. I think someone else mentioned both the hair color and the torso issue in a previous post.



[edit]

Here's an image with the torso, for posterity:



The root bone is at 320x240.
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

Nate

It's quite a pain eh? :bang: Note the bone for the eyes is the same as for the head. Here's a screenshot for the un-animated Spineboy skeleton showing where you should expect the bones to be drawn.



I'd forget about images for now and just draw lines for the bones. Start by just drawing a circle for each bone world position. If your bone transforms are correct (and taking into account y-up/down) then you'll get positions like in the screenshot. Next try drawing the bone lines. When you get the rotation right, it'll look like the screenshot. This should help a lot when rotating the images.
Аватара пользователя
Nate

Nate
  • Сообщения: 9853

terrymisu

Nate писал(а):It's quite a pain eh? :bang: Note the bone for the eyes is the same as for the head. Here's a screenshot for the un-animated Spineboy skeleton showing where you should expect the bones to be drawn.



I'd forget about images for now and just draw lines for the bones. Start by just drawing a circle for each bone world position. If your bone transforms are correct (and taking into account y-up/down) then you'll get positions like in the screenshot. Next try drawing the bone lines. When you get the rotation right, it'll look like the screenshot. This should help a lot when rotating the images.
Haha, yes, it is a pain, but it feels so close... ;)

Thanks for the still image. That will help.
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

Nope, bones don't look right.

I guess I'll need to start looking in the BoneData class? [Edit] Errr... Bone class. ;)

Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

I can't get my root bone to draw properly. My Y is set to -240, which is obviously wrong. I can't see anything different between my Bone class and Corona's, and Corona isn't using FlipY, so I don't think I should use that either, correct?

What else might be causing the root bone's location to be flipped, if not something in the Bone class? Hrm.
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

:-O

'm01': -0.0,

Seriously? I didn't know Python had a concept of a negative 0. That's problematic.
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

Chounard

Does pygame work in radians or degrees? The numbers from Spine are in degrees, which I overlooked at first.

Another thing that took me awhile, was to figure out how to calculate the attachment rotation. (I'm working in C++, but in quads, not vertices, so I had to reference the corona runtime to figure it out.)

My final rotation looks like this: (Note the negation at the front.)
-(slot->bone->worldRotation + rotation) * 3.14159f / 180.0f
Аватара пользователя
Chounard

Kickstarter Backer
  • Сообщения: 50

terrymisu

Does anyone know whether Corpna's. image rotation functions rotate clockwise or counter-clockwise?
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

Chounard писал(а):Does pygame work in radians or degrees? The numbers from Spine are in degrees, which I overlooked at first.

Another thing that took me awhile, was to figure out how to calculate the attachment rotation. (I'm working in C++, but in quads, not vertices, so I had to reference the corona runtime to figure it out.)

My final rotation looks like this: (Note the negation at the front.)
-(slot->bone->worldRotation + rotation) * 3.14159f / 180.0f
Hmmmm

I'm using math.radians() and I've quadruple checked my code against both Corona and C++ in terms of the mathematics.

But Pygame rotates counter-clockwise so I am wondering if that is different than other graphics libraries?

It looks like I've got an inversion happening on my Y-axis somewhere, so I'm trying to track that down. My root bone isn't in the right spot.

I've set my system up with x = 320, y = 240 but when the drawing code gets ahold of things the bone is at 320, -240.
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

Pygame uses degrees to rotate, so I think this is fine.
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

Still struggling with my root bone.

I've been combing through the code trying to figure out what's going on.

Here's the main initialization code and loop:
skeleton.flipX = False
skeleton.flipY = False
skeleton.setToBindPose()
rootBone = skeleton.getRootBone()
rootBone.x = 320
rootBone.y = 240
skeleton.setRootBone(rootBone)
skeleton.updateWorldTransform()

clock = pygame.time.Clock()
animationTime = 0.0

done = False

while not done:
clock.tick(60)
animationTime += clock.get_time() / 1000.0
animation.apply(skeleton=skeleton,
time=animationTime,
loop=True)
screen.fill((0, 0, 0))
skeleton.draw(screen, 0)
pygame.display.flip()
pygame.quit()
Here's my debug code for drawing the bone circles:
if self.debug:
for bone in self.bones:
if not bone.circle:
bone.circle = Circle(0, 0, 3)
bone.circle.x = int(bone.worldX)
bone.circle.y = -int(bone.worldY)
bone.circle.color = (0, 255, 0)
pygame.draw.circle(screen,
bone.circle.color,
(bone.circle.x, bone.circle.y),
bone.circle.r,
3)
When this debug code gets used, the bone.worldY is 240, so it gets flipped to -240 and my circle draws off screen.

This is exactly how Corona does it, so I can only assume that I've got something messed up somewhere that is supposed to be making bone.worldY negative before this drawing routine, but it's not happening.

Any ideas? I can't seem to figure out what's going on.
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

Nate

You don't need skeleton.setRootBone(rootBone). Doesn't help your problem though. I would not apply the animation until your are drawing the skeleton correctly.

Is 0,0 in the lower left corner of the screen? If so, then you have a y-up coordinate system like the libgdx runtime. Is 0,0 in the upper left corner of the screen? If so, then you have a y-down coordinate system like the Corona runtime.

If the negation is wrong, take it out. You might try not loading the bones from the file. Create a second bone parented to the root. Get those two bones to draw correctly with just translation, without any rotation and with scale at 1,1. Then add some rotation and make sure the two bones are in the correct place. Then go back to loading the skeleton from a file.

I would jump in the code and help out, but I'm swamped with other stuff at the moment. I've had a lot of non-coding stuff to get done and it's stressing me out, both that those tasks aren't finished and that I haven't been coding so I'm not making progress on the Kickstarter goals. :doh:
Аватара пользователя
Nate

Nate
  • Сообщения: 9853

terrymisu

Thanks for the suggestions Nate. I realize you're super busy and I really appreciate all of your help.

I did figure some things out. ;)

I realized that the Corona runtime is actually setting skeleton.x and skeleton.y, while C++ is setting the root bone coordinates.

Both are setting these to positive values. I missed the fact that Corona is *NOT* actually setting the root bone coordinates, which means that when the root bone gets drawn, it is drawn at 0, 0 relative to skeleton.x, skeleton.y... doh... and since C++ uses flipped coordinates, setting the root bone to a positive value will cause it to get flipped with is The Right Thing™ for the SMFL runtime.

So... one mystery solved. :-)

I've added an x, y to my own skeleton class, and now I'm drawing things relative to its x, y.

I hate to be optimistic, but my pose looks 100% correct compared to the Corona bone points *EXCEPT* for the arm bone locations! :/



Is this another red herring, or does this actually help?

As for your other suggestion, I did a simple test where I created a root bone, and 4 other bones with a length of 10 and coordinates of:

(10, 10), (-10, 10), (10, -10), (-10, -10)

All of those bone points check out. I tested them one at a time. My drawing looks like:



I also plugged this into a test skeleton file and tested those one at a time... they draw correctly.

Any thoughts?
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

Nate

Good progress! :) Do more tests with simple bones. Rotate the root, do the 4 children rotate correctly? Add more debug drawing, draw lines for the bone lengths.

These guys say they have Spine in Python, but I can't find the code:
http://ignifuga.org/
Аватара пользователя
Nate

Nate
  • Сообщения: 9853

terrymisu

Since I'm currently only drawing the first frame of the skeleton at bone.worldX, -bone.worldY, shouldn't the arm placements be correct, or is there something that happens in the initial setup that could cause these to be off?

I'm not currently doing any rotation or anything like that... do I need to do that for these circles? I just drew them at bone.worldX, -bone.worldY.

This is what the Corona runtime seems to be doing, and the bones are all correct... so why are my arms broken?

I'll play some more, but it sounds like you're saying I'm on the right track...? ;)

Thanks for the link to the other library. I'll take a look.
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

I redrew the children in different colors to visualize what was happening.

When I add a positive rotation to the bones (self.bones[0].rotation += 10), they rotate counter-clockwise.

Is this the expected behavior?
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

It looks like children of children bones are properly rotating:

Initial state:



Rotated state:



Assuming additive rotation should cause counter-clockwise motion, this should be doing what it's supposed to?
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

Aha... something looks wrong with my rotation.

Starting point (looks good):


And once I start rotating:

Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

Nate писал(а):These guys say they have Spine in Python, but I can't find the code:
http://ignifuga.org/
I don't see the code in their repo. Maybe it's unreleased.

Could be wrapping C++ maybe. Thought about doing that myself, but I like the idea of a pure Python implementation. It'll Just Work™ on Windows, Linux, OS X. :-)

Well, that is, if I can ever get it to work. ;)
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

HAH!

Found it.

*grumble*
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

terrymisu писал(а):HAH!

Found it.

*grumble*

def setToBindPose(self):
@@ -34,7 +37,7 @@ class Bone(object):
self.worldY = self.x * self.parent.m10 + self.y * self.parent.m11 + self.parent.worldY
self.worldScaleX = self.parent.worldScaleX * self.scaleX
self.worldScaleY = self.parent.worldScaleY * self.scaleY
- self.worldRotation = self.parent.rotation + self.rotation
+ self.worldRotation = self.parent.worldRotation + self.rotation
Teehee. ;)
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

Hahaha... Still have a few kinks to work out:

Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136

terrymisu

Love those Neanderthal eyes though!
Аватара пользователя
terrymisu

Kickstarter Backer
  • Сообщения: 136


Вернуться в Editor