Skip to content

Add various shape type - #97

Merged
pjessesco merged 7 commits into
mainfrom
m
Jun 26, 2026
Merged

Add various shape type#97
pjessesco merged 7 commits into
mainfrom
m

Conversation

@pjessesco

Copy link
Copy Markdown
Owner
  • Fix TriangleMesh to handle triangle vertex by index (no longer store duplicated vertices)
  • Add Instance shape type for multiple instances of the same shape with different transforms :
{
    "type" : "instance",
    "shapes": [
        {
            "type" : "obj",
            "path" : "cube.obj",
            "bsdf" : {
                "type" : "conductor",
                "material" : "Ag",
                "ex_ior" : 1.0
            },
            "to_world" : [
                {
                    "type" : "rotate_y",
                    "degree" : 30
                }
            ]
        },
        // ... other shapes
    ],
    "instances": [
        {
            "to_world": [1.0, 0.0, 0.0, -2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5.0, 0.0, 0.0, 0.0, 1.0]
        },
        {
            "to_world": [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5.0, 0.0, 0.0, 0.0, 1.0]
        },
        {
            "to_world": [1.0, 0.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5.0, 0.0, 0.0, 0.0, 1.0]
        }
    ]
}
  • Add InlineTriangleMesh to specify triangle mesh in json file :
{
    "type": "trianglemesh",
    "P": [-0.5, -0.5, 0,  0.5, -0.5, 0,  0.5, 0.5, 0,  -0.5, 0.5, 0],
    "indices": [0, 2, 1,  0, 3, 2],
    "to_world": [
        1.0, 0.0, 0.0, 0.0,
        0.0, 0.707106, -0.707106, -1.5,
        0.0, 0.707106, 0.707106, 0.0,
        0.0, 0.0, 0.0, 1.0
    ],
    "bsdf": {
        "type": "diffuse",
        "albedo": [0.8, 0.2, 0.2]
    }
},

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends Caramel鈥檚 shape system by introducing instancing and an inline triangle-mesh JSON format, while also refactoring mesh shapes (OBJ/PLY/inline) to share a unified TriangleMesh implementation based on indexed triangles.

Changes:

  • Refactors OBJ/PLY meshes onto a shared TriangleMesh base with m_face_indices and a common finalize() path (AABB/area/BVH/solid-angle polygon extraction).
  • Adds Instance shape type (per-placement transform around a shared template shape).
  • Adds InlineTriangleMesh and scene parsing support for "type": "trianglemesh" with inline vertex/index arrays; adds/updates tests and a new render test scene.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
test/unit_tests.cpp Adds unit tests for Instance ray intersection and inline triangle mesh behavior.
test/simple_render_test.cpp Adds a new render regression test (test7) and scaffolding for instance-related render tests (currently commented).
src/shapes/triangle_mesh.cpp Introduces shared TriangleMesh implementation (finalize, sampling, BVH integration, solid-angle polygon extraction).
src/shapes/plymesh.cpp Simplifies PLY mesh loading to populate shared TriangleMesh buffers and call finalize().
src/shapes/objmesh.cpp Updates OBJ loading to weld vertices by (v/n/uv) and emit indexed faces into TriangleMesh.
src/shapes/instance.cpp Implements instanced shape intersection + transformed AABB, sampling, and solid-angle PDF.
src/shapes/inline_triangle_mesh.cpp Implements mesh construction directly from inline vertex/index arrays and calls finalize().
src/scene_parser.cpp Adds parsing for "type":"instance" expansion and for inline "type":"trianglemesh".
include/shape.h Refactors TriangleMesh to a concrete base class; adds InlineTriangleMesh + Instance declarations.
include/scene_parser.h Declares parse_instanced_shapes() and documents instance schema.
CMakeLists.txt Registers new shape sources in the build.

馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/shapes/triangle_mesh.cpp Outdated
Comment thread src/shapes/triangle_mesh.cpp
Comment thread src/shapes/objmesh.cpp
Comment thread src/scene_parser.cpp
Comment thread src/scene_parser.cpp Outdated
Comment thread src/scene_parser.cpp Outdated
Comment thread src/scene_parser.cpp Outdated
Comment thread src/scene_parser.cpp
Comment thread include/scene_parser.h Outdated
Comment thread src/shapes/instance.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Comment thread src/shapes/instance.cpp
Comment thread src/shapes/objmesh.cpp
Comment thread src/scene_parser.cpp
@pjessesco
pjessesco marked this pull request as ready for review June 26, 2026 10:04
@pjessesco
pjessesco merged commit e259e24 into main Jun 26, 2026
4 checks passed
@pjessesco
pjessesco deleted the m branch June 26, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants