mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0031373: Samples - provide sample combining OCCT and 3 viewer
This commit is contained in:
@@ -52,6 +52,14 @@ namespace
|
|||||||
return aDevicePixelRatio;
|
return aDevicePixelRatio;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*EM_JS(void, jsSetOcctCamera, (float theFOV, float theAspect, float theNear, float theFar), {
|
||||||
|
setOcctCamera();
|
||||||
|
});*/
|
||||||
|
|
||||||
|
EM_JS(void, jsPostFrameRender, (), {
|
||||||
|
postFrameRender();
|
||||||
|
});
|
||||||
|
|
||||||
//! Return cavas size in pixels.
|
//! Return cavas size in pixels.
|
||||||
static Graphic3d_Vec2i jsCanvasSize()
|
static Graphic3d_Vec2i jsCanvasSize()
|
||||||
{
|
{
|
||||||
@@ -336,7 +344,13 @@ void WasmOcctView::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCt
|
|||||||
const Handle(V3d_View)& theView)
|
const Handle(V3d_View)& theView)
|
||||||
{
|
{
|
||||||
myUpdateRequests = 0;
|
myUpdateRequests = 0;
|
||||||
|
|
||||||
|
theView->Invalidate(); /// Three.js cannot be rendered properly without full redraw
|
||||||
|
glEnable (GL_POLYGON_OFFSET_FILL); /// reset defaults Graphic3d_PolygonOffset after Three.js
|
||||||
|
glPolygonOffset (1.0f, 1.0f);
|
||||||
|
|
||||||
AIS_ViewController::handleViewRedraw (theCtx, theView);
|
AIS_ViewController::handleViewRedraw (theCtx, theView);
|
||||||
|
jsPostFrameRender();
|
||||||
if (myToAskNextFrame)
|
if (myToAskNextFrame)
|
||||||
{
|
{
|
||||||
// ask more frames
|
// ask more frames
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
<div><label for="fileInput">Choose BREP file to upload: </label><input type="file" id="fileInput" accept=".brep"></div>
|
<div><label for="fileInput">Choose BREP file to upload: </label><input type="file" id="fileInput" accept=".brep"></div>
|
||||||
<h4>Console output:</h4>
|
<h4>Console output:</h4>
|
||||||
<p id="output"></p>
|
<p id="output"></p>
|
||||||
|
<script src="three.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
//! Resize canvas to fit into window.
|
//! Resize canvas to fit into window.
|
||||||
function updateCanvasSize()
|
function updateCanvasSize()
|
||||||
@@ -57,6 +58,7 @@ if (!isWasmSupported())
|
|||||||
{
|
{
|
||||||
var anElement = document.getElementById('output');
|
var anElement = document.getElementById('output');
|
||||||
anElement.innerHTML += "Browser is too old - WebAssembly support is missing!<br>Please check updates or install a modern browser.<br>";
|
anElement.innerHTML += "Browser is too old - WebAssembly support is missing!<br>Please check updates or install a modern browser.<br>";
|
||||||
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Define OCCT WebGL Viewer module.
|
//! Define OCCT WebGL Viewer module.
|
||||||
@@ -76,6 +78,44 @@ var Module =
|
|||||||
})()
|
})()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var aCanvas = document.getElementById ('canvas');
|
||||||
|
var aGlCtx = aCanvas.getContext ('webgl2', { alpha: false, depth: true, antialias: false, preserveDrawingBuffer: true } );
|
||||||
|
if (aGlCtx == null)
|
||||||
|
{
|
||||||
|
aGlCtx = aCanvas.getContext ('webgl', { alpha: false, depth: true, antialias: false, preserveDrawingBuffer: true } );
|
||||||
|
}
|
||||||
|
var aScene = new THREE.Scene();
|
||||||
|
var aCamera = new THREE.PerspectiveCamera (75, window.innerWidth / window.innerHeight);
|
||||||
|
//var aRenderer = new THREE.WebGLRenderer ({antialias: true});
|
||||||
|
var aRenderer = new THREE.WebGLRenderer ({antialias: false, canvas: aCanvas, context: aGlCtx});
|
||||||
|
aRenderer.autoClear = false;
|
||||||
|
aRenderer.autoClearColor = false;
|
||||||
|
aRenderer.autoClearDepth = false;
|
||||||
|
aRenderer.autoClearStencil = false;
|
||||||
|
aRenderer.setSize (window.innerWidth,window.innerHeight);
|
||||||
|
//document.body.appendChild (aRenderer.domElement);
|
||||||
|
var aGeom = new THREE.BoxGeometry (1,1,1);
|
||||||
|
var aMat = new THREE.MeshBasicMaterial ({color: 0xff0000});
|
||||||
|
var aCube = new THREE.Mesh (aGeom, aMat);
|
||||||
|
aScene.add (aCube);
|
||||||
|
aCube.position.z = -5; aCube.rotation.x = 10; aCube.rotation.y = 5;
|
||||||
|
/*aRenderer.render (aScene, aCamera);
|
||||||
|
var anAnimate = function(){
|
||||||
|
aCube.rotation.x += 0.01;
|
||||||
|
aRenderer.state.reset();
|
||||||
|
aRenderer.render (aScene, aCamera);
|
||||||
|
requestAnimationFrame (anAnimate);
|
||||||
|
}
|
||||||
|
anAnimate();*/
|
||||||
|
|
||||||
|
function postFrameRender()
|
||||||
|
{
|
||||||
|
//console.log("postFrameRender()"); ///
|
||||||
|
//aCamera.
|
||||||
|
aRenderer.state.reset();
|
||||||
|
aRenderer.render (aScene, aCamera)
|
||||||
|
}
|
||||||
|
|
||||||
//! Handle file uploading.
|
//! Handle file uploading.
|
||||||
fileInput.onchange = function()
|
fileInput.onchange = function()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user