Difference between revisions of "Mesh Converter/en"
(69 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Scope == | == Scope == | ||
− | The W4 game engine uses its own asset storage format. Therefore, before using | + | The W4 game engine uses its own asset storage format. Therefore, before using any fbx asset, it has to be converted. This can be done using the Mesh Converter tool that comes with the W4 SDK. |
Mesh Converter converts assets from Autodesk FBX (.fbx) format. Other formats are not supported. | Mesh Converter converts assets from Autodesk FBX (.fbx) format. Other formats are not supported. | ||
== Technical limitations == | == Technical limitations == | ||
− | Mesh Converter | + | Mesh Converter converts any fbx with the following restrictions: |
− | + | Due to the hardware and software features of some popular device models, a skinned mesh may contain: | |
* no more than 28 bones | * no more than 28 bones | ||
* no more than 8 vertices per bone | * no more than 8 vertices per bone | ||
== How to use == | == How to use == | ||
− | + | The procedure for obtaining the project repository is described in the [[Quick Start]] article. | |
The W4MeshConverter.bin file is located in the w4framework/tools directory. | The W4MeshConverter.bin file is located in the w4framework/tools directory. | ||
− | The conversion | + | The conversion is started from the command line, as described in the [http://wiki.w4-dev.ciliz.com/index.php/Mesh_Converter#Short_manual Short manual] section and shown in the case below. |
=== Mesh Exmple === | === Mesh Exmple === | ||
==== Preparing ==== | ==== Preparing ==== | ||
− | + | Let’s take the [http://demo.w4-dev.ciliz.com/wiki-files/utah-teapot.fbx Utah teapot] as an example. | |
− | If you view the file using the utility [https://www.autodesk.com/products/fbx/fbx-review Autodesk FBX Review], you will see | + | If you view the file using the utility [https://www.autodesk.com/products/fbx/fbx-review Autodesk FBX Review], you will see something similar to the following figure. |
− | + | http://demo.w4-dev.ciliz.com/wiki-files/cb84552c-5001-4127-9d9d-1e93f9c96696.png | |
− | Pay attention to the | + | Pay attention to the orientation of the teapot spout when viewing fbx, we will get back to this later. |
==== Converting ==== | ==== Converting ==== | ||
− | Copy the model file to the | + | Copy the model file to the directory where the file W4MeshConverter.bin is located. |
− | + | To convert the model to the W4 Engine format (asset), the following command are executed: | |
./W4MeshConverter utah-teapot.fbx teapot | ./W4MeshConverter utah-teapot.fbx teapot | ||
− | As a result, the 'teapot' directory will appear | + | As a result, the 'teapot' directory will appear containing asset data. |
==== Adding to the project structure ==== | ==== Adding to the project structure ==== | ||
− | To work with an asset, you need to copy its directory (in our case, it is 'teapot') into the directory 'resources' of the project. The resources directory is located at the same level of the project structure as the 'sources' directory. Thus, the structure of the project | + | To work with an asset, you need to copy its directory (in our case, it is 'teapot') into the directory 'resources' of the project. The 'resources' directory is located at the same level of the project structure as the 'sources' directory. Thus, the structure of the project becomes similar to the following: |
. | . | ||
Line 56: | Line 56: | ||
Loading: | Loading: | ||
+ | <syntaxhighlight lang="c++"> | ||
auto asset = Asset::load(Path("resources/teapot", "teapot.asset")); | auto asset = Asset::load(Path("resources/teapot", "teapot.asset")); | ||
+ | </syntaxhighlight> | ||
− | Adding to Render | + | Adding to the Render: |
+ | <syntaxhighlight lang="c++"> | ||
auto root = RootNode::make(); | auto root = RootNode::make(); | ||
root->addChild(asset->getRoot()); | root->addChild(asset->getRoot()); | ||
Render::instance().getPass(0)->setRoot(root); | Render::instance().getPass(0)->setRoot(root); | ||
+ | </syntaxhighlight> | ||
− | Full source code | + | Full source code of the example: |
+ | <syntaxhighlight lang="c++"> | ||
#include "W4Framework.h" | #include "W4Framework.h" | ||
Line 91: | Line 96: | ||
W4_RUN(AssetSample) | W4_RUN(AssetSample) | ||
+ | </syntaxhighlight> | ||
==== Result ==== | ==== Result ==== | ||
− | As a result of execution, the same teapot | + | As a result of execution, the same teapot is displayed, but with a slight difference. |
− | + | http://demo.w4-dev.ciliz.com/wiki-files/3aa4d02a-5152-44d6-9168-13a155f1b049.png | |
− | + | If you compare the drawings, you may notice that the spout of the teapot has changed its directed after the program execution. This happens due to differences in coordinate systems. | |
− | If you compare the drawings, you | ||
− | |||
− | + | The FBX coordinate system [https://help.autodesk.com/view/FBX/2017/ENU/?guid=__files_GUID_CC93340E_C4A1_49EE_B048_E898F856CFBF_htm Scene Axis and Unit Conversion] is right-handed (with the Y pointing up), whereas W4 coordinate system is left-handed (the the Y axis is also pointing up). | |
− | The FBX coordinate system [https://help.autodesk.com/view/FBX/2017/ENU/?guid=__files_GUID_CC93340E_C4A1_49EE_B048_E898F856CFBF_htm Scene Axis and Unit Conversion] is right-handed (with the Y | ||
− | |||
=== Animated mesh Exmple === | === Animated mesh Exmple === | ||
− | Working with animated meshes is not much different from [http://wiki.w4-dev.ciliz.com/index.php/Mesh_Converter#Mesh_Exmple the | + | Working with animated meshes is not much different from [http://wiki.w4-dev.ciliz.com/index.php/Mesh_Converter#Mesh_Exmple the simple meshes]. |
==== Preparing ==== | ==== Preparing ==== | ||
− | + | Take, for example, [http://demo.w4-dev.ciliz.com/wiki-files/Hand_rigged.FBX Rigged Hand]. | |
− | If you view it using [https://www.autodesk.com/products/fbx/fbx-review Autodesk FBX Review] you will see | + | If you view it using [https://www.autodesk.com/products/fbx/fbx-review Autodesk FBX Review] you will see approximately the following: |
[[file:hand.mov|500px]] | [[file:hand.mov|500px]] | ||
+ | |||
+ | http://demo.w4-dev.ciliz.com/wiki-files/Hand.mov | ||
==== Converting ==== | ==== Converting ==== | ||
− | + | Copy the model file to the directory where the file W4MeshConverter.bin is located. | |
+ | |||
+ | Convert the model to the W4 Engine format (asset), using the following command: | ||
./W4MeshConverter Hand_rigged.FBX hand | ./W4MeshConverter Hand_rigged.FBX hand | ||
− | As a result, the 'hand' directory | + | As a result, the 'hand' directory appears in the current folder, containing asset data. |
==== Adding to the project structure ==== | ==== Adding to the project structure ==== | ||
− | + | To work with an asset, you need to copy its directory (in our case, it is 'hand') into the directory 'resources' of the project. The 'resources' directory is located at the same level of the project structure as the 'sources' directory. Thus, the structure of the project will become similar to the following: | |
. | . | ||
Line 146: | Line 152: | ||
Download asset and add it to the render tree: | Download asset and add it to the render tree: | ||
+ | <syntaxhighlight lang="c++"> | ||
auto asset = Asset::load(Path("resources/hand", "hand.asset")); | auto asset = Asset::load(Path("resources/hand", "hand.asset")); | ||
render::getRoot()->addChild(asset->getRoot()); | render::getRoot()->addChild(asset->getRoot()); | ||
+ | </syntaxhighlight> | ||
− | If | + | If you build the project now, most probably you will not see anything, because the camera is located inside of the asset. |
− | + | Move the camera away (you may need to set other values, depending on the size of the browser window, the size of the object, etc.): | |
+ | <syntaxhighlight lang="c++"> | ||
auto cam = render::getScreenCamera(); | auto cam = render::getScreenCamera(); | ||
cam->setWorldTranslation({0.f, 125.f, -300.f}); | cam->setWorldTranslation({0.f, 125.f, -300.f}); | ||
− | + | </syntaxhighlight> | |
− | |||
− | + | If you build the project now, a hand will appear on the screen, but it will not be animated. | |
+ | Run the animator on the corresponding skinned mesh. In this case there is one skinned mesh with one animation, so in a loop the program goes through the entire asset tree and all skinned meshes in it and we play the animation (in our example - the first one): | ||
+ | |||
+ | <syntaxhighlight lang="c++"> | ||
asset->getRoot()->traversal([&](Node& node) | asset->getRoot()->traversal([&](Node& node) | ||
{ | { | ||
Line 169: | Line 180: | ||
} | } | ||
}); | }); | ||
+ | </syntaxhighlight> | ||
Full source code for the example: | Full source code for the example: | ||
+ | <syntaxhighlight lang="c++"> | ||
#include "W4Framework.h" | #include "W4Framework.h" | ||
Line 202: | Line 215: | ||
W4_RUN(MeshAnimatedSample) | W4_RUN(MeshAnimatedSample) | ||
+ | </syntaxhighlight> | ||
==== Result ==== | ==== Result ==== | ||
− | As a result of the | + | As a result of the program, the following animation is shown: |
[[File:Hand engine.mov|500px]] | [[File:Hand engine.mov|500px]] | ||
+ | |||
+ | http://demo.w4-dev.ciliz.com/wiki-files/Hand_engine.mov | ||
== Short manual == | == Short manual == | ||
=== Basics === | === Basics === | ||
− | Convert utah-teapot.fbx to asset with the name 'asset' current directory: | + | Convert utah-teapot.fbx to asset with the name 'asset' (current directory): |
./W4MeshConverter utah-teapot.fbx | ./W4MeshConverter utah-teapot.fbx | ||
− | Convert utah-teapot.fbx to asset with the name 'teapot' current directory: | + | Convert utah-teapot.fbx to asset with the name 'teapot' (current directory): |
./W4MeshConverter utah-teapot.fbx teapot | ./W4MeshConverter utah-teapot.fbx teapot | ||
Line 250: | Line 266: | ||
(DEBUG) create default skinned material... | (DEBUG) create default skinned material... | ||
− | Size control (scale) | + | Size control (scale). Where 'arg' is the value. For example (10, 1, 0.1): |
--scale arg | --scale arg | ||
− | Flip vertical axis V of texture coordinates. If the flag is specified, then a transformation | + | Flip vertical axis V of texture coordinates. If the flag is specified, then a transformation 'V = 1.0 - V' applies to the texture coordinates: |
--uv-flip | --uv-flip | ||
=== Setting limitations === | === Setting limitations === | ||
− | + | Restrictions on the maximum number of vertices and indices can be set for all meshes. For Skinned Meshes, the limit of the maximum number of bones and the maximum number of bones per vertex can be set. | |
− | A model that does not meet the specified | + | A model that does not meet the specified limitation requirements can still be converted using the flag 'force'. However, performance is not guaranteed in this case: |
-f, --force | -f, --force | ||
− | + | Limit of the maximum number of vertices per object, where 'arg' is the value (it is not specified by default): | |
--max-vertex arg | --max-vertex arg | ||
− | + | Limit of the maximum number of indices per object, where 'arg' is the value (it is not specified by default): | |
--max-index arg | --max-index arg | ||
− | + | Limit of the maximum number of bones for Skinned Mesh, where 'arg' is value (28 by default). If the value is set higher than the default, operability is not guaranteed: | |
--max-bones arg | --max-bones arg | ||
− | + | Limit of the maximum number of bones per vertex for Skinned Mesh, where 'arg' is the value (8 by default). If the value is set higher than the default, operability is not guaranteed: | |
--max-bones-per-vertex arg | --max-bones-per-vertex arg |
Latest revision as of 13:20, 1 June 2020
Scope
The W4 game engine uses its own asset storage format. Therefore, before using any fbx asset, it has to be converted. This can be done using the Mesh Converter tool that comes with the W4 SDK.
Mesh Converter converts assets from Autodesk FBX (.fbx) format. Other formats are not supported.
Technical limitations
Mesh Converter converts any fbx with the following restrictions:
Due to the hardware and software features of some popular device models, a skinned mesh may contain:
- no more than 28 bones
- no more than 8 vertices per bone
How to use
The procedure for obtaining the project repository is described in the Quick Start article. The W4MeshConverter.bin file is located in the w4framework/tools directory. The conversion is started from the command line, as described in the Short manual section and shown in the case below.
Mesh Exmple
Preparing
Let’s take the Utah teapot as an example. If you view the file using the utility Autodesk FBX Review, you will see something similar to the following figure.
Pay attention to the orientation of the teapot spout when viewing fbx, we will get back to this later.
Converting
Copy the model file to the directory where the file W4MeshConverter.bin is located.
To convert the model to the W4 Engine format (asset), the following command are executed:
./W4MeshConverter utah-teapot.fbx teapot
As a result, the 'teapot' directory will appear containing asset data.
Adding to the project structure
To work with an asset, you need to copy its directory (in our case, it is 'teapot') into the directory 'resources' of the project. The 'resources' directory is located at the same level of the project structure as the 'sources' directory. Thus, the structure of the project becomes similar to the following:
. └── W4TemplateGame ├── resources │ └── teapot │ ├── Animations │ ├── BoneInfo │ ├── Materials │ │ ├── defaultMaterial.matInst │ │ └── defaultSkinnedMaterial.matInst │ ├── Splines │ ├── teapot.asset │ └── VertexData │ ├── Utah Teapot Quads_0.ib │ └── Utah Teapot Quads.vb └── sources └── main.cpp
Code example
Loading:
auto asset = Asset::load(Path("resources/teapot", "teapot.asset"));
Adding to the Render:
auto root = RootNode::make();
root->addChild(asset->getRoot());
Render::instance().getPass(0)->setRoot(root);
Full source code of the example:
#include "W4Framework.h"
W4_USE_UNSTRICT_INTERFACE
class AssetSample : public w4::IGame
{
public:
AssetSample() = default;
~AssetSample() = default;
void onStart() override
{
auto cam = Render::instance().getScreenCamera();
cam->setWorldTranslation({0.f, 0, -50.f});
auto asset = Asset::load(Path("resources/teapot", "teapot.asset"));
auto root = RootNode::make();
root->addChild(asset->getRoot());
Render::instance().getPass(0)->setRoot(root);
}
};
W4_RUN(AssetSample)
Result
As a result of execution, the same teapot is displayed, but with a slight difference.
If you compare the drawings, you may notice that the spout of the teapot has changed its directed after the program execution. This happens due to differences in coordinate systems.
The FBX coordinate system Scene Axis and Unit Conversion is right-handed (with the Y pointing up), whereas W4 coordinate system is left-handed (the the Y axis is also pointing up).
Animated mesh Exmple
Working with animated meshes is not much different from the simple meshes.
Preparing
Take, for example, Rigged Hand.
If you view it using Autodesk FBX Review you will see approximately the following:
http://demo.w4-dev.ciliz.com/wiki-files/Hand.mov
Converting
Copy the model file to the directory where the file W4MeshConverter.bin is located.
Convert the model to the W4 Engine format (asset), using the following command:
./W4MeshConverter Hand_rigged.FBX hand
As a result, the 'hand' directory appears in the current folder, containing asset data.
Adding to the project structure
To work with an asset, you need to copy its directory (in our case, it is 'hand') into the directory 'resources' of the project. The 'resources' directory is located at the same level of the project structure as the 'sources' directory. Thus, the structure of the project will become similar to the following:
. └── W4TemplateGame ├── resources │ └── hand │ ├── Animations │ │ └── Take 001.ssa │ ├── BoneInfo │ │ ├── bone_main_hande.skeleton │ │ └── Hand_rigged.skin │ ├── hand.asset │ ├── Materials │ │ ├── defaultMaterial.matInst │ │ └── defaultSkinnedMaterial.matInst │ ├── Splines │ └── VertexData │ ├── Hand_rigged_0.ib │ └── Hand_rigged.vb └── sources └── main.cpp
Code example
Download asset and add it to the render tree:
auto asset = Asset::load(Path("resources/hand", "hand.asset"));
render::getRoot()->addChild(asset->getRoot());
If you build the project now, most probably you will not see anything, because the camera is located inside of the asset.
Move the camera away (you may need to set other values, depending on the size of the browser window, the size of the object, etc.):
auto cam = render::getScreenCamera();
cam->setWorldTranslation({0.f, 125.f, -300.f});
If you build the project now, a hand will appear on the screen, but it will not be animated.
Run the animator on the corresponding skinned mesh. In this case there is one skinned mesh with one animation, so in a loop the program goes through the entire asset tree and all skinned meshes in it and we play the animation (in our example - the first one):
asset->getRoot()->traversal([&](Node& node)
{
if(node.is<SkinnedMesh>())
{
auto skinned = node.as<SkinnedMesh>();
skinned->getAnimator(0).setIsLooped(true);
skinned->play(0);
}
});
Full source code for the example:
#include "W4Framework.h"
W4_USE_UNSTRICT_INTERFACE
class MeshAnimatedSample : public w4::IGame
{
public:
MeshAnimatedSample() = default;
void onStart() override
{
auto asset = Asset::load(Path("resources/hand", "hand.asset"));
render::getRoot()->addChild(asset->getRoot());
auto cam = render::getScreenCamera();
cam->setWorldTranslation({0.f, 150.f, -300.f});
asset->getRoot()->traversal([&](Node &node)
{
if (node.is<SkinnedMesh>())
{
auto skinned = node.as<SkinnedMesh>();
skinned->getAnimator(0).setIsLooped(true);
skinned->play(0);
}
});
}
};
W4_RUN(MeshAnimatedSample)
Result
As a result of the program, the following animation is shown:
http://demo.w4-dev.ciliz.com/wiki-files/Hand_engine.mov
Short manual
Basics
Convert utah-teapot.fbx to asset with the name 'asset' (current directory):
./W4MeshConverter utah-teapot.fbx
Convert utah-teapot.fbx to asset with the name 'teapot' (current directory):
./W4MeshConverter utah-teapot.fbx teapot
Convert utah-teapot.fbx to asset with the name 'teapot' which will be saved in the directory ~/some/dir:
./W4MeshConverter utah-teapot.fbx teapot ~/some/dir
Common keys
Show manual:
-h, --help
Scene statistics output:
-v, --verbose
Example of statistics:
(DEBUG) ==================== Scene statistics ==================== (DEBUG) Nodes: 2 (DEBUG) Geometries: 1 (DEBUG) Poses: 0 (DEBUG) Materials: 1 (DEBUG) Textures: 0 (DEBUG) ====================== Axis & Scale ====================== (DEBUG) Up: +Y, Front: +ParityOdd, System: RightHanded (DEBUG) Scale: 1.000000 (DEBUG) ================ Mesh: Red_label ================ (DEBUG) Vertex count: 404 (DEBUG) Index count: 2118 (DEBUG) All polygons are triangles: 1 (DEBUG) ========================================================== (DEBUG) create default material... (DEBUG) create default skinned material...
Size control (scale). Where 'arg' is the value. For example (10, 1, 0.1):
--scale arg
Flip vertical axis V of texture coordinates. If the flag is specified, then a transformation 'V = 1.0 - V' applies to the texture coordinates:
--uv-flip
Setting limitations
Restrictions on the maximum number of vertices and indices can be set for all meshes. For Skinned Meshes, the limit of the maximum number of bones and the maximum number of bones per vertex can be set.
A model that does not meet the specified limitation requirements can still be converted using the flag 'force'. However, performance is not guaranteed in this case:
-f, --force
Limit of the maximum number of vertices per object, where 'arg' is the value (it is not specified by default):
--max-vertex arg
Limit of the maximum number of indices per object, where 'arg' is the value (it is not specified by default):
--max-index arg
Limit of the maximum number of bones for Skinned Mesh, where 'arg' is value (28 by default). If the value is set higher than the default, operability is not guaranteed:
--max-bones arg
Limit of the maximum number of bones per vertex for Skinned Mesh, where 'arg' is the value (8 by default). If the value is set higher than the default, operability is not guaranteed:
--max-bones-per-vertex arg