diff --git a/src/objects/InstancedEntity.ts b/src/core/InstancedEntity.ts similarity index 100% rename from src/objects/InstancedEntity.ts rename to src/core/InstancedEntity.ts diff --git a/src/objects/InstancedMesh2.ts b/src/core/InstancedMesh2.ts similarity index 99% rename from src/objects/InstancedMesh2.ts rename to src/core/InstancedMesh2.ts index 341d2c5..1f24ced 100644 --- a/src/objects/InstancedMesh2.ts +++ b/src/core/InstancedMesh2.ts @@ -1,9 +1,9 @@ import { Box3, BufferAttribute, BufferGeometry, Camera, Color, ColorManagement, ColorRepresentation, DataTexture, FloatType, Group, InstancedBufferAttribute, Material, Matrix4, Mesh, MeshDepthMaterial, MeshDistanceMaterial, Object3D, Object3DEventMap, RGBADepthPacking, RGFormat, RedFormat, Scene, ShaderMaterial, Sphere, WebGLRenderer } from "three"; -import { createTexture_mat4, createTexture_vec4 } from "../utils/createTexture.js"; -import { GLInstancedBufferAttribute } from "./GLInstancedBufferAttribute.js"; +import { createTexture_mat4, createTexture_vec4 } from "../utils/CreateTexture.js"; +import { GLInstancedBufferAttribute } from "./utils/GLInstancedBufferAttribute.js"; import { InstancedEntity, UniformValue, UniformValueNoNumber } from "./InstancedEntity.js"; import { InstancedMeshBVH } from "./InstancedMeshBVH.js"; -import { InstancedRenderItem } from "./InstancedRenderList.js"; +import { InstancedRenderItem } from "./utils/InstancedRenderList.js"; // TODO: Add expand and count/maxCount when create? // TODO: partial texture update diff --git a/src/objects/InstancedMeshBVH.ts b/src/core/InstancedMeshBVH.ts similarity index 99% rename from src/objects/InstancedMeshBVH.ts rename to src/core/InstancedMeshBVH.ts index d07e1eb..8cd5e5c 100644 --- a/src/objects/InstancedMeshBVH.ts +++ b/src/core/InstancedMeshBVH.ts @@ -1,7 +1,7 @@ import { box3ToArray, BVH, BVHNode, FloatArray, HybridBuilder, onFrustumIntersectionCallback, onFrustumIntersectionLODCallback, onIntersectionCallback, onIntersectionRayCallback, vec3ToArray, WebGLCoordinateSystem } from 'bvh.js'; import { Box3, Matrix4, Raycaster, Sphere, Vector3 } from 'three'; import { InstancedMesh2, LODLevel } from './InstancedMesh2.js'; -import { getSphereFromMatrix_centeredGeometry, SphereTarget } from '../utils/matrixUtils.js'; +import { getSphereFromMatrix_centeredGeometry, SphereTarget } from '../utils/MatrixUtils.js'; export class InstancedMeshBVH { public target: InstancedMesh2; diff --git a/src/objects/FrustumCulling.ts b/src/core/feature/FrustumCulling.ts similarity index 96% rename from src/objects/FrustumCulling.ts rename to src/core/feature/FrustumCulling.ts index 3e0a2f8..9e794d6 100644 --- a/src/objects/FrustumCulling.ts +++ b/src/core/feature/FrustumCulling.ts @@ -1,11 +1,11 @@ import { BVHNode } from "bvh.js"; import { Camera, Frustum, Material, Matrix4, Sphere, Vector3 } from "three"; -import { getMaxScaleOnAxisAt, getPositionAt } from "../utils/matrixUtils.js"; -import { sortOpaque, sortTransparent } from "../utils/sortingUtils.js"; -import { InstancedMesh2 } from "./InstancedMesh2.js"; -import { InstancedRenderList } from "./InstancedRenderList.js"; +import { getMaxScaleOnAxisAt, getPositionAt } from "../../utils/MatrixUtils.js"; +import { sortOpaque, sortTransparent } from "../../utils/SortingUtils.js"; +import { InstancedMesh2 } from "../InstancedMesh2.js"; +import { InstancedRenderList } from "../utils/InstancedRenderList.js"; -declare module './InstancedMesh2.js' { +declare module '../InstancedMesh2.js' { interface InstancedMesh2 { frustumCulling(camera: Camera): void; /** @internal */ updateIndexArray(): void; diff --git a/src/objects/Raycasting.ts b/src/core/feature/Raycasting.ts similarity index 94% rename from src/objects/Raycasting.ts rename to src/core/feature/Raycasting.ts index 7bc335e..96cd015 100644 --- a/src/objects/Raycasting.ts +++ b/src/core/feature/Raycasting.ts @@ -1,8 +1,8 @@ import { Intersection, Matrix4, Mesh, Ray, Raycaster, Sphere, Vector3 } from "three"; -import { InstancedMesh2 } from "./InstancedMesh2.js"; -import { ascSortIntersection } from "../utils/sortingUtils.js"; +import { InstancedMesh2 } from "../InstancedMesh2.js"; +import { ascSortIntersection } from "../../utils/SortingUtils.js"; -declare module './InstancedMesh2.js' { +declare module '../InstancedMesh2.js' { interface InstancedMesh2 { /** @internal */ checkObjectIntersection(raycaster: Raycaster, objectIndex: number, result: Intersection[]): void; } diff --git a/src/objects/GLInstancedBufferAttribute.ts b/src/core/utils/GLInstancedBufferAttribute.ts similarity index 100% rename from src/objects/GLInstancedBufferAttribute.ts rename to src/core/utils/GLInstancedBufferAttribute.ts diff --git a/src/objects/InstancedRenderList.ts b/src/core/utils/InstancedRenderList.ts similarity index 100% rename from src/objects/InstancedRenderList.ts rename to src/core/utils/InstancedRenderList.ts diff --git a/src/index.ts b/src/index.ts index b316a7d..af2d83e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,19 @@ -export * from './objects/GLInstancedBufferAttribute.js'; -export * from './objects/FrustumCulling.js'; -export * from './objects/Raycasting.js'; -export * from './objects/InstancedEntity.js'; -export * from './objects/InstancedMesh2.js'; -export * from './objects/InstancedMeshBVH.js'; -export * from './objects/InstancedRenderList.js'; +export * from './core/InstancedEntity.js'; +export * from './core/InstancedMesh2.js'; +export * from './core/InstancedMeshBVH.js'; +export * from './core/feature/FrustumCulling.js'; +export * from './core/feature/Raycasting.js'; +export * from './core/utils/GLInstancedBufferAttribute.js'; +export * from './core/utils/InstancedRenderList.js'; + export * from './shaders/ShaderChunk.js'; export * from './shaders/chunks/get_from_texture.glsl.js'; export * from './shaders/chunks/instanced_pars_vertex.glsl.js'; export * from './shaders/chunks/instanced_vertex.glsl.js'; -export * from './utils/createTexture.js'; -export * from './utils/createRadixSort.js'; + +export * from './utils/CreateTexture.js'; +export * from './utils/MatrixUtils.js'; +export * from './utils/SortingUtils.js'; /** @internal */ declare module 'three' { diff --git a/src/utils/createTexture.ts b/src/utils/CreateTexture.ts similarity index 100% rename from src/utils/createTexture.ts rename to src/utils/CreateTexture.ts diff --git a/src/utils/matrixUtils.ts b/src/utils/MatrixUtils.ts similarity index 99% rename from src/utils/matrixUtils.ts rename to src/utils/MatrixUtils.ts index bc360cb..9028d51 100644 --- a/src/utils/matrixUtils.ts +++ b/src/utils/MatrixUtils.ts @@ -34,6 +34,7 @@ export function getSphereFromMatrix_centeredGeometry(id: number, array: FloatArr return target; } +// TODO move it export function getPositionAt(index: number, array: FloatArray, target: Vector3): Vector3 { const offset = index * 16; target.x = array[offset + 12]; diff --git a/src/utils/createRadixSort.ts b/src/utils/SortingUtils.ts similarity index 68% rename from src/utils/createRadixSort.ts rename to src/utils/SortingUtils.ts index f6fcb38..480b270 100644 --- a/src/utils/createRadixSort.ts +++ b/src/utils/SortingUtils.ts @@ -1,7 +1,9 @@ -import { Material } from "three"; +import { Intersection, Material } from "three"; +import { InstancedRenderItem } from "../core/utils/InstancedRenderList.js"; import { radixSort, RadixSortOptions } from "three/examples/jsm/utils/SortUtils.js"; -import { InstancedMesh2 } from "../objects/InstancedMesh2.js"; -import { InstancedRenderItem } from "../objects/InstancedRenderList.js"; +import { InstancedMesh2 } from "../core/InstancedMesh2.js"; + +// REFERENCE: https://github.com/mrdoob/three.js/blob/master/examples/webgl_mesh_batch.html#L291 export function createRadixSort(target: InstancedMesh2): typeof radixSort { @@ -41,4 +43,17 @@ export function createRadixSort(target: InstancedMesh2): typeof radixSort