Skip to content

Commit 2dc6516

Browse files
committed
pystark compilation fixes maxOS and Windows
1 parent 8d158b3 commit 2dc6516

3 files changed

Lines changed: 35 additions & 37 deletions

File tree

examples/main.cpp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,6 @@ void simple_grasp()
421421
1. In absence of gravity, the fingers close and squeeze the object.
422422
2. Gravity is progressively turned on. The object stays between the fingers due to Coulomb friction coefficient slightly larger than the sticking threshold.
423423
3. The friction coefficient is reduced to slightly below the sticking threshold. The object slides between the fingers.
424-
425-
This scene also shows how to anonymous lambdas to scope the script code, which is an option to avoid global variables.
426424
*/
427425

428426
stark::Settings settings = stark::Settings();
@@ -448,43 +446,35 @@ void simple_grasp()
448446
simulation.interactions->contact->set_global_params(
449447
stark::EnergyFrictionalContact::GlobalParams()
450448
.set_default_contact_thickness(contact_thickness)
451-
.set_friction_stick_slide_threshold(0.001) // Tighther threshold for more accurate frictional forces
449+
.set_friction_stick_slide_threshold(0.001) // Tighter threshold for more accurate frictional forces
452450
.set_min_contact_stiffness(1e7)
453451
);
454452

455453
// Object
456-
auto [obj, obj_c] = [&]()
457-
{
458-
auto params = stark::Volume::Params::Soft_Rubber();
459-
params.inertia.density = mass/std::pow(d, 3);
460-
params.strain.elasticity_only = true; // We don't need material damping nor strain limiting for this scene
461-
params.strain.youngs_modulus = 2e3;
462-
auto [V, T, H] = simulation.presets->deformables->add_volume_grid("deformable", { d, d, d }, { n, n, n }, params);
463-
return std::make_tuple( H, H.contact);
464-
}();
454+
stark::Volume::Params obj_params = stark::Volume::Params::Soft_Rubber();
455+
obj_params.inertia.density = mass/std::pow(d, 3);
456+
obj_params.strain.elasticity_only = true; // We don't need material damping nor strain limiting for this scene
457+
obj_params.strain.youngs_modulus = 2e3;
458+
auto [V_obj, T_obj, obj] = simulation.presets->deformables->add_volume_grid("deformable", { d, d, d }, { n, n, n }, obj_params);
459+
auto obj_c = obj.contact;
465460

466461
// Hand
467-
auto [hand, hand_c] = [&]()
468-
{
469-
auto [V, C, H] = simulation.presets->rigidbodies->add_box("hand", mass, { 3*d, 3*d, 3*d });
470-
H.rigidbody.set_translation({ 0.0, -(3 * hd + hd + gap), 0.0 });
471-
return std::make_tuple(H.rigidbody, H.contact);
472-
}();
462+
auto [V_hand, C_hand, H_hand] = simulation.presets->rigidbodies->add_box("hand", mass, { 3*d, 3*d, 3*d });
463+
H_hand.rigidbody.set_translation({ 0.0, -(3 * hd + hd + gap), 0.0 });
464+
auto hand = H_hand.rigidbody;
465+
auto hand_c = H_hand.contact;
473466

474467
// Fingers
475468
const Eigen::Vector3d fingers_size = { 0.5*d, 2*d, 2*d };
476-
auto [left_finger, left_finger_c] = [&]()
477-
{
478-
auto [V, C, H] = simulation.presets->rigidbodies->add_box("hand", mass, fingers_size);
479-
H.rigidbody.set_translation({ -(hd + 0.5 * hd + gap), -gap, 0.0 });
480-
return std::make_tuple(H.rigidbody, H.contact);
481-
}();
482-
auto [right_finger, right_finger_c] = [&]()
483-
{
484-
auto [V, C, H] = simulation.presets->rigidbodies->add_box("hand", mass, fingers_size);
485-
H.rigidbody.set_translation({ (hd + 0.5 * hd + gap), -gap, 0.0 });
486-
return std::make_tuple(H.rigidbody, H.contact);
487-
}();
469+
auto [V_lf, C_lf, H_lf] = simulation.presets->rigidbodies->add_box("hand", mass, fingers_size);
470+
H_lf.rigidbody.set_translation({ -(hd + 0.5 * hd + gap), -gap, 0.0 });
471+
auto left_finger = H_lf.rigidbody;
472+
auto left_finger_c = H_lf.contact;
473+
474+
auto [V_rf, C_rf, H_rf] = simulation.presets->rigidbodies->add_box("hand", mass, fingers_size);
475+
H_rf.rigidbody.set_translation({ (hd + 0.5 * hd + gap), -gap, 0.0 });
476+
auto right_finger = H_rf.rigidbody;
477+
auto right_finger_c = H_rf.contact;
488478

489479
// Disable collisions
490480
simulation.interactions->contact->disable_collision(hand_c, left_finger_c);

pystark/cpp/nanobind_stark_include_all.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,19 @@ inline nb::object create_named_tuple(const std::string& typeName, const std::vec
162162
nb::object collections = nb::module_::import_("collections");
163163
nb::object namedtuple = collections.attr("namedtuple");
164164

165-
// Create a Python list for field names
166-
nb::list fields;
167-
for (const auto& fieldName : fieldNames) {
168-
fields.append(fieldName);
165+
// Create a Python list for field names.
166+
// Note: the local variable is named field_list (not fields) to avoid
167+
// potential conflicts with MSVC's name lookup inside Windows SDK headers.
168+
nb::list field_list;
169+
for (const auto& field_name : fieldNames) {
170+
field_list.append(field_name);
169171
}
170-
nb::object tupleType = namedtuple(typeName.c_str(), fields);
171-
return tupleType(*values);
172+
nb::object tuple_type = namedtuple(typeName.c_str(), field_list);
173+
174+
// Use PyObject_Call to unpack `values` as positional args (*values in Python).
175+
// This is explicit and sidesteps MSVC template-resolution issues with
176+
// nanobind's operator* unpacking on nb::tuple.
177+
PyObject* result = PyObject_Call(tuple_type.ptr(), values.ptr(), nullptr);
178+
if (!result) throw nb::python_error();
179+
return nb::steal<nb::object>(result);
172180
}

stark/extern/symx/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,5 @@ target_link_options(symx INTERFACE
258258
"$<$<CXX_COMPILER_ID:MSVC>:/STACK:${SYMX_STACK_SIZE}>"
259259
"$<$<CXX_COMPILER_ID:GNU>:-Wl,-z,stack-size=${SYMX_STACK_SIZE}>"
260260
"$<$<CXX_COMPILER_ID:Clang>:-Wl,-z,--stack_size=${SYMX_STACK_SIZE}>"
261-
"$<$<CXX_COMPILER_ID:AppleClang>:-Wl,-stack_size,${SYMX_STACK_SIZE}>"
261+
"$<$<AND:$<CXX_COMPILER_ID:AppleClang>,$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>>:-Wl,-stack_size,${SYMX_STACK_SIZE}>"
262262
)

0 commit comments

Comments
 (0)