Skip to content

Commit 8686e33

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

40 files changed

+7614
-1197
lines changed
 

‎angular/laptop-holder/package-lock.json

+235-337
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎angular/laptop-holder/package.json

+1-1
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

+3
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

+40
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

+36
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

+101
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

+9
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.

‎nextjs/simple/app/globals.css

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
:root {
6+
--background: #ffffff;
7+
--foreground: #171717;
8+
}
9+
10+
@media (prefers-color-scheme: dark) {
11+
:root {
12+
--background: #0a0a0a;
13+
--foreground: #ededed;
14+
}
15+
}
16+
17+
body {
18+
color: var(--foreground);
19+
background: var(--background);
20+
font-family: Arial, Helvetica, sans-serif;
21+
}
22+
23+
canvas {
24+
width: 100%;
25+
height: 100%;
26+
outline: none;
27+
}

‎nextjs/simple/app/jscad.worker.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference lib="webworker" />
2+
/*eslint no-restricted-globals: 0*/
3+
4+
import { Workers } from '@bitbybit-dev/core';
5+
6+
import("@bitbybit-dev/core/jscad-generated")
7+
.then((s) => {
8+
Workers.initializationComplete(s.default());
9+
});
10+
11+
addEventListener('message', ({ data }) => {
12+
Workers.onMessageInput(data, postMessage);
13+
});

‎nextjs/simple/app/layout.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { Metadata } from "next";
2+
import localFont from "next/font/local";
3+
import "./globals.css";
4+
5+
const geistSans = localFont({
6+
src: "./fonts/GeistVF.woff",
7+
variable: "--font-geist-sans",
8+
weight: "100 900",
9+
});
10+
const geistMono = localFont({
11+
src: "./fonts/GeistMonoVF.woff",
12+
variable: "--font-geist-mono",
13+
weight: "100 900",
14+
});
15+
16+
export const metadata: Metadata = {
17+
title: "Create Next App",
18+
description: "Generated by create next app",
19+
};
20+
21+
export default function RootLayout({
22+
children,
23+
}: Readonly<{
24+
children: React.ReactNode;
25+
}>) {
26+
return (
27+
<html lang="en">
28+
<body
29+
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
30+
>
31+
{children}
32+
</body>
33+
</html>
34+
);
35+
}

‎nextjs/simple/app/occ.worker.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference lib="webworker" />
2+
/*eslint no-restricted-globals: 0*/
3+
import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt";
4+
import type { OpenCascadeInstance } from '@bitbybit-dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.js';
5+
import { initializationComplete, onMessageInput } from '@bitbybit-dev/occt-worker';
6+
7+
initOpenCascade().then((occ: OpenCascadeInstance) => {
8+
initializationComplete(occ, undefined);
9+
});
10+
11+
addEventListener('message', ({ data }) => {
12+
onMessageInput(data, postMessage);
13+
});

0 commit comments

Comments
 (0)
Please sign in to comment.