MCPcopy Create free account
hub / github.com/crownengine/crown / compile_collider

Function compile_collider

src/resource/physics_resource.cpp:150–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148 }
149
150 s32 compile_collider(Buffer &output, UnitCompiler &compiler, FlatJsonObject &obj, CompileOptions &opts)
151 {
152 CE_UNUSED(compiler);
153
154 TempAllocator4096 ta;
155 DynamicString type(ta);
156 RETURN_IF_ERROR(sjson::parse_string(type, flat_json_object::get(obj, "data.shape")));
157
158 ColliderType::Enum st = shape_type_to_enum(type.c_str());
159 RETURN_IF_FALSE(PHYSICS_RESOURCE, st != ColliderType::COUNT
160 , opts
161 , "Unknown shape type: '%s'"
162 , type.c_str()
163 );
164
165 ColliderDesc cd;
166 memset((void *)&cd, 0, sizeof(cd));
167 cd.type = st;
168 cd.local_tm = MATRIX4X4_IDENTITY;
169 cd.size = 0;
170
171 Array<Vector3> points(default_allocator());
172 Array<u32> point_indices(default_allocator());
173
174 DynamicString source(ta);
175 if (flat_json_object::has(obj, "data.source")) {
176 RETURN_IF_ERROR(sjson::parse_string(source, flat_json_object::get(obj, "data.source")));
177 }
178 bool explicit_collider = source == "mesh"
179 || (source != "inline" && flat_json_object::has(obj, "data.scene"));
180
181 if (explicit_collider) {
182 DynamicString scene(ta);
183 DynamicString name(ta);
184 RETURN_IF_ERROR(sjson::parse_string(scene, flat_json_object::get(obj, "data.scene")));
185 RETURN_IF_ERROR(sjson::parse_string(name, flat_json_object::get(obj, "data.name")));
186
187 // Parse mesh resource.
188 RETURN_IF_MISSING(PHYSICS_RESOURCE, "mesh", scene.c_str(), opts);
189 scene += ".mesh";
190 Mesh mesh(default_allocator());
191 s32 err = mesh::parse(mesh, scene.c_str(), opts);
192 ENSURE_OR_RETURN(PHYSICS_RESOURCE, err == 0, opts);
193
194 Node deffault_node(default_allocator());
195 Node &node = hash_map::get(mesh._nodes, name, deffault_node);
196 RETURN_IF_FALSE(PHYSICS_RESOURCE, &node != &deffault_node
197 , opts
198 , "Node '%s' does not exist"
199 , name.c_str()
200 );
201
202 Geometry deffault_geometry(default_allocator());
203 Geometry &geometry = hash_map::get(mesh._geometries, node._geometry, deffault_geometry);
204 RETURN_IF_FALSE(PHYSICS_RESOURCE, &geometry != &deffault_geometry
205 , opts
206 , "Geometry '%s' does not exist"
207 , node._geometry.c_str()

Callers

nothing calls this directly

Calls 15

getFunction · 0.85
shape_type_to_enumFunction · 0.85
memsetFunction · 0.85
compile_sphereFunction · 0.85
compile_capsuleFunction · 0.85
compile_boxFunction · 0.85
parse_quaternionFunction · 0.85
parse_vector3Function · 0.85
parseFunction · 0.70
parse_stringFunction · 0.50
hasFunction · 0.50

Tested by

no test coverage detected