Study Notes on Cocos 3D functions (2) --- 3D genie, cocos --- 3d

Source: Internet
Author: User

Study Notes on Cocos 3D functions (2) --- 3D genie, cocos --- 3d

Personal Original, welcome to reprint, reprint please note the address, column address http://blog.csdn.net/bill_man

In the 2D stage, the most commonly used drawing unit is undoubtedly the Genie. With the genie, we can draw images to the screen; In the 3d stage, we need to plot the 3d model on the screen into a 3D model made by the artist using tools such as 3dmax. Drawing 3d genie is one of the earliest functions of cocos and one of the most important functions, in this section, we will learn how to draw 3D genie.

The formats supported by 3D genie include obj, c3t, and c3b. The differences are as follows:

Obj: it is the file format exported by 3dmax, but does not support exporting model animations.

C3t: a file in json format. It is converted by the fbx file exported by the model through the file conversion tool provided by cocos. It facilitates you to view the version number and model information of the model, in actual projects, the loading speed is slow due to the large size of c3t, so it is not recommended.

C3b: c3b binary file version, suitable for use in projects

The exported model must meet the following conditions:

1. Only one skeleton can be set.

2. No parent node exists.

3. Only one material can be created.

The export process is in the tools \ fbx-conv \ win directory of the windows tool under the cocos directory (the mac tool is in the tools \ fbx-conv \ mac directory)


Fbx-conv-a simultaneously generates c3b c3t

Fbx-conv-B generates c3b

Fbx-conv-t generates c3t

After running the command line, the directory contains the c3b or c3t file of the model you want to generate.

Use of the Sprite3D class:

After the resources are ready, the following figure shows how to use them. The create function of Sprite3D can input obj, c3b, or c3t file names and directories to create a 3d genie.

Auto sprite = Sprite3D: create ("Sprite3DTest/boss1.obj ");

Auto orc = cocos2d: Sprite3D: create ("Sprite3DTest/orc. c3b ");

3d genie can add animations like other common nodes, and can be used as root nodes like other nodes. In a recent version, zhonghai Fixed rendering errors with transparent textures.

Sprite3D also provides the createAsync function to asynchronously create a 3D genie. If the 3D model has been loaded, it will immediately create a new 3D Genie and the callback will be called once. Otherwise, the model file will be loaded in a new thread. Once the file is loaded, it will execute the callback function and use the newly created model and Custom User data as parameters. This callback will be called in the main thread, so it is safe to create any cocos2d object in the callback function.

Sprite3D: createAsync (path, CC_CALLBACK_2 (Test: callback, this), (void *) index ++ );

The first parameter is the directory plus the file name, the second parameter is the callback function after loading, and the third parameter is the parameter passed in during callback. When loading a large model or loading more models at the same time, you can use the asynchronous loading function, so that your game has no effect.

SetTexture is used to set the texture. If multiple textures exist, set the first one.

SetCullFaceEnabled is used to set whether to crop and remove

SetCullFace determines which plane to remove, including gl_back, gl_front, and gl_front_and_back.

GetAttachNode obtains the skeleton by passing in a bone name.

RemoveAttachNode: Delete the imported skeleton

You can use getMeshByIndex and getMeshByName to obtain the grid. By displaying or hiding different grids, you can achieve the effect of reloading.

Sprite3D is a subclass of node. That is to say, all node functions are inherited by Sprite3D.

Animation function:

You can use Animate3D and Animation3D to play a skeleton animation, provided that your model has an animation.

Animate3D static animation data can be shared by multiple Animate3D. Animate3D uses the action created by the specified Animation3D to play the animation to Sprite3D.

// Input the model name to create static animation data

Animation = Animation3D: create (fileName );

// Determine whether an animation exists

If (animation)

{

// Create an animation

Auto animate = Animate3D: create (animation );

// The animation is always repeated.

Auto act = RepeatForever: create (animate );

Act-> setTag (0 );

// Execute the animation

Sprite-> runAction (act );

}

Functions in Animate3D:

SetSpeed: sets the animation playback speed.

SetQuality: Set the animation Quality

SetOriginInterval

You can pass in the start time and duration in the create FUNCTION to differentiate multiple actions in an Animation3D, or you can pass in the start frame in the createWithFrames function, multiple actions are obtained at the end frame and frame rate.

In Animation3D, you can pass in the action name in the animation in the second parameter during create to differentiate multiple actions in the same model, such as attacks and injuries.

3d genie Line tracing:

// Create an tracing wizard

Auto sprite = EffectSprite3D: create (fileName );

// Create Line tracing

Optional t3doutline * effect = optional t3doutline: create ();

// Line tracing color

Effect-> setOutlineColor (Vec3 (1, 0, 0 ));

// Line width

Effect-> setOutlineWidth (0.01f );

// Add Line tracing

Sprite-> addEffect (effect,-1 );

EffectSprite3D can be used to create the Sprite3D edge tracing effect. It is a subclass of Sprite3D and has all Sprite3D functions. By adding javast3doutline to it, you can achieve the Sprite3D edge tracing effect and set the color and width, at the same time, more than one line can be traced.

 

Insufficient capacity and limited level. If you have any mistakes, please note.


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.