How to make the download of objects in the engine?


Just want to hear some theories on how to do things right the primary testing facilities in the radius of the camera. In my spare time, I decided to write a simple engine and everything's working now... But now got to load objects from a file. As it is more correct to do?

For example right now the example from Microsoft I have a function "load geometry". Where the compiled shaders, there is an array with vertices, indices and load textures, and then in the render function I just draw the cubes (by changing their positions through XMMatrixTranslation) through the loop, the tops of which have been loaded into the buffer in the download of "geometry".

Now the question on loading objects from file...
I understand the need to create a single file which will be the vertices of all objects and their indexes, when you start the game all it is to drive in the array, and then dynamically load their textures based on the camera's coordinate so they don't clog up the memory. Right thoughts? But here I don't know what to do with the textures... All a little understood how to work texture. Now I have to load the geometry here the following lines

And this texture stands for the whole cube

And as I like to do so were covered in that texture only one side? Or on different sides of different textures. And in General how to load multiple textures on different objects?

Or it will be correct for each object to create a separate file? But how do they then load into an array of vertices and indices? If one file can be the same indexes...
June 14th 19 at 19:11
1 answer
June 14th 19 at 19:13
It is logical to assume that the objects can be duplicated so to write everything into one file makes no sense. One file per object. Multiple instances of one object, you can draw in one call (DrawCall), passing in the Shader an array of matrices for all object.
Then right before doing render culling - check whether the object in the scope of the camera and not covering it with another object.
To optimize textures, prigruzhajut only certain levels of detail (LOD), starting with the smallest size. The closer the camera is to the object the greater the detail used. The texture is really possible to upload/download on the go. But it makes no sense to direct to constantly chase them around, this app is faster will not need to consider the amount of free memory and the frequency of use of texture.
Textures are applied for texture coordinates. I.e. each vertex corresponds to some Texel on the texture, then overlay is performed using interpolation, thus the texture "fills" the entire face of the triangle. Also, all this logic of blending and mixing is determined by the Shader (pixel) with which and achieve different visual effects like lighting, shadows, reflection. Usually to pour a single object use the same texture, in the sense that if one side must be red and the other green, it will be one texture with the red and green part, and not two different textures. Just it is superimposed on the object.
I am just before doing the scripting in SA-MP'e and there was an opportunity to apply the object texture index of the texture on the object from another object. It turns out that there texture on the object was not one, but several. Otherwise, how it changed? Well, for example:

new object = CreateObject(9247, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // Creates a standard object
SetObjectMaterial(object, 0, 4981, !"wiresetc2_las", !"lasunion2", 0xFFFFFFFF); // Change its texture from another object 4981 at index 0


But for example, index 1 (texture from the roof, crawled in the garage)


I the same function to add to the engine? To textures could also be changed. - marge_Runte57 commented on June 14th 19 at 19:16

Find more questions by tags C++DirectX