-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Add independent loadModel() U and V flipping flags #5021
Comments
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already. |
I would go for an configuration object as to the flipU, flipV additional parameter, similar to the options one in:
Such a key-value object helps adding other fancy options for the future without always increasing loadModel()'s parameters number. That other objects may also be a sort of symbol for options that do not originate from Processing. |
Thanks @myselfhimself! I agree that an object literal parameter would be a good idea here. I can see more parameters being added to |
Thanks for commenting
Indeed fileType could force the parser to interpret some file without
extension to be detected as something specific (obj, stl..), such as a blob
downloaded or from some remote server or badly named.. I wonder if that
should be dealt with in a different issue or this one; the amount of code
may not be that big though for it, so we might want to rename the present
issue to "Add 'options' object parameter to loadModel() for U,V flipping,
fileType". What do you think?
Not being a native english speaker, what would be more natural for UV
flipping keyword parameters:
flipU:bool
flipV:bool
or invertU:bool
invertV:bool
?
út 2. 2. 2021 v 16:32 odesílatel Stalgia Grigg <[email protected]>
napsal:
… Thanks @myselfhimself <https://github.com/myselfhimself>! I agree that an
object literal parameter would be a good idea here. I can see more
parameters being added to loadModel() in the future and there are already
quite a few. I wonder if fileType should be part of the options parameter.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5021 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJU5QXO2225Q6FJMM6OA43S5ALJPANCNFSM4WY7DHAA>
.
|
Hi! Is this issue still open to work on? |
Hello I haven't implemented the idea. It could be done by anyone.
Le mer. 13 déc. 2023, 16:39, Deveshi Dwivedi ***@***.***> a
écrit :
… Hi! Is this issue still open to work on?
—
Reply to this email directly, view it on GitHub
<#5021 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJU5QUIMBZL6SM6LMVCQP3YJHD2HAVCNFSM4WY7DHAKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBVGQYTMNBSHA2Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I'd like to take this up please. Could you please guide me how to go about it? |
Hi! I think in loading.js, we could introduce the parameters as: /**
* Load a 3D model with optional UV flipping.
* @method loadModel
* @param {String} path
* @param {function(p5.Geometry)} [successCallback]
* @param {function(Event)} [failureCallback]
* @param {String} [fileType]
* @param {Object} [options]
* @param {boolean} [options.normalize]
* @param {boolean} [options.flipU]
* @param {boolean} [options.flipV]
* @return {p5.Geometry} the <a href="#/p5.Geometry">p5.Geometry</a> object
*/ Introducing additional parameters to the loadModel function to allow for more flexibility and customization: p5.prototype.loadModel = function(path, successCallback, failureCallback, fileType, options) Declaration of the parameters: let normalize = false;
let flipU = false;
let flipV = false;
if (options && typeof options === 'object') {
normalize = options.normalize || false;
flipU = options.flipU || false;
flipV = options.flipV || false;
} Modifying loaded model for U V flipping: if (fileType.match(/\.obj$/i)) {
this.loadStrings(
path,
strings => {
parseObj(model, strings, { flipU, flipV });
if (normalize) {
model.normalize();
}
self._decrementPreload();
if (typeof successCallback === 'function') {
successCallback(model);
}
},
failureCallback
); Now, the function accepts an additional options parameter. |
@davepagurek I'd request you to give your views as well! |
Thanks for your interest @deveshidwivedi! A few thoughts:
|
|
Thank you!@davepagurek if (typeof arguments[1] === 'object') {
options = arguments[1];
} else {
options = {
normalize: arguments[1],
successCallback: arguments[2],
failureCallback: arguments[3]
};
if (typeof arguments[4] !== 'undefined') {
fileType = arguments[4];
}
} Could you give an idea as to what the flipU and flipV models would contain? |
@deveshidwivedi that code snippet looks like a decent way to go about it!
I'm imagining something sort of like this: p5.Geometry = class Geometry {
// ...
// (exisiting methods are in here)
// ...
flipU() {
this.uvs = this.uvs.flat().map((val, index) => {
if (index % 2 === 0) {
return 1 - val;
} else {
return val;
}
});
}
} ...and similar for |
@davepagurek I get it now:) I was wondering if we could pass the coordinates as array of pairs to avoid inconsistency. p5.Geometry = class Geometry {
//.....
flipU() {
this.uvs = this.uvs.map(pair => [1 - pair[0], pair[1]]);
return this;
}
flipV() {
this.uvs = this.uvs.map(pair => [pair[0], 1 - pair[1]]);
return this;
}
} Does this seem okay? |
Avoiding inconsistency would be great! Just a question of whether to standardize on a flat array or on an array of pairs. Right now I think it might be a slightly better choice to standardize on a flat array? It looks like that's how most code in p5 treats it already (some exceptions in some shapes in webgl/3d_primitives.js, and for loaded models in webgl/loading.js) and arrays need to be flat anyway when passed into vertex buffers for the native WebGL APIs, so it would be a bit more efficient to store them in that format from the start. Can you think of any drawbacks of that format? |
Do those tests fail for you on the |
The tests failed due to the changes introduced. I tried to make it better but it still needs improvement. There are still some errors due to |
I'm sorry for being unclear, the errors I was getting were different than timeout errors after I made changes. I understand where the problem is. I will try to work on this bit to see that all the three cases are handled. Thank you! |
no problem, good luck! |
Hi! @davepagurek
|
Enhanced loadModel() method signature with independent U and V flipping options.
Hello,
How would this new feature help increase access to p5.js?
The feature suggests adding extra parameters to loadModel() so that OBJ files can have their U and/or V texture coordinates flipped, in order to fine-tune flipped texture displays.
Most appropriate sub-area of p5.js?
Feature enhancement details:
In issue #4866 and related PR #5017, we fixed p5js's OBJ vertex UV texture coordinates parsing's behaviour to more closely match that of Processing, where the V coordinate is inverted, to anticipate WebGL's flipping of that V/Y coordinate. Still, this does not solve all texture horizontal or vertical flipping issues for people exporting .OBJ files for a p5js import using many kinds of 3d software.
Diverging slightly from Processing's loadShape() (which tolerates .OBJ files to make 3d geometries)'s signature, why not add 2 parameters to the p5js
loadModel(modelPath:String, normalize:boolean)
, giving one of those possibilities:loadModel(modelPath:String, normalize:boolean, flipU:boolean, flipV:boolean)
loadModel(modelPath:String, normalize:boolean, flipUV:list)
where flipUV would be a list of two 0-1 integers, eg. [0,1] for U and V respectivelyThanks @stalgiag for pushing me into adding this new issue
The text was updated successfully, but these errors were encountered: