/
Zamar_Terrier
/
TigorEngine
Обзор
Документация
Войти
/
Zamar_Terrier
/
TigorEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Objects/models.c
225 строк
6 KB
Zamar_Terrier
Запрос на слияние 'feature-12032026' (
#9
) из feature-12032026 в master
08 июн 2026, 11:31
Верифицирован
08 июн 2026, 11:31
2200f38
Код
Авторство
О чём код?
#include "Objects/models.h" #include "Objects/gameObject.h" #include "Objects/render_texture.h" #include <vulkan/vulkan.h> #include "Core/e_memory.h" #include "Core/e_device.h" #include "Core/e_camera.h" #include "Core/e_buffer.h" #include "Core/pipeline.h" #include "Core/e_texture.h" #include "Objects/light_object.h" #include "math.h" #include "Tools/e_math.h" #include "Tools/fbxLoader.h" #include "Tools/glTFLoader.h" #include "Tools/objLoader.h" #include "Tools/fbxLoader.h" #include "Data/e_resource_data.h" #include "Data/e_resource_engine.h" #include "Data/e_resource_descriptors.h" typedef void (*Update_Model)(ModelObject3D* mo, uint32_t indx_node, BluePrintDescriptor *descriptor); extern TEngine engine; void ModelDefaultDraw(ModelObject3D* mo, void *command){ for(int i=0; i < mo->num_draw_nodes;i++){ for(int j=0; j < mo->nodes[i].num_models; j++){ GameObject3D *model = &mo->nodes[i].models[j]; GameObjectDraw((GameObject *)model); } } } void ModelLightDescriptorUpdate(ModelObject3D* mo, uint32_t indx_node, void *data){ LightBuffer lbo = {0}; memset(&lbo, 0, sizeof(LightBuffer)); LightObjectSetLights(lbo.lights); lbo.num_lights = engine.lights.size; lbo.light_enable = mo->self.flags & TIGOR_GAME_OBJECT_FLAG_LIGHT; memcpy(data, (char *)&lbo, sizeof(lbo)); } void ModelUpdateModel(ModelObject3D *mo, GameObject3D *model, uint32_t model_indx){ Camera3D* cam = (Camera3D*) engine.cam3D; for(int i=0; i < model->graphObj.gItems.num_shader_packs;i++) { BluePrintPack *pack = &model->graphObj.BluePrints.blue_print_packs[i]; if(model->graphObj.render_point == engine.current_render) { for(int j=0;j < pack->num_descriptors;j++) { BluePrintDescriptor *descriptor = &pack->descriptors[j]; if(descriptor->descrType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) { if(descriptor->uniform.count == 0 || descriptor->update == NULL) continue; void *point; vkMapMemory(engine.device.e_device, descriptor->uniform.buffers[engine.imageIndex].memory, 0, descriptor->buffsize, 0, &point); Update_Model update = descriptor->update; update(mo, model_indx, point); vkUnmapMemory(engine.device.e_device, descriptor->uniform.buffers[engine.imageIndex].memory); } } } } } void ModelDefaultUpdate(ModelObject3D *mo) { Camera3D* cam = (Camera3D*) engine.cam3D; for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { GameObject3D *model = &mo->nodes[i].models[j]; ModelUpdateModel(mo, model, i); } } } void ModelClean(ModelObject3D* mo){ for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { GameObject3D *model = &mo->nodes[i].models[j]; GameObjectClean((GameObject *)model); } } } void ModelRecreate(ModelObject3D* mo){ for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { GameObject3D *model = &mo->nodes[i].models[j]; GameObjectRecreate((GameObject *)model); } } } void ModelNextFrame(ModelObject3D *mo, double time, int num_animation){ if(mo->type == TIGOR_MODEL_TYPE_FBX) Load3DFBXNextFrame(mo, time, num_animation); else if(mo->type == TIGOR_MODEL_TYPE_GLTF) Load3DglTFNextFrame(mo, time, num_animation); } //Не корректно void ModelSetSomeViewport(ModelObject3D* mo, float x, float y, float height, float width) { /*for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { ModelStruct *model = &mo->nodes[i].models[j]; PipelineSetting *settings = (PipelineSetting *)&model->graphObj.gItems.setting; settings[m].viewport.x = x; settings[m].viewport.y = y; settings[m].viewport.height = height; settings[m].viewport.width = width; } }*/ } void ModelDestroy(ModelObject3D* mo){ for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0;j < mo->nodes[i].num_models;j++) { GameObject3D *model = &mo->nodes[i].models[j]; GameObjectDestroy((GameObject *)model); } } } void ModelSetLightEnable(void *obj, bool enable) { ModelObject3D *mo = (ModelObject3D *)obj; if(enable) mo->self.flags |= TIGOR_GAME_OBJECT_FLAG_LIGHT; else mo->self.flags &= ~(TIGOR_GAME_OBJECT_FLAG_LIGHT); } void ModelSetSelCameraEnable(void *obj, bool enable) { ModelObject3D *mo = (ModelObject3D *)obj; if(enable) mo->self.flags |= TIGOR_GAME_OBJECT_FLAG_SELF_CAMERA; else mo->self.flags &= ~(TIGOR_GAME_OBJECT_FLAG_SELF_CAMERA); } void ModelPopulateVertex3D(GameObject3D *model) { uint32_t num = model->graphObj.num_shapes; model->graphObj.shapes[num].bindingDescription = &Bind3DDescription; model->graphObj.shapes[num].attr = cubeAttributeDescription; model->graphObj.shapes[num].countAttr = 3; ModelVertex3D *m_verts = model->graphObj.shapes[0].vParam.vertices; uint32_t count = model->graphObj.shapes[0].vParam.num_verts; Vertex3D *verts = AllocateMemory(count, sizeof(Vertex3D)); for(int i=0;i < count;i++) { verts[i].position = m_verts[i].position; verts[i].normal = m_verts[i].normal; verts[i].texCoord = m_verts[i].texCoord; } VertextIterator vi = {0}; vi.v_index = count; vi.i_index = model->graphObj.shapes[0].iParam.indexesSize; GraphicsObjectSetVertex(&model->graphObj, verts, sizeof(Vertex3D), model->graphObj.shapes[0].iParam.indices, &vi); } void ModelDefaultInit(ModelObject3D *mo, GameObjectType type){ for(int i=0; i < mo->num_draw_nodes;i++) { for(int j=0; j < mo->nodes[i].num_models;j++) { GameObjectInit((GameObject *)&mo->nodes[i].models[j]); } } mo->self.flags |= TIGOR_GAME_OBJECT_FLAG_INIT; }