MCPcopy Create free account
hub / github.com/defold/defold / CompModelCreate

Function CompModelCreate

engine/gamesys/src/gamesys/components/comp_model.cpp:1155–1209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1153 }
1154
1155 dmGameObject::CreateResult CompModelCreate(const dmGameObject::ComponentCreateParams& params)
1156 {
1157 ModelWorld* world = (ModelWorld*)params.m_World;
1158
1159 if (world->m_Components.Full())
1160 {
1161 ShowFullBufferError("Model", "model.max_count", world->m_Components.Capacity());
1162 return dmGameObject::CREATE_RESULT_UNKNOWN_ERROR;
1163 }
1164 uint32_t index = world->m_Components.Alloc();
1165 ModelComponent* component = new ModelComponent;
1166 memset(component, 0, sizeof(ModelComponent));
1167 world->m_Components.Set(index, component);
1168 component->m_Instance = params.m_Instance;
1169 component->m_Transform = dmTransform::Transform(Vector3(params.m_Position), params.m_Rotation, 1.0f);
1170 ModelResource* resource = (ModelResource*)params.m_Resource;
1171 component->m_Resource = resource;
1172
1173 component->m_ComponentIndex = params.m_ComponentIndex;
1174 component->m_Enabled = 1;
1175 component->m_World = Matrix4::identity();
1176 component->m_DoRender = 0;
1177 component->m_Callback = 0;
1178 component->m_CallbackContext = 0;
1179 component->m_RenderConstants = 0;
1180
1181 // Create GO<->bone representation
1182 // We need to make sure that bone GOs are created before we start the default animation.
1183 if (component->m_Resource->m_Model->m_CreateGoBones)
1184 {
1185 if (!CreateGOBones(world, component))
1186 {
1187 dmLogError("Failed to create game objects for bones in model. Consider increasing collection max instances (collection.max_instances).");
1188 DestroyComponent(world, index);
1189 return dmGameObject::CREATE_RESULT_UNKNOWN_ERROR;
1190 }
1191 }
1192
1193 // Create rig instance
1194 component->m_RigInstance = 0;
1195
1196 dmGameObject::CreateResult res = SetupRigInstance(world->m_RigContext, component, resource->m_RigScene, dmHashString64(resource->m_Model->m_DefaultAnimation));
1197 if (res != dmGameObject::CREATE_RESULT_OK)
1198 {
1199 DestroyComponent(world, index);
1200 return res;
1201 }
1202
1203 SetupRenderItems(component, resource);
1204
1205 component->m_ReHash = 1;
1206
1207 *params.m_UserData = (uintptr_t)index;
1208 return dmGameObject::CREATE_RESULT_OK;
1209 }
1210
1211 void* CompModelGetComponent(const dmGameObject::ComponentGetParams& params)
1212 {

Callers

nothing calls this directly

Calls 12

ShowFullBufferErrorFunction · 0.85
identityFunction · 0.85
CreateGOBonesFunction · 0.85
SetupRigInstanceFunction · 0.85
SetupRenderItemsFunction · 0.85
AllocMethod · 0.80
DestroyComponentFunction · 0.70
TransformClass · 0.50
Vector3Class · 0.50
FullMethod · 0.45
CapacityMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected