Skip to content
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

Set MapNode material #79

Open
atruebin opened this issue Sep 20, 2024 · 3 comments
Open

Set MapNode material #79

atruebin opened this issue Sep 20, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@atruebin
Copy link

Hi there!

I need to use MeshStandardMaterial for the MapPlaneNode so the light affects it. For now it seems the only way to do it is to extend MapPlaneNode class and change material after super() is called.

It would be great to have an option to set the material with constructor argument or have MapNode class atribute storing the material class, so it can be reassigned.

Thank you!

@tentone tentone added the enhancement New feature or request label Sep 21, 2024
@tentone
Copy link
Owner

tentone commented Sep 21, 2024

Hello

We can add a callback to set the material, everytime that a new tile is created.

Would this work for you?

@atruebin
Copy link
Author

It will still be created with MeshBasicMaterial, and changed after, right? I propose options to change it before creation.

@rotu
Copy link

rotu commented Oct 24, 2024

This tripped me up too. I would think that you could pass in a factory function that creates the material, or that you would set MapView.material and each tile would inherit that material (or actually a clone() thereof.

I think I expected (and would like) MapPlaneNode.createChildNodes() to look more like this, which I think is in line with @atruebin's suggestion:

// ...
let node = new Constructor(this, this.mapView, QuadTreePosition.topLeft, level, x, y);
// ...
material = this.material.clone();
material.map = MapNode.defaultTexture;
node.setMaterial(material);
// ... create other child nodes

I think it would suffice to have a onNodeCreated callback on the MapView object which allows overriding the mesh or material as @tentone suggested.


To actually change the material in MapView, I had to make the below change, which felt a little awkward.

From this:

const map_view = new MapView(MapView.PLANAR, map_provider)

To this:

class MyMapPlaneNode extends MapPlaneNode {
   constructor(...args) {
      super(...args);
      this.material = new THREE.MeshBasicMaterial({ transparent: true, opacity: 0.5 });
   }
}
const map_view = new MapView(MapView.PLANAR, map_provider);
map_view.setRoot(new MyMapPlaneNode(null, map_view));

I was also a little thrown off by language in the readme which suggests that each node should not necessarily have its own Material. That doesn't really seem doable with the current shader setup.

These materials and geometries can be customized and are not required to be of any specific type. It is recommended to reuse them as much as possible to save memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants