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

Cleaning #105

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ name: "CodeQL config"

paths-ignore:
- "node_modules"
- "examples"
- "examples"
- "docs"
- "packages"
33 changes: 24 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import stylistic from '@stylistic/eslint-plugin';

export default [
{
files: ['**/*.{js,ts}'],
},
{
ignores: ['dist', 'vite.config.js', 'examples', 'test', 'docs', 'packages'],
},
js.configs.recommended,
...tseslint.configs.strict,
stylistic.configs.customize({
jsx: false,
semi: true,
commaDangle: 'never',
arrowParens: true,
braceStyle: '1tbs',
blockSpacing: true,
indent: 2,
quoteProps: 'as-needed',
quotes: 'single'
}),
{
ignores: ['dist', 'docs', 'packages']
},
{
rules: {
camelcase: 'warn',
'no-unused-vars': 'off',
'no-undef': 'off',
'prefer-rest-params': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-wrapper-object-types': 'off'
},
},
'@typescript-eslint/no-wrapper-object-types': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-invalid-void-type': 'off',
'@typescript-eslint/no-this-alias': 'off'
// "@typescript-eslint/explicit-function-return-type": "error",
}
}
];
4 changes: 2 additions & 2 deletions examples/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const box = new Mesh(new BoxGeometry(0.1, 0.1, 0.1), new MeshNormalMaterial());
box.draggable = true;
box.on('animate', (e) => box.rotateX(e.delta).rotateY(e.delta * 2));
box.on(['pointerover', 'pointerout'], function (e) {
this.tween('id').to(500, { scale: e.type === 'pointerover' ? 1.5 : 1 }, { easing: 'easeOutElastic' }).start();
this.tween('id').to(500, { scale: e.type === 'pointerover' ? 1.5 : 1 }, { easing: 'easeOutElastic' }).start();
});

const scene = new Scene().add(box);

const main = new Main({ fullscreen: false });
main.createView({ scene, camera: new PerspectiveCameraAuto(70).translateZ(1) });
main.createView({ scene, camera: new PerspectiveCameraAuto(70).translateZ(1) });
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</head>

<body>
<script type="module" src="example.ts"></script>
<script type="module" src="./examples/example.ts"></script>
</body>

</html>
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"vite-plugin-dts": "^4.3.0",
"vite-plugin-externalize-deps": "^0.8.0",
"vite-plugin-static-copy": "^1.0.6",
"vitest": "^0.34.6"
"vitest": "^0.34.6",
"@stylistic/eslint-plugin": "^2.10.1"
},
"peerDependencies": {
"three": ">=0.151.0"
Expand Down
130 changes: 65 additions & 65 deletions packages/InstancedMesh2/examples/example.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
import { Asset, Main, PerspectiveCameraAuto } from '../../../src';
import { ACESFilmicToneMapping, AmbientLight, BufferGeometry, DirectionalLight, FogExp2, Mesh, MeshLambertMaterial, MeshStandardMaterial, PlaneGeometry, Scene, Vector3 } from 'three';
import { MapControls } from 'three/examples/jsm/controls/MapControls';
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min';
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { Sky } from 'three/examples/jsm/objects/Sky';
import { CullingStatic, InstancedMesh2 } from '../src/InstancedMesh2';
// import { Asset, Main, PerspectiveCameraAuto } from '../../../src';
// import { ACESFilmicToneMapping, AmbientLight, BufferGeometry, DirectionalLight, FogExp2, Mesh, MeshLambertMaterial, MeshStandardMaterial, PlaneGeometry, Scene, Vector3 } from 'three';
// import { MapControls } from 'three/examples/jsm/controls/MapControls';
// import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min';
// import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
// import { Sky } from 'three/examples/jsm/objects/Sky';
// import { CullingStatic, InstancedMesh2 } from '../src/InstancedMesh2';

const count = 1000000;
const terrainSize = 200000;
// const count = 1000000;
// const terrainSize = 200000;

const main = new Main({ rendererParameters: { antialias: true } }); // init renderer and other stuff
main.renderer.toneMapping = ACESFilmicToneMapping;
main.renderer.toneMappingExposure = 0.5;
// const main = new Main({ rendererParameters: { antialias: true } }); // init renderer and other stuff
// main.renderer.toneMapping = ACESFilmicToneMapping;
// main.renderer.toneMappingExposure = 0.5;

const camera = new PerspectiveCameraAuto(70, 0.1, 4000).translateY(300).translateZ(-900);
const scene = new Scene();
// const camera = new PerspectiveCameraAuto(70, 0.1, 4000).translateY(300).translateZ(-900);
// const scene = new Scene();

const treeGLTF = (await Asset.load<GLTF>(GLTFLoader, '../tree.glb')).scene.children[0] as Mesh<BufferGeometry, MeshStandardMaterial>;
// const treeGLTF = (await Asset.load<GLTF>(GLTFLoader, '../tree.glb')).scene.children[0] as Mesh<BufferGeometry, MeshStandardMaterial>;

const trees = new InstancedMesh2(treeGLTF.geometry, treeGLTF.material, count, {
behaviour: CullingStatic,
// createEntities: false,
verbose: true,
bvhParams: { maxDepth: 30, maxLeaves: 5 },
onInstanceCreation: (obj, index) => {
obj.position.setX(Math.random() * terrainSize - terrainSize / 2).setZ(Math.random() * terrainSize - terrainSize / 2);
obj.scale.setScalar(Math.random() * 0.1 + 0.1);
obj.rotateY(Math.random() * Math.PI * 2).rotateZ(Math.random() * 0.3 - 0.15);
}
});
// const trees = new InstancedMesh2(treeGLTF.geometry, treeGLTF.material, count, {
// behaviour: CullingStatic,
// // createEntities: false,
// verbose: true,
// bvhParams: { maxDepth: 30, maxLeaves: 5 },
// onInstanceCreation: (obj, index) => {
// obj.position.setX(Math.random() * terrainSize - terrainSize / 2).setZ(Math.random() * terrainSize - terrainSize / 2);
// obj.scale.setScalar(Math.random() * 0.1 + 0.1);
// obj.rotateY(Math.random() * Math.PI * 2).rotateZ(Math.random() * 0.3 - 0.15);
// }
// });

const terrain = new Mesh(new PlaneGeometry(terrainSize, terrainSize, 10, 10), new MeshLambertMaterial({ color: 0x004622 }));
terrain.rotateX(Math.PI / -2);
// const terrain = new Mesh(new PlaneGeometry(terrainSize, terrainSize, 10, 10), new MeshLambertMaterial({ color: 0x004622 }));
// terrain.rotateX(Math.PI / -2);

const sun = new Vector3();
const sky = new Sky();
sky.scale.setScalar(450000);
const uniforms = sky.material.uniforms;
uniforms['turbidity'].value = 5;
uniforms['rayleigh'].value = 2;
// const sun = new Vector3();
// const sky = new Sky();
// sky.scale.setScalar(450000);
// const uniforms = sky.material.uniforms;
// uniforms['turbidity'].value = 5;
// uniforms['rayleigh'].value = 2;

sky.on('animate', (e) => {
sun.setFromSphericalCoords(1, Math.PI / -1.9 + e.total * 0.02, Math.PI / 1.4);
uniforms['sunPosition'].value.copy(sun);
});
// sky.on('animate', (e) => {
// sun.setFromSphericalCoords(1, Math.PI / -1.9 + e.total * 0.02, Math.PI / 1.4);
// uniforms['sunPosition'].value.copy(sun);
// });

const dirLight = new DirectionalLight('white');
dirLight.on('animate', (e) => {
dirLight.intensity = sun.y > 0.1 ? 10 : Math.max(0, sun.y / 0.1 * 10);
dirLight.position.copy(sun).multiplyScalar(terrainSize);
dirLight.target.position.copy(sun).multiplyScalar(-terrainSize);
});
// const dirLight = new DirectionalLight('white');
// dirLight.on('animate', (e) => {
// dirLight.intensity = sun.y > 0.1 ? 10 : Math.max(0, sun.y / 0.1 * 10);
// dirLight.position.copy(sun).multiplyScalar(terrainSize);
// dirLight.target.position.copy(sun).multiplyScalar(-terrainSize);
// });

scene.add(sky, trees, terrain, new AmbientLight(), dirLight, dirLight.target);
// scene.add(sky, trees, terrain, new AmbientLight(), dirLight, dirLight.target);

scene.fog = new FogExp2('white', 0.0004);
scene.on('animate', (e) => scene.fog.color.setHSL(0, 0, sun.y));
// scene.fog = new FogExp2('white', 0.0004);
// scene.on('animate', (e) => scene.fog.color.setHSL(0, 0, sun.y));

main.createView({
scene, camera, onBeforeRender: () => {
camera.updateMatrixWorld(true);
trees.updateCulling(camera);
treeCount.updateDisplay();
}
});
// main.createView({
// scene, camera, onBeforeRender: () => {
// camera.updateMatrixWorld(true);
// trees.updateCulling(camera);
// treeCount.updateDisplay();
// }
// });

const controls = new MapControls(camera, main.renderer.domElement);
controls.maxPolarAngle = Math.PI / 2.1;
controls.minDistance = 100;
controls.maxDistance = 1000;
// const controls = new MapControls(camera, main.renderer.domElement);
// controls.maxPolarAngle = Math.PI / 2.1;
// controls.minDistance = 100;
// controls.maxDistance = 1000;

scene.on("pointermove", (e) => console.log(e.intersection));
sky.interceptByRaycaster = false;
terrain.interceptByRaycaster = false;
// scene.on("pointermove", (e) => console.log(e.intersection));
// sky.interceptByRaycaster = false;
// terrain.interceptByRaycaster = false;

const gui = new GUI();
gui.add(trees.instances as any, 'length').name("instances total").disable();
const treeCount = gui.add(trees, 'count').name("instances rendered").disable();
gui.add(camera, 'far', 1000, 10000, 100).name("camera far").onChange(() => camera.updateProjectionMatrix());
// const gui = new GUI();
// gui.add(trees.instances as any, 'length').name("instances total").disable();
// const treeCount = gui.add(trees, 'count').name("instances rendered").disable();
// gui.add(camera, 'far', 1000, 10000, 100).name("camera far").onChange(() => camera.updateProjectionMatrix());
92 changes: 46 additions & 46 deletions packages/InstancedMesh2/examples/example2.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import { Main, PerspectiveCameraAuto } from '../../../src/';
import { MeshNormalMaterial, Scene, SphereGeometry, Vector3 } from 'three';
import { FlyControls } from 'three/examples/jsm/controls/FlyControls';
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min';
import { CullingDynamic, InstancedMesh2 } from '../src';

const count = 150000;
const worldSize = 20000;

const main = new Main({ rendererParameters: { antialias: true } }); // init renderer and other stuff
const camera = new PerspectiveCameraAuto(70, 0.1, 500);
const scene = new Scene();

const spheres = new InstancedMesh2<{ dir: Vector3 }>(new SphereGeometry(1, 16), new MeshNormalMaterial(), count, {
behaviour: CullingDynamic,
onInstanceCreation: (obj, index) => {
obj.position.randomDirection().multiplyScalar(((Math.random() * 0.99 + 0.01) * worldSize) / 2);
obj.dir = new Vector3().randomDirection();
},
});

spheres.on('animate', (e) => {
for (const mesh of spheres.instances) {
mesh.position.add(mesh.dir.setLength((e.delta || 0.01) * 5));
mesh.updateMatrix();
}
});

scene.add(spheres);

main.createView({ scene, camera, enabled: false, onBeforeRender: () => {
camera.updateMatrixWorld(true);
spheres.updateCulling(camera);
spheresCount.updateDisplay();
}
});

const controls = new FlyControls(camera, main.renderer.domElement);
controls.rollSpeed = Math.PI / 10;
controls.movementSpeed = 50;
scene.on('animate', (e) => controls.update(e.delta));

const gui = new GUI();
gui.add(spheres.instances as any, 'length').name('instances total').disable();
const spheresCount = gui.add(spheres, 'count').name('instances rendered').disable();
gui.add(camera, 'far', 100, 5000, 100).name('camera far').onChange(() => camera.updateProjectionMatrix());
// import { Main, PerspectiveCameraAuto } from '../../../src/';
// import { MeshNormalMaterial, Scene, SphereGeometry, Vector3 } from 'three';
// import { FlyControls } from 'three/examples/jsm/controls/FlyControls';
// import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min';
// import { CullingDynamic, InstancedMesh2 } from '../src';

// const count = 150000;
// const worldSize = 20000;

// const main = new Main({ rendererParameters: { antialias: true } }); // init renderer and other stuff
// const camera = new PerspectiveCameraAuto(70, 0.1, 500);
// const scene = new Scene();

// const spheres = new InstancedMesh2<{ dir: Vector3 }>(new SphereGeometry(1, 16), new MeshNormalMaterial(), count, {
// behaviour: CullingDynamic,
// onInstanceCreation: (obj, index) => {
// obj.position.randomDirection().multiplyScalar(((Math.random() * 0.99 + 0.01) * worldSize) / 2);
// obj.dir = new Vector3().randomDirection();
// },
// });

// spheres.on('animate', (e) => {
// for (const mesh of spheres.instances) {
// mesh.position.add(mesh.dir.setLength((e.delta || 0.01) * 5));
// mesh.updateMatrix();
// }
// });

// scene.add(spheres);

// main.createView({ scene, camera, enabled: false, onBeforeRender: () => {
// camera.updateMatrixWorld(true);
// spheres.updateCulling(camera);
// spheresCount.updateDisplay();
// }
// });

// const controls = new FlyControls(camera, main.renderer.domElement);
// controls.rollSpeed = Math.PI / 10;
// controls.movementSpeed = 50;
// scene.on('animate', (e) => controls.update(e.delta));

// const gui = new GUI();
// gui.add(spheres.instances as any, 'length').name('instances total').disable();
// const spheresCount = gui.add(spheres, 'count').name('instances rendered').disable();
// gui.add(camera, 'far', 100, 5000, 100).name('camera far').onChange(() => camera.updateProjectionMatrix());
Loading
Loading