fbx mesh load geometry transformation - c++

I am trying to load a car model from fbx file with one model that divided into 5 sub models.
4 sub models are the wheels and one sub model is the car.
At first when I tried to render it I Saw only one wheel so I start diagnostic on the frame.
I realized that all the four wheel are much more big then the car.
This and the fact that I see only one wheel make me think that in fbx each sub model has own transformation matrix.
Am I right?
And if yes how can I get the specific transformation for the specific sub model?

All nodes in fbx have own transformation. You can take it by EvaluateLocalTransform(if you keep hierarchy) or EvaluateGlobalTransform (if you don't)

Related

Comparison of Two 3D Models to Determine Orientation Difference

I am working on a project where I am trying to compare a 3D reconstructed model with a predefined 3D model of the same object to find the orientation shift between them. An example of these types of models can be seen here: example models.
I was thinking about maybe trying to use Kabsch's algorithm to compare them but I'm not completely sure that will work because they don't have the same number of vertices and I'm not sure if there's a good way to make that happen. Also, I don't know the correspondence information - which point in set 1 represents which point in set 2.
Regardless, I have the model's PLY files which contains the coordinates of each vertex so I'm looking for some way to compare them that will match up the different features in each object together. Here is a GitHub repo with both PLY files just in case that would be useful.
Thanks in advance for any help, I've been struck trying to figure out this problem for a while!

How to render different maps (diffuse, depth, specular, shaded) of a 3d model from different camera angles, in Blender?

My task is to render a 3d model from different camera angles. Along with the original snapshot, my script should also render depth/normal/albedo/diffuse/mask/specular maps of the object in view.
I already have a script for rendering depth/normal/albedo maps. https://github.com/panmari/stanford-shapenet-renderer
How can I render diffuse/mask/specular maps as well.
The online tutorials on generating these maps follow the technique of converting one map to another(like diffuse to specular), rather than rendering a 3d model from different angles.
I have been also trying to get something similar. So far my approach is manual. This process is easy enough to be converted into python code quickly. I have tested only EEVEE with this.
The process is basically enabling holdout for each object or object groups that need to be segmented in different view layers. Then after rendering outputting the Alpha from Render Layers node within compositing tab with desired view layer selected. They can be output with File Output node in BW or RGB.
Similarly in view layer properties tab there is option for diffuse and specular passes. After rendering once with these selected the the output will be available in Render Layers node.
I have described the entire process here in detail. There is also an existing GitHub python repo named bpycv that generates various types of masks and also generates depth map.
References
https://github.com/quickgrid/AI-Resources/tree/master/code-lab/blender
https://github.com/DIYer22/bpycv

Creating a 3D model of object with non-overlapping stereo cameras?

Say I wanted to create a 3D model of an object, and I have a pair of cameras that will take a photo of the object at a given distance (the position of the cameras is fixed relative to the object itself.) However, the Field Of View of the cameras is such that not all of the object is visible for each camera; only part of the object is visible for both cameras. See the figure below for what I mean.
Is it possible to create a 3D model of the object using the images from the two cameras, even thought they do not completely see the entirety of the model? If so, how can this be done?

How to place 3D objects in a scene?

I'm developing a simple rendering engine as a pet project.
So far I'm able to load geometry data from Wavefront .obj files and render them onscreen separately. I know that vertex coordinates stored in these files are defined in Model space and to place them correctly in the scene I need to apply Model-to-world transform matrix to each vertex position (am I even correct here?).
But how do I define those matrices for each object? Do i need to develop a separate tool for scene composition, in which I will move objects around and the "tool" will calculate appropriate Model-to-world matrices based on translations, rotations an so on?
I would look into the "Scene Graph" data structure. It's essentially a tree, where nodes (may) define their transformations relative to their parent. Think of it this way. Each of your fingers moves relative to your hand. Moving your hand, rotating or scaling it also involves doing the same transformation on your fingers.
It is therefore beneficial to base all these relative transformations on one another as relative ones, and combine trhem to determine the overall transformation of each individual part of your model. As such you don't just define the direct model to view transformation, but rather a transformation from each part to its parent.
This saves having to define a whole bunch of transformations yourself, which are in the vast majority of cases similarly in the way I described anyway. As such you save yourself a lot of work by representing your models/scene in this manner.
Each of these relative transformations is usually a 4x4 affine transformation matrix. Combining these is just a matter of multiplying them together to obtain the combination of all of them.
A description of Scene Graphs
In order to animate objects within a scene graph, you need to specify transformations relative to their parent in the tree. For instance, spinning wheels of a car need to rotate relative to the car's chassis. These transformations largely depend on what kind of animations you'd like to show.
So I guess the answer to your question is "mostly yes". You do need to define transformations for every single object in your scene if things are going to look good. However, orgasnising the scene into a tree structure makes this process a lot easier to handle.
Regarding the creation of those matrices what you have to do is to export a scene from an authoring package.
That software can be the same you used to model the objects in the first place, Maya, Lightwave...
Right now you have your objects independent of each other.
So, using the package of your choice, either find a file format allowing you to export a scene you would have made by positioning each of your meshes where you want them, like FBX or GLTF or make your own.
Either way there is a scene structure, containing models, transforms, lights, cameras, everything you want in your engine.
After that you have to parse that structure.
You'll find here some explanations regarding how you could architect that:
https://nlguillemot.wordpress.com/2016/11/18/opengl-renderer-design/
Good luck,

general scheme of 3d geometry storage and usage in OpenGL or DirectX

I know OpenGL only slight and all this docs and tutorials are damn hard to read so i do not helps.. I got some vision though how it could work and only would like some clarification or validation of my vision
I assume 3D world is build from 3d meshes, each mesh may be hold in some array or few arrays (storing the geometry for that mesh).. I assume also that some meshes may be sorta like cloned and used more than once on the scene.. So in my wision i got say 50 meshes but some of them are used more than once... Lets say those clones i would name as a instance of a mesh (each mesh may have 0 instances, 1 instance or more instances)
Is this vision okay? Some more may be added?
I understand that each instance should have its own position and orientation, so do we have some array of instances each element containing one pos-oriantation matrix? or thiose matrices only existing in the code branches (you know what i mean, i set such matrix then send a mesh then modify this position matrix then send the mesh again till all instances are sent) ?
Do this exhaust the geomety (non-shader) part of the things?
(then shaders part come which i also not quite understand, there is a tremendous amount of hoax on shaders where this geometry part seem more important to me, well whatever)
Can someone validate the vision i spread here?
So you have a model which will contain one or more meshes, a mesh that will contain one or more groups, and a group that will contain vertex data.
There is only a small difference between a model and a mesh such as a model will contain other data such as texture which will be used by a mesh (or meshes).
A mesh will also contain data on how to draw the groups such as a matrix.
A group is a part of the mesh which is generally used to move a part of the model using sub matrices. Take a look at "skeletal animation".
So as traditional fixed pipelines suggest you will usually have a stack of matrices which can be pushed and popped to define somewhat "sub-positions". Imaging having a model representing a dragon. The model would most likely consist of a single mesh, a texture and maybe some other data on the drawing. In the runtime this model would have some matrix defining the model basic position and rotation, even scale. Then when the dragon needs to fly you would move its wings. Since the wings may be identical there may be only 1 group but the mesh would contain data to draw it twice with a different matrix. So the model has the matrix which is then multiplied with the wing group matrix to draw the wing itself:
push model matrix
multiply with the dragon matrix
push model matrix
multiply with the wing matrix
draw wing
pop matrix
push matrix
multiply with the second wing matrix
draw second wing
pop matrix
... draw other parts of the dragon
pop matrix
You can probably imagine the wing is then divided into multiple parts each again containing an internal relative matrix achieving a deeper level of matrix usage and drawing.
The same procedures would then be used on other parts of the model/mesh.
So the idea is to put as least data as possible on the GPU and reuse them. So when model is loaded all the textures and vertex data should be sent to the GPU and be prepared to use. The CPU must be aware of those buffers and how are they used. A whole model may have a single vertex buffer where each of the draw calls will reuse a different part of the buffer but rather just imagine there is a buffer for every major part of the mode such as a wing, a head, body, leg...
In the end we usually come up with something like a shared object containing all the data needed to draw a dragon which would be textures and vertex buffers. Then we have another dragon object which will point out to that model and contain all the necessary data to draw a specific dragon on the scene. That would include the matrix data for the position in the scene, the matrix for the groups to animate the wings and other parts, maybe some size or even some basic color to combine with the original model... Also some states are usually stored here such as speed, some AI parameters or maybe even hit points.
So in the end what we want to do is something like foreach(dragon in dragons) dragon.draw() which will use its internal data to setup the basic model matrices and use any additional data needed. Then the draw method will call out to all the groups, meshes in the model to be drawn as well until the "recursion" is done and the whole model is drawn.
So yes, the structure of the data is quite complicated in the end but if you start with the smaller parts and continue outwards it all fits together quite epic.
There are other runtime systems that need to be handled as well to have a smooth loading. For instance if you are in a game and there are dragons in vicinity you will not have the model for the dragon loaded. When the dragon enters the vicinity the model should be loaded in the background if possible but drawn only when needed (in visual range). Then when the dragon is gone you may not simply unload the model, you must be sure all of the dragons are gone and maybe even wait a little bit if someone might return. This then leads to something much like a garbage collector.
I hope this will help you to a better understanding.