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

assert for Mesh material check doesn't let THREE.MeshFaceMaterial work #296

Closed
alexcasalboni opened this issue May 31, 2013 · 5 comments
Closed

Comments

@alexcasalboni
Copy link

This check doesn't allow me to use THREE.MeshFaceMaterial with a cube instance:

var red = tQuery.createMeshBasicMaterial().color(0xff0000).get(0);
var green = tQuery.createMeshBasicMaterial().color(0x00ff00).get(0);
var blue = tQuery.createMeshBasicMaterial().color(0x0000ff).get(0);
var multipleMaterial = new THREE.MeshFaceMaterial([red, green, blue, red, green, blue]);
tQuery.createCube().addTo(world).material(multipleMaterial);

And actually the same happens here: without it I could directly call createCube(multipleMaterial).

It looks like instanceof does not work well as a check here.
Is it a bug or an intended limitation?
Thank you

@jeromeetienne
Copy link
Owner

i would say the bug is in three.js :) because i think all material should inherit from THREE.Material but it would not help you much.

i will simply change the assert

@jeromeetienne
Copy link
Owner

there tell me if it fit your need

@alexcasalboni
Copy link
Author

Thank you very much, but actually the main benefit would come from editing here so that it will work simply using tQuery.createCube(multipleMaterial).

By the way, you're right: the problem seems to be about THREE.MeshFaceMaterial prototype definition, since there is no prototype inheritance:

THREE.MeshFaceMaterial = function ( materials ) {
    this.materials = materials instanceof Array ? materials : [];
};
THREE.MeshFaceMaterial.prototype.clone = function () {
    return new THREE.MeshFaceMaterial( this.materials.slice( 0 ) );
};

There should be something similar to THREE.MeshFaceMaterial.prototype = Object.create( THREE.Material.prototype );.

I know that adding multiple inheritance checks all around the library is not very elegant, I will report this issue asap.

Thank you again

@jeromeetienne
Copy link
Owner

i did it this way to reduce the 'spreading bug workaround' effect you talked about

@alexcasalboni
Copy link
Author

If you check the issue I've opened, it looks like it is an intended behaviour, since THREE.MeshFaceMaterial is just a container for multiple materials.

I don't think they're going to make it inherit from THREE.Material.

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

No branches or pull requests

2 participants