project method
void
project(
- Mesh mesh
)
Implementation
void project(Mesh mesh) {
if (
!(mesh.material is GroupMaterial
? (mesh.material as GroupMaterial).children.any((m) => m is ProjectedMaterial)
: mesh.material is ProjectedMaterial)
) {
throw ('The mesh material must be a ProjectedMaterial');
}
if (
!(mesh.material is GroupMaterial
? (mesh.material as GroupMaterial).children.any((m) => m == this)
: mesh.material == this)
) {
throw ('''The provided mesh doesn't have the same material as where project() has been called from''');
}
// make sure the matrix is updated
mesh.updateWorldMatrix(true, false);
// we save the object model matrix so it's projected relative
// to that position, like a snapshot
this.uniforms['savedModelMatrix']['value'].setFrom(mesh.matrixWorld);
// if the material is not the first, output just the texture
if (mesh.material is GroupMaterial) {
final materialIndex = (mesh.material as GroupMaterial).children.indexOf(this);
if (!(mesh.material as GroupMaterial).children[materialIndex].transparent) {
console.warning('''You have to pass "transparent: true" to the ProjectedMaterial if you're working with multiple materials.''');
}
if (materialIndex > 0) {
this.uniforms['backgroundOpacity']['value'] = 0;
}
}
// persist also the current camera position and matrices
_saveCameraMatrices();
}