Skip to content

Commit f824152

Browse files
committed
WebGL sample
1 parent 6832d24 commit f824152

9 files changed

Lines changed: 1380 additions & 1 deletion

File tree

OCC_logo.png

11.2 KB
Loading

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
Open CASCADE Technology - WebGL sample
22
======================================
33

4+
## About this project
5+
6+
![Open CASCADE Technology logo](/images/occt_draw_logo.png)
7+
48
This is a web DEMO of WebGL sample coming with Open CASCADE Technology.
9+
The DEMO itself could be found here:<br>
10+
https://gkv311.github.io/occt-webgl/
11+
12+
Requirements - any modern browser:
13+
- Running 64-bit;
14+
- Supporting *WebAssembly*;
15+
- Hardware-accelerated *WebGL 2.0*;
16+
- 3+ GB of memory (RAM) available on device.
17+
18+
## About Open CASCADE Technology
19+
20+
Open CASCADE Technology (OCCT) is an open source full-scale 3D geometry library.
21+
Striving to be one of the best free cad software kernels, OCCT is widely used for the development of specialized programs
22+
dealing with the following engineering and mechanical domains:
23+
3D modeling (CAD), manufacturing (CAM), numerical simulation (CAE), measurement equipment (CMM) and quality control (CAQ).
24+
Since its publication in 1999 as an open source CAD software kernel,
25+
OCCT has been successfully used in numerous projects ranging from building and construction to aerospace and automotive.
26+
527
Please visit official site for more information:<br/>
6-
https://dev.opencascade.org
28+
[https://dev.opencascade.org](https://dev.opencascade.org)

images/occt_draw_logo.png

16.9 KB
Loading

index.html

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!DOCTYPE html>
2+
<html lang=en-us>
3+
<head>
4+
<meta charset=utf-8><meta content="text/html; charset=utf-8" http-equiv=Content-Type>
5+
<link rel="shortcut icon" href="lamp.ico" type="image/x-icon" />
6+
<title>OCCT WebGL Viewer Sample</title>
7+
</head>
8+
<body>
9+
10+
<h2>OCCT WebGL Viewer Sample</h2>
11+
<div>
12+
<canvas id=occViewerCanvas oncontextmenu=event.preventDefault() tabindex=-1 style="border:0 none;background-color:#000" width="409" height="409"></canvas>
13+
<img id=occlogo src="OCC_logo.png" style="position: absolute; left: 20px; top: 0px; z-index: 2;" />
14+
</div>
15+
16+
<div>
17+
<label for="fileInput">Choose BREP file to upload: </label><input type="file" id="fileInput" accept=".brep">
18+
<input type="button" value="Clear All" onclick="OccViewerModule.removeAllObjects()">
19+
<input type="button" value="Fit All" onclick="OccViewerModule.fitAllObjects(true)">
20+
</div>
21+
<p>Repository: <a href="https://github.com/gkv311/occt-webgl">https://github.com/gkv311/occt-webgl</a></p>
22+
<h4>Console output:</h4>
23+
<p id="output"></p>
24+
<script>
25+
//! Resize canvas to fit into window.
26+
function updateCanvasSize()
27+
{
28+
// size of canvas in logical (density-independent) units
29+
var aSizeX = Math.min (window.innerWidth, window.screen.availWidth);
30+
var aSizeY = Math.min (window.innerHeight, window.screen.availHeight);
31+
aSizeX = Math.max (300, aSizeX - 30);
32+
aSizeY = Math.max (300, aSizeY / 2);
33+
occViewerCanvas.style.width = aSizeX + "px";
34+
occViewerCanvas.style.height = aSizeY + "px";
35+
36+
// drawing buffer size (aka backing store)
37+
var aDevicePixelRatio = window.devicePixelRatio || 1;
38+
occViewerCanvas.width = aSizeX * aDevicePixelRatio;
39+
occViewerCanvas.height = aSizeY * aDevicePixelRatio;
40+
41+
occlogo.style.top = (aSizeY - 30) + "px";
42+
}
43+
window.onresize = updateCanvasSize;
44+
updateCanvasSize();
45+
46+
//! Check browser support.
47+
function isWasmSupported()
48+
{
49+
try {
50+
if (typeof WebAssembly === "object"
51+
&& typeof WebAssembly.instantiate === "function") {
52+
const aDummyModule = new WebAssembly.Module (Uint8Array.of (0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
53+
if (aDummyModule instanceof WebAssembly.Module)
54+
{
55+
return new WebAssembly.Instance(aDummyModule) instanceof WebAssembly.Instance;
56+
}
57+
}
58+
} catch (e) {}
59+
return false;
60+
}
61+
if (!isWasmSupported())
62+
{
63+
var anElement = document.getElementById('output');
64+
anElement.innerHTML += "Browser is too old - WebAssembly support is missing!<br>Please check updates or install a modern browser.<br>";
65+
}
66+
67+
//! Handle file uploading.
68+
fileInput.onchange = function()
69+
{
70+
if (fileInput.files.length == 0) { return; }
71+
// Warning! Entire file is pre-loaded into memory.
72+
var aFile = fileInput.files[0];
73+
var aReader = new FileReader();
74+
aReader.onload = function()
75+
{
76+
var aDataArray = new Uint8Array (aReader.result);
77+
const aDataBuffer = OccViewerModule._malloc (aDataArray.length);
78+
OccViewerModule.HEAPU8.set (aDataArray, aDataBuffer);
79+
OccViewerModule.openFromMemory (aFile.name, aDataBuffer, aDataArray.length, true);
80+
//OccViewerModule._free (aDataBuffer); will be freed by called method
81+
OccViewerModule.displayGround (true);
82+
};
83+
aReader.readAsArrayBuffer(aFile);
84+
};
85+
</script>
86+
<script type="text/javascript" src="occt-webgl-sample.js" charset="utf-8"></script>
87+
</body>
88+
</html>

lamp.ico

2.19 KB
Binary file not shown.

occt-webgl-sample.html

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<!DOCTYPE html>
2+
<html lang=en-us>
3+
<head>
4+
<meta charset=utf-8><meta content="text/html; charset=utf-8" http-equiv=Content-Type>
5+
<link rel="shortcut icon" href="lamp.ico" type="image/x-icon" />
6+
<title>OCCT WebGL Viewer Sample</title>
7+
</head>
8+
<body>
9+
10+
<h2>OCCT WebGL Viewer Sample</h2>
11+
<div>
12+
<canvas id=occViewerCanvas oncontextmenu=event.preventDefault() tabindex=-1 style="border:0 none;background-color:#000" width="409" height="409"></canvas>
13+
<img id=occlogo src="OCC_logo.png" style="position: absolute; left: 20px; top: 0px; z-index: 2;" />
14+
</div>
15+
16+
<div>
17+
<label for="fileInput">Choose BREP file to upload: </label><input type="file" id="fileInput" accept=".brep">
18+
<input type="button" value="Clear All" onclick="OccViewerModule.removeAllObjects()">
19+
<input type="button" value="Fit All" onclick="OccViewerModule.fitAllObjects(true)">
20+
</div>
21+
<p>Repository: <a href="https://github.com/gkv311/occt-webgl">https://github.com/gkv311/occt-webgl</a></p>
22+
<h4>Console output:</h4>
23+
<p id="output"></p>
24+
<script>
25+
//! Resize canvas to fit into window.
26+
function updateCanvasSize()
27+
{
28+
// size of canvas in logical (density-independent) units
29+
var aSizeX = Math.min (window.innerWidth, window.screen.availWidth);
30+
var aSizeY = Math.min (window.innerHeight, window.screen.availHeight);
31+
aSizeX = Math.max (300, aSizeX - 30);
32+
aSizeY = Math.max (300, aSizeY / 2);
33+
occViewerCanvas.style.width = aSizeX + "px";
34+
occViewerCanvas.style.height = aSizeY + "px";
35+
36+
// drawing buffer size (aka backing store)
37+
var aDevicePixelRatio = window.devicePixelRatio || 1;
38+
occViewerCanvas.width = aSizeX * aDevicePixelRatio;
39+
occViewerCanvas.height = aSizeY * aDevicePixelRatio;
40+
41+
occlogo.style.top = (aSizeY - 30) + "px";
42+
}
43+
window.onresize = updateCanvasSize;
44+
updateCanvasSize();
45+
46+
//! Check browser support.
47+
function isWasmSupported()
48+
{
49+
try {
50+
if (typeof WebAssembly === "object"
51+
&& typeof WebAssembly.instantiate === "function") {
52+
const aDummyModule = new WebAssembly.Module (Uint8Array.of (0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
53+
if (aDummyModule instanceof WebAssembly.Module)
54+
{
55+
return new WebAssembly.Instance(aDummyModule) instanceof WebAssembly.Instance;
56+
}
57+
}
58+
} catch (e) {}
59+
return false;
60+
}
61+
if (!isWasmSupported())
62+
{
63+
var anElement = document.getElementById('output');
64+
anElement.innerHTML += "Browser is too old - WebAssembly support is missing!<br>Please check updates or install a modern browser.<br>";
65+
}
66+
67+
//! Handle file uploading.
68+
fileInput.onchange = function()
69+
{
70+
if (fileInput.files.length == 0) { return; }
71+
// Warning! Entire file is pre-loaded into memory.
72+
var aFile = fileInput.files[0];
73+
var aReader = new FileReader();
74+
aReader.onload = function()
75+
{
76+
var aDataArray = new Uint8Array (aReader.result);
77+
const aDataBuffer = OccViewerModule._malloc (aDataArray.length);
78+
OccViewerModule.HEAPU8.set (aDataArray, aDataBuffer);
79+
OccViewerModule.openFromMemory (aFile.name, aDataBuffer, aDataArray.length, true);
80+
//OccViewerModule._free (aDataBuffer); will be freed by called method
81+
OccViewerModule.displayGround (true);
82+
};
83+
aReader.readAsArrayBuffer(aFile);
84+
};
85+
</script>
86+
<script type="text/javascript" src="occt-webgl-sample.js" charset="utf-8"></script>
87+
</body>
88+
</html>

occt-webgl-sample.js

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

occt-webgl-sample.wasm

9.31 MB
Binary file not shown.

samples/Ball.brep

Lines changed: 1131 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)