Maybe this is over the limit off what I can understand (or learn). But I tried the following:
const assets = {
ship: new pc.Asset("ship", "container", {
url: "/assets/models/ship/Ship_2K.glb",
}),
clouds: new pc.Asset("clouds", "texture", {
url: "/assets/textures/clouds.jpg",
}),
opacityShader: new pc.Asset("opacityShader", "shader", {
url: "/assets/shaders/opacity-fade.txt",
}),
};
const assetListLoader = new pc.AssetListLoader(
Object.values(assets),
app.assets
);
assetListLoader.load((err, failed) => {
if (err) {
console.log(`assets failed to load: ${err}`);
} else {
console.log(`assets loaded`);
const ship = assets.ship.resource.instantiateRenderEntity();
app.root.addChild(ship);
ship.setPosition(0, 5, 0);
ship.rotate(0, 0, -22);
ship.rotate(0, -45, 0);
// create camera entity
const camera = new pc.Entity("camera");
camera.addComponent("camera", {
clearColor: new pc.Color(0, 0, 0, 0),
});
app.root.addChild(camera);
camera.setPosition(-3, 5, 10);
// create directional light entity
const dirLight = new pc.Entity("light");
dirLight.addComponent("light", {
//type: "omni",
type: "directional",
//color: new pc.Color(0.7, 0.9, 1),
intensity: 5,
});
app.root.addChild(dirLight);
dirLight.setEulerAngles(0, 0, 45);
// prepare ship transistion
const material = ship.model.material;
material.chunks.APIVersion = pc.CHUNKAPI_1_56;
material.chunks.opacityPS = assets.opacityShader.resource;
material.setParameter("uHeightMap", assets.clouds.resource);
material.update();
let time = 0;
app.on("update", function (dt) {
time += 0.2 * dt;
// reverse time
let t = time % 2;
if (t > 1) {
t = 1 - (t - 1);
}
// set time parameter for the shader
material.setParameter("uTime", t);
material.update();
});
app.start();
}
});
So I load the ship, cloud texture and shader code assets. This seems to work.
Then I create the ship, camera and a light. All seems to work ok too.
But then I want to override the opacity shader chunk for the ship. But that give the error that ship.model is undefined. While according the reference an entity should have a model object.