Skip to content

Commit

Permalink
Merge pull request #95 from ux3d/fix/removeUIFromGltfView
Browse files Browse the repository at this point in the history
removed canvas from GltfView (GSVN-199)
  • Loading branch information
UX3D-becher authored Jan 25, 2021
2 parents 2a78fb7 + 08caa8b commit 6431a18
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 38 deletions.
3 changes: 1 addition & 2 deletions app_headless/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ async function main()
state.userCamera.fitViewToScene(state.gltf, state.sceneIndex);
state.userCamera.updatePosition();

view.animate(state);
view.renderFrame(state);
view.renderFrame(state, width, height);

let pixels = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
Expand Down
15 changes: 13 additions & 2 deletions app_web/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main()
const canvas = document.getElementById("canvas");
const context = canvas.getContext("webgl2", { alpha: false, antialias: true });
const ui = document.getElementById("app");
const view = new GltfView(context, ui);
const view = new GltfView(context);
const state = view.createState();

initDracoLib();
Expand Down Expand Up @@ -196,7 +196,18 @@ async function main()
}
};

await view.startRendering(state, canvas);
// configure the animation loop
const update = () =>
{
canvas.width = window.innerWidth - ui.getBoundingClientRect().width;
canvas.height = canvas.clientHeight;

view.renderFrame(state, canvas.width, canvas.height);
window.requestAnimationFrame(update);
};

// After this start executing animation loop.
window.requestAnimationFrame(update);
}

export { main };
38 changes: 4 additions & 34 deletions source/GltfView/gltf_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { GL } from '../Renderer/webgl.js';

class GltfView
{
constructor(context, ui)
constructor(context)
{
this.ui = ui;
this.context = context;
this.renderer = new gltfRenderer(this.context);
}
Expand All @@ -16,26 +15,11 @@ class GltfView
return new GltfState();
}

updateCanvas(canvas)
renderFrame(state, width, height)
{
if(this.ui !== undefined)
{
canvas.width = window.innerWidth - this.ui.getBoundingClientRect().width;
}
else
{
canvas.width = canvas.clientWidth;
}
canvas.height = canvas.clientHeight;
}
this.animate(state);

updateViewport(width, height)
{
this.renderer.resize(width, height);
}

renderFrame(state)
{

this.renderer.clearFrame(state.renderingParameters.clearColor);

Expand All @@ -50,6 +34,7 @@ class GltfView

this.renderer.drawScene(state, scene);
}

animate(state)
{
if(state.gltf === undefined)
Expand Down Expand Up @@ -129,21 +114,6 @@ class GltfView
transparentMaterialsCount: transparentMaterials.length
};
}

async startRendering(state, canvas)
{
const update = () =>
{
this.animate(state);
this.updateCanvas(canvas);
this.updateViewport(canvas.width, canvas.height);
this.renderFrame(state);
window.requestAnimationFrame(update);
};

// After this start executing render loop.
window.requestAnimationFrame(update);
}
}

export { GltfView };

0 comments on commit 6431a18

Please sign in to comment.