I’m having trouble trying to reproduce this image
I added all the lights but it looks the same?
Okay, I think I see the issue you have in this separate project: https://playcanvas.com/project/954661/overview/spotlight
I’m unsure on why you need code for this as you can set the glossiness factor to 0 on the material that doesn’t have a glossiness texture on it.
But to answer your question directly, I’ve added the code to the above project so it does it at runtime:
// 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();
}
}
}
};
Hey ! It’s exactly what i want thansk a lot!
Finally I succeeded with my own script, I also put my solution.
var LoadRectoGloss = pc.createScript('loadRectoGloss');
LoadRectoGloss.attributes.add('loadingScreenEntitysa', { type: 'entity' });
// initialize code called once per entity
LoadRectoGloss.prototype.initialize = function () {
this.app.assets.loadFromUrl(this.getFileFromUser(), "texture", function (err, asset) {
var recto = this.entity.render.meshInstances[1].material;
recto.glossMap = asset.resource;
if(recto.glossMap){
recto.shininess = 80;
}else{
recto.shininess = 0;
}
recto.update();
}.bind(this));
};
// update code called every frame
LoadRectoGloss.prototype.getFileFromUser = function (dt) {
return "/random_img";
};
A little question about the script order , if i’m loading glossiness with the function LoadFromUrl() , i have to do something special witht the script loading order? because i got some problem with loading glossiness with a script.
When i set it on the editor it works like a charm.
There is your forked project with my scripts : PlayCanvas 3D HTML5 Game Engine
Thanks.
Scripting order shouldn’t matter, no.
If you have an issue with your scripts that aren’t related to the light setup, please post a new thread with an example project and the steps to reproduce the issue.
Ok thanks!