Trying to add alphaMap to all trees behind the character in my proof-of-concept and it's not working #236
-
Screenshot of the PoC I'm doing some self-study and using Enable3D's experimental "flat" API, hope that doesn't complicate things. I'm trying to create an Octopath Traveler billboard style proof-of-concept and I'm running into an issue with trying to set the alphaMap for trees that are "behind" the character so they fade/opacity drops. So far, only one tree randomly faded after several reloads of the scene. Here is where I add the randomly placed trees: async createTrees() {
const texture = await this.load.texture('tree1');
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.LinearMipMapLinearFilter;
for(let i = 0; i < 40; i++) {
const tree = new FLAT.SpriteSheet(texture, { width: 68, height: 87 })
tree.setScale(0.05);
tree.position.set(this.getRandomPosition(-30, 30), 2.2, this.getRandomPosition(-30, 30));
tree.name = "tree";
this.scene.add(tree);
//treeIDs.push(tree.id);
}
} Ignore the commented out line, I first tried to track the IDs of all the trees and loop in the And my code in the if(this.scene.getObjectByName("tree").position.z > this.hero.position.z &&
this.scene.getObjectByName("tree").material.alphaMap == null) {
this.scene.getObjectByName("tree").material.alphaMap = this.alphaTree;
}
Is there something I'm doing wrong? Will my code in the Any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I have never used To add alpha, you could do: tree.material.transparent = true
tree.material.opacity = 0.5 Do you render the trees in 2d or 3d space? Can you please upload your tree and alphaTree? |
Beta Was this translation helpful? Give feedback.
I have never used
getObjectByName
. I would add them to anew Map()
.To add alpha, you could do:
Do you render the trees in 2d or 3d space?
Can you please upload your tree and alphaTree?