Skip to content

Commit

Permalink
Restructuring folders (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
agargaro authored Nov 2, 2024
1 parent f1624e8 commit 6e72631
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 42 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/objects/InstancedMesh2.ts → src/core/InstancedMesh2.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/objects/Raycasting.ts → src/core/feature/Raycasting.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 12 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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' {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/utils/matrixUtils.ts → src/utils/MatrixUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
23 changes: 19 additions & 4 deletions src/utils/createRadixSort.ts → src/utils/SortingUtils.ts
Original file line number Diff line number Diff line change
@@ -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<InstancedRenderItem> {

Expand Down Expand Up @@ -41,4 +43,17 @@ export function createRadixSort(target: InstancedMesh2): typeof radixSort<Instan
}
}

// REFERENCE: https://github.com/mrdoob/three.js/blob/master/examples/webgl_mesh_batch.html#L291
/** @internal */
export function sortOpaque(a: InstancedRenderItem, b: InstancedRenderItem) {
return a.depth - b.depth;
}

/** @internal */
export function sortTransparent(a: InstancedRenderItem, b: InstancedRenderItem) {
return b.depth - a.depth;
}

/** @internal */
export function ascSortIntersection(a: Intersection, b: Intersection): number {
return a.distance - b.distance;
}
17 changes: 0 additions & 17 deletions src/utils/sortingUtils.ts

This file was deleted.

0 comments on commit 6e72631

Please sign in to comment.