3D model support

cocos2d-x wants to support 3d models. Then you can load 3d models in your game.
What format of 3d models do you want?
How to use 3d models? Like CCSprite?

What i think now are:
* supporting formats
*** OBJ
*** 3DS
*** MD2?
I am not sure if it is needed. It is supported now, you can refer to Jame’s repo https://github.com/dumganhar/cocos2d-x/tree/3d-model.
Run HelloCpp demo.
*** COLLADA
It is text-based, we should have our own binary format.
* how to use it

// draw static 3d model
MD2 *md2 = MD2::create("xxx.md2");
md2->setSkin("xxx.png");
CCSprite3D *sp = CCSprite3D::create(md2);
sp->setPosition(x, y);
addChild(sp);

// animation
CCAnimate3D *animate = CCAnimation3D(duration, start frame, end frame);
sp->runAction(animate);

Any suggestions?
I am not sure if there should be a duration for 3d model animation, may be it should run action all the time until being stopped.

Any one has any suggestions?

This improvement looks soo cool Minggo.

I like the way of creating and using a model, it looks pretty simple and easy to understand.

Some suggestions:

  • The advantage of MD3 and MD5 is that there are a lot of models out there (I think doom models and from some other games). But I think it would be more important to support more modern formats like FBX.
  • What about setting up the camera and its Z value? Or we will use the scale to simulate the z position and size of the model?
  • Any possibility in regards to play animations. I’m not talking about CCActions, but about keyframe based animations based on the 3D bones and so on. I don’t know if you were talking about the same kind of animations

Best,

Jesús

Does not make sense at all for a 2D framework.

Herman, it makes perfect sense for a 2D framework. You can still make a space shooter, all in 2D, but with 3D spaceships for better visuals. You retain the simplicity of working with a 2D framework, but you get the benefit of better visuals.

I have done quite a bit of 3D stuff in the past, and I would avoid COLLADA or FBX for the start. OBJ is a great choice, because it is very easy to implement and very universal. I almost implemented this in cocos2dx for my current project but decided I didn’t have time :slight_smile: The downside of OBJ is lack of keyframe/bone animation support. Once you have OBJ I think COLLADA would be the next best choice because it’s a growing standard.

Ambitious idea, and a potential to open a big can of worms. I agree that OBJ support would probably be the place to start, aware that it is a ‘bloated’ model, but it is still supported in every 3d design application.

I understand we’re keeping the 2D perspective, but what is the approach for collision handling in the physics libraries (Box2d, chipmunk), a model can end up being very complex, (large empty spaces, rotation, etc) which may make collision handling tough.

Regardless, sounds good. Maybe I can start swapping my unity work for cocos2dx.

John Atherton wrote:

Herman, it makes perfect sense for a 2D framework. .

I would render high-res spaceships in a 3D renderer and use them as 2D bitmaps Makes sense when your camera does not move.

Herman Jakobi wrote:

John Atherton wrote:
> Herman, it makes perfect sense for a 2D framework. .
>
I would render high-res spaceships in a 3D renderer and use them as 2D bitmaps Makes sense when your camera does not move.

But then what about lighting effects? When the enemy ships fire an plasma ball that whizzes past, it would be cool to show the light reflecting off your ship. There are advantages to 3D models that are totally impractical with 2D pre-rendering.

I understand your reservations for this… adding 3D to a 2D engine can make things complex very quickly. And why not just go to a 3D engine for 3D effects?

My experience with 3D engines (and I have not yet used Unity) has been that they are well designed for full 3D games (especially FPS), but it’s a pain to make 2D gameplay with them (I’m not talking about art here, but the actual space the game takes place in). Also, I really like the structure of cocos2dx and have found other game engines to be less intuitive, so it would painful to move to a different engine.

Believe what you want, but I can see advantages to supporting 3D models in a 2D engine.

John Atherton wrote:

Believe what you want, but I can see advantages to supporting 3D models in a 2D engine.

You should see the Cocos2d 2.0 tech demo with the 2d cars & lighting shaders. Don’t have the link now but Google it.

Anyway.

When I need 3D I use a 3D engine. The physics should support 2D plane optimization of course.

`Jesus Bosch

The advantage of MD3 and MD5 is that there are a lot of models out there (I think doom models and from some other games). But I think it would be more important to support more modern formats like FBX.
I think we can support simple format at first. Then we let developers to determine which format is needed. Of course, if you think some format is important, you are appreciated to send a pull request.
What about setting up the camera and its Z value? Or we will use the scale to simulate the z position and size of the model?
I think we should setting up a camera and its Z value. But now i haven’t maken it work correctly with current mechanism.
Any idea?
Any possibility in regards to play animations. I’m not talking about CCActions, but about keyframe based animations based on the 3D bones and so on. I don’t know if you were talking about the same kind of animations
CCAnimate3D is used for animations. You can set start and end frame, then it will play animations for you.
Did you have any suggestions to play animations?

`John Atherton
Yep, we will support OBJ at first. Since COLLADA is text-based format, so we should have our own binary format to support it.
Any suggestions?

@Michael Developer
What we want is just load and show 3d models. If we want to support collision in the physics libraries, it will make things complex.
What’s your opinion?

A separate class to control the camera and the lighting will be nice.

As for animations:

  • Ability to control separate bones
  • Ability to play animations stored in the model file itself
  • Ability to use “motion files” that contain animation information so that one motion file can be used to animate a number of models. For example, a generic “walking” animation can be stored in a motion file and apply that motion file into different models on the screen.

There is CCCamera, so i think it can be used to control the camera.

  • Ability to control separate bones
    Not all model has bones. So it is model specific. How about using model object to control separate bones?
  • Ability to play animations stored in the model file itself
    Sure.
  • Ability to use “motion files” that contain animation information so that one motion file can be used to animate a number of models. For example, a generic “walking” animation can be stored in a motion file and apply that motion file into different models on the screen.
    How to generate “motion files”? Did you mean that some model format support it?

cocos2dx supporting 3D scenes would be great!

One could have a 3D scene and cocod2dx for the game flow (helps, setting, etc) and HUD.

This could happen incrementally, for example, in one version we could have a basic CCLayer3D, CCCamera3D, CCModel3D, etc.

CCModel3D is the base class, from it we can have CCModelOBJ, CCModelCOLLADA, and so on. This makes easier to add support for other formats.

In further versions we could add bone animations, shaders, etc.

@Jose Marin
If cocos2d-x has CCLayer3D, CCCamera3D, CCModel3D, etc. Then it will be cocos3d-x:)

Hi, i think that a good idea could be create an “cocos2d-x’s object3d format”, it could be similar to obj or collada, and to create a script on blender to export to that own format. It will allow to load 3d objects in blender (open source) and export to cocos2d-x 3d format.

Yes this is the big can of worms I was planning on.

Mingo, I agree just allow us to drop a 3d shape inside the app, and we’ll do the collision handling. We don’t want to, as you pointed out, go down a Cocos3d-x route. A simple cocos2d-x + 3d model support, like you are suggesting is perfect.

As far as object format, I agree again to start with OBJ, and then look into others. Maybe once the basics are up of a simple format, we can get some contribs to add to extensions for other formats.

`nick3d Nicita
It is a final goal to have our own format. I think we can support other format at first.

`Michael Developer
Thank you for your understanding. I think it is a continuous work to support 3d models.
I hope the community can help to complete it.

I remember that there is a project named as Cocos3D which is written in ObjC.
Will you consider porting it?

@winipcfg winipcfg
We don’t have enough resource to do it. May be some day in future.