Skip to content

Instantly share code, notes, and snippets.

@wallabyway
Last active March 31, 2022 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallabyway/e1e40100c8a71b092fa34d9b28533bad to your computer and use it in GitHub Desktop.
Save wallabyway/e1e40100c8a71b092fa34d9b28533bad to your computer and use it in GitHub Desktop.
solving texture material in forgeViewer, so it is completely unlit (no weird lighting artifacts
function getFlatTexture_FlatMaterial(textureUrl) {
const shader = {
side: THREE.DoubleSide,
depthWrite: false,
depthTest: true,
uniforms: {
map: { value: THREE.ImageUtils.loadTexture(textureUrl), type: 't' }
},
fragmentShader: `
varying vec2 vUv;
uniform sampler2D map;
void main() {
vec4 texelColor = texture2D( map, vUv );
gl_FragColor = pow( texelColor, vec4( float( 2.2 ) ) ) ;
}`,
vertexShader: `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
}`,
};
return new THREE.ShaderMaterial(shader);
}
quad(x,y) {
const szTextureURL = `https://api.mapbox.com/v4/mapbox.satellite/16/${59157+x}/${40217-y}.webp?sku=101gdtmdKGvJF&access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA`;
const material = getFlatTexture_FlatMaterial(szTextureURL);
const mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 256, 256 ), material );
mesh.position.set (x*256,y*256, 1);
return mesh;
}
const options = {
env: 'AutodeskProduction',
accessToken: _access_token,
};
Autodesk.Viewing.Initializer(options, () => {
let viewer = new Autodesk.Viewing.Private.GuiViewer3D(document.getElementById('forgeViewer'));
// this line is important...
viewer.start( null, null, null, null, {useIdBufferSelection:true} );
Autodesk.Viewing.Document.load(`urn:${urn}`, (doc) => {
var viewables = doc.getRoot().getDefaultGeometry();
viewer.loadDocumentNode(doc, viewables).then( onLoadFinished );
});
function onLoadFinished() {
viewer.overlays.addScene('map');
viewer.overlays.addMesh(this.quad(0,0), 'map');
viewer.overlays.addMesh(this.quad(0,1), 'map');
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment