Skip to content

Commit 8686e33

Browse files
nextjs example + v0.17.3 update
1 parent 03f63a0 commit 8686e33

40 files changed

+7614
-1197
lines changed

angular/laptop-holder/package-lock.json

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

angular/laptop-holder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"private": true,
1212
"dependencies": {
13-
"@bitbybit-dev/core": "0.17.1",
13+
"@bitbybit-dev/core": "0.17.3",
1414
"@angular/animations": "13.3.0",
1515
"@angular/common": "13.3.0",
1616
"@angular/compiler": "13.3.0",

nextjs/simple/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["next/core-web-vitals", "next/typescript"]
3+
}

nextjs/simple/.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
32+
# env files (can opt-in for commiting if needed)
33+
.env*
34+
35+
# vercel
36+
.vercel
37+
38+
# typescript
39+
*.tsbuildinfo
40+
next-env.d.ts

nextjs/simple/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

nextjs/simple/app/bitbybit.tsx

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
'use client'
2+
import { BitByBitBase } from "@bitbybit-dev/core";
3+
import { OccStateEnum } from '@bitbybit-dev/occt-worker';
4+
import { Engine, Scene, Color4, ArcRotateCamera, Vector3, HemisphericLight, Light } from "@babylonjs/core";
5+
import { useEffect, useRef } from "react";
6+
7+
export default function Bitbybit() {
8+
const initialized = useRef(false)
9+
10+
useEffect(() => {
11+
if (!initialized.current) {
12+
const bitbybit = new BitByBitBase();
13+
const canvas = document.getElementById('renderCanvas') as HTMLCanvasElement;
14+
canvas.onwheel = function (event) {
15+
event.preventDefault();
16+
};
17+
18+
const engine = new Engine(canvas);
19+
const scene = new Scene(engine);
20+
engine.setHardwareScalingLevel(0.5);
21+
scene.clearColor = new Color4(26 / 255, 28 / 255, 31 / 255, 1);
22+
const camera = new ArcRotateCamera('Camera', 0, 10, 10, new Vector3(0, 0, 0), scene);
23+
camera.attachControl(canvas, true);
24+
25+
const light = new HemisphericLight('HemiLight', new Vector3(0, 1, 0), scene);
26+
light.intensityMode = Light.INTENSITYMODE_ILLUMINANCE;
27+
light.intensity = 1;
28+
scene.metadata = { shadowGenerators: [] };
29+
30+
const occt = new Worker(new URL('./occ.worker', import.meta.url), { name: 'OCC', type: 'module' })
31+
const jscad = new Worker(new URL('./jscad.worker', import.meta.url), { name: 'JSCAD', type: 'module' })
32+
33+
bitbybit.init(scene, occt, jscad);
34+
35+
engine.runRenderLoop(() => {
36+
scene.render();
37+
});
38+
39+
window.onresize = () => {
40+
if (engine) {
41+
engine.resize();
42+
}
43+
}
44+
45+
bitbybit.occtWorkerManager.occWorkerState$.subscribe(s => {
46+
if (s.state === OccStateEnum.initialised) {
47+
engine.resize();
48+
49+
const start = async () => {
50+
const sphere = await bitbybit.occt.shapes.solid.createSphere({
51+
radius: 5,
52+
center: [0, 0, 0]
53+
});
54+
55+
const circle = await bitbybit.occt.shapes.wire.createCircleWire({
56+
radius: 10,
57+
center: [0, 0, 0],
58+
direction: [0, 1, 0],
59+
});
60+
61+
const points = await bitbybit.occt.shapes.wire.pointsOnWireAtPatternOfLengths({
62+
shape: circle,
63+
lengths: [0.1, 0.3, 0.4],
64+
includeFirst: true,
65+
includeLast: false,
66+
tryNext: false
67+
})
68+
69+
bitbybit.draw.drawAnyAsync({
70+
entity: sphere
71+
});
72+
73+
bitbybit.draw.drawAnyAsync({
74+
entity: circle
75+
});
76+
77+
bitbybit.draw.drawAnyAsync({
78+
entity: points
79+
});
80+
}
81+
82+
start();
83+
engine.runRenderLoop(() => {
84+
scene.render();
85+
});
86+
} else if (s.state === OccStateEnum.computing) {
87+
// Show Spinner
88+
} else if (s.state === OccStateEnum.loaded) {
89+
// Show Spinner
90+
}
91+
});
92+
}
93+
}, [])
94+
95+
return (
96+
<>
97+
<canvas id="renderCanvas"></canvas>
98+
<div>HELLO</div>
99+
</>
100+
);
101+
}

nextjs/simple/app/client-only.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use client'
2+
import dynamic from "next/dynamic"
3+
import { FunctionComponent, PropsWithChildren } from "react"
4+
5+
const ClientOnly: FunctionComponent<PropsWithChildren> = ({ children }) => children
6+
7+
export default dynamic(() => Promise.resolve(ClientOnly), {
8+
ssr: false,
9+
})

nextjs/simple/app/favicon.ico

25.3 KB
Binary file not shown.
66.3 KB
Binary file not shown.

nextjs/simple/app/fonts/GeistVF.woff

64.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)