Files
housesof/src/globe/beam/Mesh.js
Félix Péault 2064885997 WIP Interactive globe from Nico's sources
- The globe is a bit small? Ability to control the max-min size potentially
- Is there a reason why `globe.update()` runs every second? Sounds like a lot of resources?
- Have the ability to control the `addEventListener` of the markers to do whatever (in this case, going to a route by clicking on a link with a sapper-noscroll attribute + changing the href attribute on click - the method `goto` from Sapper scrolls back to top / maybe something to fix with the current transition issues?)
- Edited in `./index.js`:
    1. Using the class as `export default WebglGlobe` instead of Window (as Svelte or Sapper doesn't likayt)
- Edited in `Camera.js`:
    1. Commented line 218: `e.preventDefault();` would cause this error: `[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See <URL>`
2020-04-02 20:59:40 +02:00

90 lines
2.6 KiB
JavaScript
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Container from './Container';
import * as mat4 from './glMatrix/mat4';
class Mesh extends Container {
constructor(options) {
super();
this.material = null;
this.geometry = null;
this.options = options || {};
this._viewMatrix = mat4.create()
this._invViewMatrix = mat4.create()
this._modelViewMatrix = mat4.create()
this._normalMatrix = mat4.create()
}
render(camera, options={}) {
super.render( camera, options );
let material = options.overrideMaterial || this.material;
if (camera && material &&
this.geometry && //TODO: check for geometry.length
this.visible) {
if (this.options.beforeRender) {
this.options.beforeRender()
}
// setTimeout(()=>{
mat4.invert(this._viewMatrix, camera.worldMatrix);
mat4.multiply(this._modelViewMatrix, this._viewMatrix, this.worldMatrix);
if (material.uniforms['uInverseViewMatrix'] !== void 0) {
mat4.copy(this._invViewMatrix, camera.worldMatrix);
mat4.invert(this._invViewMatrix, this._invViewMatrix);
material.uniforms['uInverseViewMatrix'].value = camera.worldMatrix;
}
if (material.uniforms['uCameraPosition'] !== void 0) {
material.uniforms['uCameraPosition'].value = camera.position;
}
if (material.uniforms['uVMatrix'] !== void 0) {
material.uniforms['uVMatrix'].value = this._viewMatrix;
}
if (material.uniforms['uNormalMatrix'] !== void 0) {
mat4.multiply( this._normalMatrix, this._rotationMat4, this.parent._rotationMat4);
material.uniforms['uNormalMatrix'].value = this._normalMatrix
}
if (material.uniforms['uMMatrix'] !== void 0) {
material.uniforms['uMMatrix'].value = this.worldMatrix;
// console.log('MANUALLY ASSIGN ', this.matrix, this.name)
// console.log('setMM', this.name, this.matrix[0], this.matrix[1], this.matrix[2], this.matrix[3])
}
if (material.uniforms['uMVMatrix'] !== void 0) {
material.uniforms['uMVMatrix'].value = this._modelViewMatrix;
}
if (material.uniforms['uPMatrix'] !== void 0) {
material.uniforms['uPMatrix'].value = camera.projectionMatrix;
}
for (let u in options.uniforms) {
if (material.uniforms[ u ] !== void 0) {
material.uniforms[ u ].value = options.uniforms[u];
}
}
let needsCompile = false;
for (let k in options.defines) {
if (material.defines[ k ] !== options.defines[ k ]) {
material.defines[ k ] = options.defines[ k ];
needsCompile = true;
}
}
if (needsCompile) {
material.compile();
}
material.draw( this.geometry );
// })
}
}
}
export default Mesh;