- 수정됨
[Cocos2d-x 3.0] Creating bodies & fixtures from meshes
Is there an existing tool that simplifies the process of creating bodies & fixtures in Cocos2d-x 3.0 from meshes? I'm thinking about writing a C++ tool to do this, but would hate to re-invent the wheel.
Also, does the latest 3.2 version of Cocos2d-x support meshes, or is that runtime still being created? Is there a place I can find this out?
Cocos2d-x runtimes rely on the spine-c runtimes which are up-to-date. Cocos2d-x has a wrapper that performs the rendering/updating and it is also up-to-date as far as meshes are concerned.
Because Cocos2d-x uses spine-c, you could conceivably create a c++ tool to generate bodies/fixtures/etc... for a whole slew of runtimes.
Approach 1
I've been thinking about this all day, but I would bet the best approach would be to create a body for each bone with the mesh hulls as the fixtures. The bone positions would be the joint positions and the IK Constraints could give you some hints for the joint properties.
Check out this ground constraint video: viewtopic.php?f=3&t=3318 The SkeletonUtilityConstraints in Unity simply performs an updateWorldTransforms() after the bone is repositioned to resolve the IK constraints. The (simplified) order of operations is something along the lines of:
Apply Animation
UpdateWorld Transforms
Resolve Bone Position <- Your Physics Step
UpdateWorld Transforms (resolving IK) <- probably creating more collisions
render
Approach 2
The other approach would be to create fixtures from all the attachments and make the root bone the physics body. It's simpler, and it solves a lot of other problems, but it would make the animation very static looking, and the IK resolving wouldn't be necessary.
hull
Also, as a hint, the first N vertices in the sp(Skinned)MeshAttachment_ComputeWorldVertices() are the polygon HULL for the mesh, where N is sp(Skinned)MeshAttachment::hullLength. That should make building your fixtures easier.
Are you using Box2d as the engine?
Yeah I'm using Box2d. It's nice to know the runtimes are up to date.
Not sure what approach I'll use as I was hoping someone did it already. I really don't need animations even though it's what Spine was made for. I would like the benefit of polys meshes instead of sprites with lots of empty space. Otherwise I might use simpler tools such as Texture Packer and Physics Editor or RUBE.
Not sure if I'll try to integrate the physics, but thanks for the info.
If you aren't using the animations then you'll be fine just adding all of the meshes as fixtures to a single body. You won't need the (2nd) call to updateWorldTransforms to resolve any IK issues. What you might need to do is grab the position and rotation from the physics body and apply it to the skeleton (root bone).
I don't know if anyone has already got box2d running, this post seems like a good place to start: viewtopic.php?f=7&t=3001&p=14588#p14588
You might event try to get in touch with the OP (Sheado) to see how far they got with it.
Ok, I've read several other threads, went over the Box2d Workshop and read a forum topic on the subject.
I don't think there's a general solution to the problem where you can drop in some code and it just works. From what I've seen there are many different uses and each use has an optimal approach.
I would even go as far as say that it would be beneficial to use an editor that generates hints. Hints that could be serialized.
I think for your specific use, you can just read through this post and get some good information: