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

Function joint_common_parse

src/resource/physics_resource.cpp:375–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373 }
374
375 s32 joint_common_parse(JointDesc &jd, JointType::Enum jt, UnitCompiler &compiler, FlatJsonObject &obj, CompileOptions &opts)
376 {
377 const Guid other_unit_id = RETURN_IF_ERROR(sjson::parse_guid(flat_json_object::get(obj, "data.other_actor")));
378
379 jd = {};
380 jd.type_and_flags = u32(jt) << JOINT_TYPE_AND_FLAGS_TYPE_SHIFT;
381 jd.other_actor_unit_index = UINT32_MAX;
382 jd.pose = MATRIX4X4_IDENTITY;
383 jd.other_pose = MATRIX4X4_IDENTITY;
384 jd.break_force = RETURN_IF_ERROR(sjson::parse_float(flat_json_object::get(obj, "data.break_force")));
385
386 if (jt != JointType::FIXED) {
387 Vector3 position = RETURN_IF_ERROR(sjson::parse_vector3(flat_json_object::get(obj, "data.position")));
388 Quaternion rotation = QUATERNION_IDENTITY;
389 Vector3 other_position = RETURN_IF_ERROR(sjson::parse_vector3(flat_json_object::get(obj, "data.other_position")));
390 Quaternion other_rotation = QUATERNION_IDENTITY;
391
392 if (jt != JointType::SPHERICAL) {
393 rotation = RETURN_IF_ERROR(sjson::parse_quaternion(flat_json_object::get(obj, "data.rotation")));
394 other_rotation = RETURN_IF_ERROR(sjson::parse_quaternion(flat_json_object::get(obj, "data.other_rotation")));
395 }
396
397 jd.pose = from_quaternion_translation(rotation, position);
398 jd.other_pose = from_quaternion_translation(other_rotation, other_position);
399 }
400
401 if (other_unit_id != GUID_ZERO) {
402 const u32 root_unit_index = compiler._unit_roots[compiler._current_unit_index];
403 jd.other_actor_unit_index = unit_compiler::find_unit_index(compiler, other_unit_id, root_unit_index);
404 RETURN_IF_FALSE(PHYSICS_RESOURCE, jd.other_actor_unit_index != UINT32_MAX
405 , opts
406 , "Joint references a unit outside this unit resource"
407 );
408
409 Unit *other_unit = unit_compiler::find_unit(compiler, jd.other_actor_unit_index);
410 bool has_actor = false;
411 RETURN_IF_ERROR(unit_compiler::unit_has_component_type(has_actor
412 , other_unit
413 , STRING_ID_32("actor", UINT32_C(0x374cf583))
414 ));
415 RETURN_IF_FALSE(PHYSICS_RESOURCE, has_actor
416 , opts
417 , "Joint references a unit without an actor component"
418 );
419 }
420
421 return 0;
422 }
423
424 s32 joint_common_write(FileBuffer &fb, JointDesc &jd)
425 {

Callers 6

compile_fixed_jointFunction · 0.85
compile_hinge_jointFunction · 0.85
compile_spherical_jointFunction · 0.85
compile_limb_jointFunction · 0.85
compile_spring_jointFunction · 0.85
compile_d6_jointFunction · 0.85

Calls 9

parse_guidFunction · 0.85
getFunction · 0.85
parse_vector3Function · 0.85
parse_quaternionFunction · 0.85
find_unit_indexFunction · 0.85
find_unitFunction · 0.85
unit_has_component_typeFunction · 0.85
parse_floatFunction · 0.50

Tested by

no test coverage detected