-
-
Notifications
You must be signed in to change notification settings - Fork 428
mesh_view c api #3229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
mesh_view c api #3229
Changes from 2 commits
8ecb7fa
32a3933
9e71d98
3391c89
8f97173
e815de6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #include <engine_c_api.h> | ||
| #include <scene_c_api.h> | ||
| #include <types_c_api.h> | ||
|
|
||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| int test_scene_mesh_view() | ||
| { | ||
| f3d_engine_t* engine = f3d_engine_create(1); // offscreen | ||
| if (!engine) | ||
| { | ||
| puts("[ERROR] Failed to create engine"); | ||
| return 1; | ||
| } | ||
|
|
||
| f3d_scene_t* scene = f3d_engine_get_scene(engine); | ||
| if (!scene) | ||
| { | ||
| puts("[ERROR] Failed to get scene"); | ||
| f3d_engine_delete(engine); | ||
| return 1; | ||
| } | ||
|
|
||
| // A single triangle with a per-point scalar. All arrays are caller-owned and stay alive | ||
| // for the whole function: f3d_scene_add_mesh_view keeps references, it does not copy them. | ||
| float points[] = { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f, 0.0f }; | ||
| unsigned int offsets[] = { 0, 3 }; // one polygon of 3 corners (offset_count = cells + 1) | ||
| unsigned int indices[] = { 0, 1, 2 }; | ||
| float height[] = { 0.0f, 0.5f, 1.0f }; | ||
|
|
||
| f3d_data_array_t point_scalar; | ||
| memset(&point_scalar, 0, sizeof(point_scalar)); | ||
| point_scalar.name = "height"; | ||
| point_scalar.type = F3D_MESH_DATA_F32; | ||
| point_scalar.data = height; | ||
| point_scalar.components = 1; | ||
|
|
||
| f3d_memory_view_t view; | ||
| memset(&view, 0, sizeof(view)); // zero => no normals/texcoords/texture, identity transform | ||
| view.point_count = 3; | ||
| view.points.type = F3D_MESH_DATA_F32; | ||
| view.points.data = points; | ||
| view.points.components = 3; | ||
| view.polygons.offset_count = 2; | ||
| view.polygons.offsets.type = F3D_MESH_DATA_U32; | ||
| view.polygons.offsets.data = offsets; | ||
| view.polygons.index_count = 3; | ||
| view.polygons.indices.type = F3D_MESH_DATA_U32; | ||
| view.polygons.indices.data = indices; | ||
| view.point_scalars = &point_scalar; | ||
| view.point_scalars_count = 1; | ||
|
|
||
| // Static mesh (t_min == t_max). | ||
| if (f3d_scene_add_mesh_view(scene, &view, "triangle", 0.0, 0.0) != 1) | ||
| { | ||
| puts("[ERROR] f3d_scene_add_mesh_view failed"); | ||
| f3d_engine_delete(engine); | ||
| return 1; | ||
| } | ||
|
|
||
| f3d_scene_clear(scene); | ||
| f3d_engine_delete(engine); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,23 @@ class F3D_EXPORT mesh_view | |
| data_array_t indices; | ||
| }; | ||
|
|
||
| /** | ||
| * Structure representing an in-memory base-color (albedo) texture, sampled through the | ||
| * mesh `textureCoordinates`. Avoids writing a temporary image file to disk. `data` is a | ||
| * row-major uint8 buffer of `width * height * components` bytes, with `components` equal | ||
| * to 3 (RGB) or 4 (RGBA). Leave `data` null (the default) for no texture. The pointer | ||
| * must remain valid until the mesh is removed from the scene. When `emissive` is true the | ||
| * same image is additionally installed as the emissive texture (for unlit/flat display). | ||
| */ | ||
| struct texture_t | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as pointed in Discord, I still think we should use |
||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in the PR update |
||
| size_t width = 0; | ||
| size_t height = 0; | ||
| size_t components = 3; | ||
| const void* data = nullptr; | ||
| bool emissive = false; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
| }; | ||
|
|
||
| /** | ||
| * Structure representing a view of the mesh in memory at a given time. | ||
| * The pointers provided in this structure must remain valid once the mesh is added to the scene. | ||
|
|
@@ -155,6 +172,9 @@ class F3D_EXPORT mesh_view | |
| // scalars | ||
| std::vector<data_array_t> pointScalars; | ||
| std::vector<data_array_t> cellScalars; | ||
|
|
||
| // optional in-memory base-color texture (sampled via textureCoordinates) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what makes this optional ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR update has now a longer comments about this |
||
| texture_t baseColorTexture; | ||
| }; | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.