diff --git a/primitive_process/interface/base/primitive.hpp b/primitive_process/interface/base/primitive.hpp index b0cf6e1..622b5e2 100644 --- a/primitive_process/interface/base/primitive.hpp +++ b/primitive_process/interface/base/primitive.hpp @@ -62,7 +62,9 @@ EXTERN_C struct PE_API primitive { // so we don't need to fetch aabb anymore // aabb fetch_aabb() const; // CAUTION: keep characteristics local_to_world as the first subface's part - const internal::transform_block &get_identity_local_to_world() const; + // why virtual? for special primitive like cylinder, it may have multiple parts, the part + // with index 0 may not be the identity transform. e.g., cylinder face has no z translation. + virtual const internal::transform_block &get_identity_local_to_world() const; void apply_transform(internal::transform_type, Eigen::Vector4d); diff --git a/primitive_process/interface/primitive/simple/cylinder.hpp b/primitive_process/interface/primitive/simple/cylinder.hpp index 0f42e37..20d6ac5 100644 --- a/primitive_process/interface/primitive/simple/cylinder.hpp +++ b/primitive_process/interface/primitive/simple/cylinder.hpp @@ -16,6 +16,15 @@ struct cylinder_t final : primitive { marked_subface_ptr_t bottom_plane{}; marked_subface_ptr_t top_plane{}; + // why virtual? For special primitives like cylinder, it may have multiple parts. + // The part with index 0 may not be the identity transform. + // For example, the cylinder face has no z translation. + // Note: The AABB of a cylinder is defined by the side surface, and z-axis scaling does not affect the side surface's radius. + // The degeneracy (simplification) check for a cylinder only considers the first two rows of the transform matrix (x/y directions), + // because scaling along z does not change the essential geometry of the cylinder side surface. + // TODO: the better way is to redefine cylinder, make identity transform as the first part. + const internal::transform_block &get_identity_local_to_world() const override; + protected: void initialize(primitive_data_center_t &, const std::vector> &) override; diff --git a/primitive_process/src/primitive/simple/cylinder.cpp b/primitive_process/src/primitive/simple/cylinder.cpp index 20623a6..593e02d 100644 --- a/primitive_process/src/primitive/simple/cylinder.cpp +++ b/primitive_process/src/primitive/simple/cylinder.cpp @@ -61,4 +61,9 @@ void cylinder_t::initialize(primitive_data_center_t data_center.planes.release(plane_paired_model_matrix{old_model_matrices[2]}); } } + +const internal::transform_block &cylinder_t::get_identity_local_to_world() const +{ + return get_subface()[1].get_ptr()->raw_local_to_world(); +} } // namespace internal \ No newline at end of file