-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
multi-material model parts (obj/mtl) #8879
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
Open
Nixxx19
wants to merge
5
commits into
processing:dev-2.0
Choose a base branch
from
Nixxx19:geometry-part-refactor
base: dev-2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bfec2d4
add geometrypart class
Nixxx19 e812dae
wrap geometry in a single part
Nixxx19 962112d
split obj models into per-material parts
Nixxx19 b086d81
drop opacity from part state, make parts public
Nixxx19 1234024
Merge branch 'dev-2.0' into geometry-part-refactor
Nixxx19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * @module Shape | ||
| * @submodule 3D Primitives | ||
| * @for p5 | ||
| */ | ||
|
|
||
| // fresh part state. fields use p5 names (fill, texture...), not obj/mtl tokens. | ||
| // importers translate into this and drop anything we can't draw yet. | ||
| function createPartState() { | ||
| return { | ||
| fill: null, // Kd | ||
| ambientColor: null, // Ka | ||
| specularColor: null, // Ks | ||
| shininess: null, // Ns | ||
| texture: null // map_Kd | ||
| }; | ||
| } | ||
|
|
||
| // one part of a geometry. a multi-material model is a p5.Geometry made of | ||
| // several parts, each holding the verts/faces/uvs for one material plus the | ||
| // state to draw them. single-material models are just one part. | ||
| class GeometryPart { | ||
| constructor(gid, partState) { | ||
| // renderer caches buffers by this, derived from the parent geometry's gid | ||
| this.gid = gid; | ||
|
|
||
| this.vertices = []; | ||
| this.vertexNormals = []; | ||
| this.faces = []; | ||
| this.uvs = []; | ||
| this.vertexColors = []; | ||
|
|
||
| this.partState = partState || createPartState(); | ||
| this.dirtyFlags = {}; | ||
| } | ||
| } | ||
|
|
||
| function geometryPart(p5, fn) { | ||
| p5.GeometryPart = GeometryPart; | ||
| } | ||
|
|
||
| export default geometryPart; | ||
| export { GeometryPart, createPartState }; | ||
|
|
||
| if (typeof p5 !== 'undefined') { | ||
| geometryPart(p5, p5.prototype); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| newmtl mat0 | ||
| Kd 1 1 1 | ||
| Ns 50 | ||
| map_Kd cat.jpg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| mtllib textured.mtl | ||
| v 0 0 0 | ||
| v 1 0 0 | ||
| v 0 1 0 | ||
| vt 0 0 | ||
| vt 1 0 | ||
| vt 0 1 | ||
| usemtl mat0 | ||
| f 1/1 2/2 3/3 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe double check, but I assume that since this check is in the constructor, geometry built via
buildGeometrywill hit this path too and end up having its vertices mapped to a single part.One thought: maybe we can default to having one part if none have been made yet, and that's where the data lives, and on the geometry itself we just have getter/setters that map to that first part? If we mark it as empty with a flag, then a method to add a part can check for that first and delete the old one if it's the default empty one?
Regardless, we maybe want to make parts a documented thing (so, maybe without the
_prefix on the name) and mark the direct access of vertices.faces/etc deprecated so that it's still there for now, but the expectation is that it's removed in 3.0?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @davepagurek for the detailed thoughts here, really helpful
checked the buildGeometry path, you're right, it goes through the same
Geometryconstructor so it gets wrapped into one part too. works fine, tests pass, good to confirmi like the first-part-holds-the-data idea. in the renderer follow up i just had the geometry be its own first part (
parts = [this]) so there's only one copy, but happy to do the getter + empty-flag way if you prefer itand agreed on making
partspublic, renamed it already, and i'll mark directvertices/facesaccess deprecated so it keeps working for now but is set to go in 3.0