-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
GSOC 26: 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
base: main
Are you sure you want to change the base?
Changes from 3 commits
bfec2d4
e812dae
962112d
b086d81
1234024
0101168
40d520a
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,48 @@ | ||
| /** | ||
| * @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 | ||
| opacity: null, // d | ||
|
Contributor
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. I think we don't yet have an actual global concept of opacity in our shaders -- we have tint, which can do opacity, but only for textured assets. Maybe worth making an issue for this (something like Also, should texture be in here too?
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. +1 Global opacity issue (discussion stage sounds most applicable?)
Member
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. hey @davepagurek @ksen0, yeah dropped opacity for now, can open a discussion for the webgl globalAlpha thing |
||
| 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); | ||
| } | ||
| 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 |
| 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 |
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