Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspaces with vite for demo running, and rollup for module building #147

Merged
merged 12 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,13 @@ Completed all iterations!

30000013 nodes executed in 2.98 seconds, at a rate of 10067118 steps/second
```

## Developer Setup

Install all dependencies:

yarn install

To start the examples:

yarn dev
14 changes: 14 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
bugfixes: true,
targets: {
esmodules: true,
},
},
],
'@babel/preset-typescript',
],
};
9 changes: 9 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0; url=/three/">
</head>
<body>
</body>
</html>
28 changes: 28 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@behave-graph/examples",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"directories": {
"lib": "lib"
},
"dependencies": {
"behave-graph": "*",
"three": "^0.145.0",
"threeify": "^2.0.2"
},
"devDependencies": {
"commander": "^9.4.1",
"ts-node": "^10.9.1",
"typescript": "^4.7.3",
"vite": "^3.2.3"
},
"scripts": {
"start": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"author": "",
"license": "ISC"
}
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Assert, EventEmitter, IScene, Vec3, Vec4 } from 'behave-graph';
import { Material, Object3D, Quaternion, Vector3, Vector4 } from 'three';

import { Assert } from '../../lib/Diagnostics/Assert.js';
import { EventEmitter } from '../../lib/Events/EventEmitter.js';
import { IScene } from '../../lib/Profiles/Scene/Abstractions/IScene.js';
import { Vec3 } from '../../lib/Profiles/Scene/Values/Internal/Vec3.js';
import { Vec4 } from '../../lib/Profiles/Scene/Values/Internal/Vec4.js';
import { GLTFJson } from './GLTFJson.js';

function mapGlTFNodeIndicesToThreeObject3Ds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</style>
</head>
<body>
<script type="module" src="/dist/examples/three/index.js"></script>
<script type="module" src="index.ts"></script>
Look in the console for output!<br />
Three.JS Example.<br /><br />
</body>
Expand Down
35 changes: 21 additions & 14 deletions src/examples/three/index.ts → examples/three/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
/* eslint-disable no-param-reassign */
import {
DefaultLogger,
Engine,
Logger,
ManualLifecycleEventEmitter,
readGraphFromJSON,
registerCoreProfile,
registerSceneProfile,
Registry,
validateGraph,
validateRegistry
} from 'behave-graph';
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';

import { Logger } from '../../lib/Diagnostics/Logger.js';
import { Engine } from '../../lib/Execution/Engine.js';
import { readGraphFromJSON } from '../../lib/Graphs/IO/readGraphFromJSON.js';
import { validateGraph } from '../../lib/Graphs/Validation/validateGraph.js';
import { DefaultLogger } from '../../lib/Profiles/Core/Abstractions/Drivers/DefaultLogger.js';
import { ManualLifecycleEventEmitter } from '../../lib/Profiles/Core/Abstractions/Drivers/ManualLifecycleEventEmitter.js';
import { registerCoreProfile } from '../../lib/Profiles/Core/registerCoreProfile.js';
import { registerSceneProfile } from '../../lib/Profiles/Scene/registerSceneProfile.js';
import { Registry } from '../../lib/Registry.js';
import { validateRegistry } from '../../lib/validateRegistry.js';
import { ThreeScene } from './ThreeScene.js';

let camera: THREE.PerspectiveCamera | null = null;
Expand All @@ -37,16 +39,19 @@ function onWindowResize() {
}
}

const publicImageUrl = (path: string) => new URL(path, import.meta.url).href;
//

async function loadThreeScene() {
const gltfPromise = new GLTFLoader()
.setPath('/src/graphs/scene/actions/')
.setPath(publicImageUrl('/graphs/scene/actions/'))
.loadAsync('SpinningSuzanne.gltf');

const gltf = await gltfPromise;

const glTFJsonPath = '/src/graphs/scene/actions/SpinningSuzanne.gltf';
const glTFJsonPath = publicImageUrl(
'/graphs/scene/actions/SpinningSuzanne.gltf'
);
const glTFFetchResponse = await fetch(glTFJsonPath);

const glTFJson = await glTFFetchResponse.json();
Expand All @@ -66,7 +71,9 @@ async function main() {
registerCoreProfile(registry, logger, manualLifecycleEventEmitter);
registerSceneProfile(registry, threeScene);

const graphJsonPath = `/src/graphs/scene/actions/SpinningSuzanne.json`;
const graphJsonPath = publicImageUrl(
`/graphs/scene/actions/SpinningSuzanne.json`
);
if (graphJsonPath === undefined) {
throw new Error('no path specified');
}
Expand Down Expand Up @@ -104,7 +111,7 @@ async function main() {
scene = localScene;

const texturePromise = new RGBELoader()
.setPath('/assets/envmaps/')
.setPath(publicImageUrl('/assets/envmaps/'))
.loadAsync('pedestrian_overpass_1k.hdr');

const localRenderer = new THREE.WebGLRenderer({ antialias: true });
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</style>
</head>
<body>
<script type="module" src="/dist/examples/threeify/index.js"></script>
<script type="module" src="index.ts"></script>
<canvas class="framebuffer" id="framebuffer"></canvas>
</body>
</html>
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"include": ["./three", "./threeify", "./web", "./typings/*.d.ts", "../lib"]
}
21 changes: 21 additions & 0 deletions examples/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from 'vite';
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig({
build: {
target: ['es2020'],
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
three: resolve(__dirname, 'three/index.html'),
web: resolve(__dirname, 'web/index.html'),
}
}
},
optimizeDeps: {
esbuildOptions: {
target: 'es2020'
}
}
});
2 changes: 1 addition & 1 deletion src/examples/web/index.html → examples/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</style>
</head>
<body>
<script type="module" src="/dist/examples/web/index.js"></script>
<script type="module" src="index.ts"></script>
Look in the console for output!<br />
</body>
</html>
18 changes: 9 additions & 9 deletions src/examples/web/index.ts → examples/web/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
DefaultLogger,
Engine,
Logger,
ManualLifecycleEventEmitter,
readGraphFromJSON,
registerCoreProfile,
Registry
} from 'behave-graph';
import * as THREEIFY from 'threeify';

import { Logger } from '../../lib/Diagnostics/Logger.js';
import { Engine } from '../../lib/Execution/Engine.js';
import { readGraphFromJSON } from '../../lib/Graphs/IO/readGraphFromJSON.js';
import { DefaultLogger } from '../../lib/Profiles/Core/Abstractions/Drivers/DefaultLogger.js';
import { ManualLifecycleEventEmitter } from '../../lib/Profiles/Core/Abstractions/Drivers/ManualLifecycleEventEmitter.js';
import { registerCoreProfile } from '../../lib/Profiles/Core/registerCoreProfile.js';
import { registerSceneProfile } from '../../lib/Profiles/Scene/registerSceneProfile.js';
import { Registry } from '../../lib/Registry.js';

async function main() {
Logger.onVerbose.clear();
//const geometry = icosahedronGeometry(0.75, 5);
Expand Down
Loading