-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Enhanced loadModel() method signature with independent U and V flipping options. #6669
Conversation
I have made the mentioned changes, please take a look. @davepagurek Thank you! |
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.
Nice work on this so far! I've added a few more comments about filling out the documentation, and whether or not we want to also add flipU and flipV support to the options object for convenience.
Btw looks like tests are failing due to this linting error:
|
I tried adding the examples, how could these errors be solved? |
That's expected if you fill everything with a solid color. Since we're only flipping the texture coordinates, we will only see a difference if you load an image and use it as a texture. Maybe we can do that in the examples? |
Right! On trying to load an image, the example doesn't seem to work. * let img
* let myModel;
*
* function preload() {
* img = loadImage('assets/laDefense.jpg');
* myModel = loadModel('assets/octahedron.obj');
* }
*
* function setup() {
* createCanvas(400, 400, WEBGL);
* background(200);
* }
* function draw() {
* background(0);
* translate(-150, 0, 0);
* texture(img);
* noStroke();
* plane(100);
*
* translate(150, 0, 0);
* flipU(myModel);
* texture(img);
* noStroke();
* plane(100);
* model(myModel);
*
* }
* </code>
* </div> Could you suggest how I can make it better? |
Just took a look again! Some notes:
|
Thank you very much, @davepagurek. Do you think any of these are okay to go ahead with, how can I make it work? let img;
let model1;
let model2;
function preload() {
img = loadImage('assets/laDefense.jpg');
}
function setup() {
createCanvas(200, 200, WEBGL);
background(200);
model1 = buildGeometry(() => plane(50));
model2 = buildGeometry(() => plane(50));
model2.flipU();
}
function draw() {
background(0);
// original
push();
translate(-25, -25, 0);
texture(img);
noStroke();
plane(50);
model(model1);
pop();
//flipped
push();
translate(25, 25, 0);
texture(img);
noStroke();
plane(50);
model(model2);
pop();
} let img;
let model1;
let model2;
function preload() {
img = loadImage('assets/laDefense.jpg');
}
function setup() {
createCanvas(200, 200, WEBGL);
background(200);
model1 = createShape(50, 50);
model2 = createShape(50, 50);
model2.flipU();
}
function draw() {
background(0);
//original
push();
translate(-25, -25, 0);
texture(img);
noStroke();
plane(50);
model(model1);
pop();
// flipped
push();
translate(25, 25, 0);
texture(img);
noStroke();
plane(50);
model(model2);
pop();
}
function createMyShape(w, h) {
let myShape = createGraphics(w, h);
myShape.beginShape();
myShape.vertex(-w / 2, -h / 2, 0, 0);
myShape.vertex(w / 2, -h / 2, 1, 0);
myShape.vertex(w / 2, h / 2, 1, 1);
myShape.vertex(-w / 2, h / 2, 0, 1);
myShape.endShape(CLOSE);
return myShape;
} |
I think that first version will work! The second one could also work with some modifications (and would maybe actually be preferable since you can see the UV values being set!) The secnd example is currently returning a function createMyShape(w, h) {
return buildGeometry(() => {
textureMode(NORMAL);
beginShape();
vertex(-w / 2, -h / 2, 0, 0);
vertex(w / 2, -h / 2, 1, 0);
vertex(w / 2, h / 2, 1, 1);
vertex(-w / 2, h / 2, 0, 1);
endShape(CLOSE);
})
} |
Hi @davepagurek please take a look, the examples work now. |
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.
Awesome, the examples look great!
I think the last thing to do is make sure that the new options in loadModel
get displayed in the p5 reference properly. I left a comment with a suggestion there. After that we should be good to go!
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 for updating the docs, I think this is good to merge now!
@all-contributors please add @deveshidwivedi for code |
I've put up a pull request to add @deveshidwivedi! 🎉 |
Resolves #5021
Changes:
The existing
loadModel()
method signatures are maintained, but a new, more flexible method is introduced asloadModel(path, [options]
. This new method allows users to specify optional parameters in an options object, providing greater control over the loading process without being constrained by parameter order. The addition offlipU()
andflipV()
options enables users to apply U and V flipping to models after they've been loaded.Screenshots of the change:
before:
after:
before:
after:
PR Checklist
npm run lint
passes