I asked a question a short time ago, to be able to change the glossiness at runtime depending on whether there was one or not.
So on this project it works perfectly when I setup the glossiness myself in the editor but when I use my scripts to download the glossiness from a url, the script doesn’t work anymore.
my script to get an image from url is :
var LoadVersoGloss = pc.createScript('loadVersoGloss');
LoadVersoGloss.attributes.add('loadingScreenEntitys', { type: 'entity' });
// initialize code called once per entity
LoadVersoGloss.prototype.initialize = function() {
this.app.assets.loadFromUrl(this.getFileFromUser(), "texture", function (err, asset) {
/** @type {pc.StandardMaterial} */
var verso = this.entity.render.meshInstances[0].material;
verso.glossMap = asset.resource;
// if(verso.glossMap){
// verso.shininess = 80;
// }else{
// verso.shininess = 0;
// }
// verso.update();
}.bind(this));
};
// update code called every frame
LoadVersoGloss.prototype.getFileFromUser = function(dt) {
return "https://raw.githubusercontent.com/Xora123/Img/master/rgh2-recto.png";
};
and the script to set up the glossiness at runtime by yaustar :
var SetGlossinessTo0WhenNoTexture = pc.createScript('setGlossinessTo0WhenNoTexture');
// initialize code called once per entity
SetGlossinessTo0WhenNoTexture.prototype.initialize = function() {
if (this.entity.render) {
const materialAssets = this.entity.render.materialAssets;
for (let i = 0; i < materialAssets.length; ++i) {
let asset = materialAssets[i];
// Workaround if the materialAssets are asset ids
if (typeof(asset) === 'number') {
asset = this.app.assets.get(asset);
}
/** @type {pc.StandardMaterial} */
const material = asset.resource;
if (!material.glossMap) {
material.shininess = 0;
material.update();
}
}
}
};
// update code called every frame
SetGlossinessTo0WhenNoTexture.prototype.update = function(dt) {
};
There are two maps/textures, one for glossiness and one for diffuse.
How do you know if a user only uploads just a diffuse and how do you know when they upload glossiness as well?
What you have to do is have a single script that knows whether or not the user has uploaded a glossiness texture/map and adjust the shininess according. You can’t do this with two separate scripts.
Ok, I’m new to code, so what I did is two scripts, as said above, and so if the user only uploads a texture, , there’s an error with my 2nd script in the console, but I still see this texture on my object, so in my head it was fine aha.
Maybe I can create two scenes per object, one with diffuse + glossiness and one with diffuse without glossiness and let the choice to the user, but since I already have 10 scenes, I didn’t find it very practical, but if I have to go through it I will do it