-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: .d.ts type annotations * Attribute expects buffersource * Narrow AttributeData, mend array methods * chore: lowercase path directory * chore: import house cleaning * chore: format with prettier config * chore: remove unnecessary declare * feat: add tuple type to set method * feat: core/math updates * feat: extras * feat: update package.json to include src files * chore: import order adjustment * chore: Transform.setParent() description adjustment * feat: add KTXTexture declaration * fix: Orbit constructor object is a Camera * fix: update package.json exports for types and default * fix: remove unnecessary fov intersection * chore: remove unnecessary intersection for CompressedImage --------- Co-authored-by: Cody Bennett <[email protected]>
- Loading branch information
1 parent
247aa67
commit 65980cf
Showing
62 changed files
with
2,498 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Transform } from './Transform.js'; | ||
import { Mat4 } from '../math/Mat4.js'; | ||
import { Vec3 } from '../math/Vec3.js'; | ||
|
||
import type { OGLRenderingContext } from './Renderer.js'; | ||
import type { Vec3Tuple } from '../math/Vec3.js'; | ||
import type { Mesh } from './Mesh.js'; | ||
|
||
export interface CameraOptions { | ||
near: number; | ||
far: number; | ||
fov: number; | ||
aspect: number; | ||
left: number; | ||
right: number; | ||
bottom: number; | ||
top: number; | ||
zoom: number; | ||
} | ||
|
||
export interface PerspectiveOptions extends Pick<CameraOptions, 'near' | 'far' | 'fov' | 'aspect'> {} | ||
|
||
export interface OrthographicOptions extends Pick<CameraOptions, 'near' | 'far' | 'left' | 'right' | 'bottom' | 'top' | 'zoom'> {} | ||
|
||
export type CameraType = 'perspective' | 'orthographic'; | ||
|
||
/** | ||
* A perspective or orthographic camera. | ||
* @see {@link https://github.com/oframe/ogl/blob/master/src/core/Camera.js | Source} | ||
*/ | ||
export class Camera extends Transform { | ||
projectionMatrix: Mat4; | ||
viewMatrix: Mat4; | ||
projectionViewMatrix: Mat4; | ||
worldPosition: Vec3; | ||
|
||
type: CameraType; | ||
|
||
near: number; | ||
far: number; | ||
fov: number; | ||
aspect: number; | ||
left: number; | ||
right: number; | ||
bottom: number; | ||
top: number; | ||
zoom: number; | ||
|
||
frustum: (Vec3 & { | ||
constant: number; | ||
})[]; | ||
|
||
constructor(gl: OGLRenderingContext, options?: Partial<CameraOptions>); | ||
|
||
perspective(options?: Partial<PerspectiveOptions>): this; | ||
|
||
orthographic(options?: Partial<OrthographicOptions>): this; | ||
|
||
updateMatrixWorld(): this; | ||
|
||
lookAt(target: Vec3 | Vec3Tuple): this; | ||
|
||
project(v: Vec3): this; | ||
|
||
unproject(v: Vec3): this; | ||
|
||
updateFrustum(): void; | ||
|
||
frustumIntersectsMesh(node: Mesh, worldMatrix?: Mat4): boolean; | ||
|
||
frustumIntersectsSphere(center: Vec3, radius: number): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Vec3 } from '../math/Vec3.js'; | ||
|
||
import type { OGLRenderingContext, RenderState } from './Renderer.js'; | ||
import type { Program } from './Program.js'; | ||
|
||
export type AttributeMap = Record<string, Partial<Attribute>>; | ||
|
||
export type AttributeData = Float32Array | Uint32Array | Uint16Array; | ||
|
||
export interface Attribute { | ||
data: AttributeData; | ||
size: number; | ||
instanced: null | number | boolean; | ||
type: GLenum; | ||
normalized: boolean; | ||
|
||
buffer: WebGLBuffer; | ||
stride: number; | ||
offset: number; | ||
count: number; | ||
target: number; | ||
id: number; | ||
divisor: number; | ||
needsUpdate: boolean; | ||
usage: number; | ||
} | ||
|
||
export interface Bounds { | ||
min: Vec3; | ||
max: Vec3; | ||
center: Vec3; | ||
scale: Vec3; | ||
radius: number; | ||
} | ||
|
||
export type GeometryRaycast = 'sphere' | 'box'; | ||
|
||
/** | ||
* A mesh, line, or point geometry. | ||
* @see {@link https://github.com/oframe/ogl/blob/master/src/core/Geometry.js | Source} | ||
*/ | ||
export class Geometry { | ||
gl: OGLRenderingContext; | ||
attributes: AttributeMap; | ||
id: number; | ||
|
||
VAOs: { | ||
[programKey: string]: WebGLVertexArrayObject; | ||
}; | ||
|
||
drawRange: { | ||
start: number; | ||
count: number; | ||
}; | ||
instancedCount: number; | ||
|
||
glState: RenderState; | ||
|
||
isInstanced: boolean; | ||
bounds: Bounds; | ||
|
||
raycast?: GeometryRaycast; // User defined | ||
|
||
constructor(gl: OGLRenderingContext, attributes?: AttributeMap); | ||
|
||
addAttribute(key: string, attr: Partial<Attribute>): number | undefined; | ||
|
||
updateAttribute(attr: Partial<Attribute>): void; | ||
|
||
setIndex(value: Attribute): void; | ||
|
||
setDrawRange(start: number, count: number): void; | ||
|
||
setInstancedCount(value: number): void; | ||
|
||
createVAO(program: Program): void; | ||
|
||
bindAttributes(program: Program): void; | ||
|
||
draw(options: { program: Program; mode?: number }): void; | ||
|
||
getPosition(): Partial<Attribute>; | ||
|
||
computeBoundingBox(attr: Partial<Attribute>): void; | ||
|
||
computeBoundingSphere(attr?: Partial<Attribute>): void; | ||
|
||
remove(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Transform } from './Transform.js'; | ||
import { Mat3 } from '../math/Mat3.js'; | ||
import { Mat4 } from '../math/Mat4.js'; | ||
|
||
import type { OGLRenderingContext } from './Renderer.js'; | ||
import type { Vec2 } from '../math/Vec2.js'; | ||
import type { Vec3 } from '../math/Vec3.js'; | ||
import type { Geometry } from './Geometry.js'; | ||
import type { Program } from './Program.js'; | ||
import type { Camera } from './Camera.js'; | ||
|
||
export interface MeshOptions< | ||
TGeometry extends Geometry = Geometry, | ||
TProgram extends Program = Program, | ||
> { | ||
geometry: TGeometry; | ||
program: TProgram; | ||
mode: GLenum; | ||
frustumCulled: boolean; | ||
renderOrder: number; | ||
} | ||
|
||
export type MeshRenderCallback = (renderInfo: { mesh: Mesh; camera?: Camera }) => any; | ||
|
||
export interface RaycastHit { | ||
localPoint: Vec3; | ||
distance: number; | ||
point: Vec3; | ||
faceNormal: Vec3; | ||
localFaceNormal: Vec3; | ||
uv: Vec2; | ||
localNormal: Vec3; | ||
normal: Vec3; | ||
} | ||
|
||
/** | ||
* Represents a {@link https://en.wikipedia.org/wiki/Polygon_mesh | polygon mesh}. | ||
* @see {@link https://github.com/oframe/ogl/blob/master/src/core/Mesh.js | Source} | ||
*/ | ||
export class Mesh< | ||
TGeometry extends Geometry = Geometry, | ||
TProgram extends Program = Program, | ||
> extends Transform { | ||
gl: OGLRenderingContext; | ||
id: number; | ||
geometry: TGeometry; | ||
program: TProgram; | ||
mode: GLenum; | ||
|
||
frustumCulled: boolean; | ||
|
||
renderOrder: number; | ||
modelViewMatrix: Mat4; | ||
normalMatrix: Mat3; | ||
beforeRenderCallbacks: MeshRenderCallback[]; | ||
afterRenderCallbacks: MeshRenderCallback[]; | ||
|
||
hit?: Partial<RaycastHit>; // Set from raycaster | ||
|
||
constructor(gl: OGLRenderingContext, options?: Partial<MeshOptions>); | ||
|
||
onBeforeRender(f: MeshRenderCallback): this; | ||
|
||
onAfterRender(f: MeshRenderCallback): this; | ||
|
||
draw(options?: { camera?: Camera }): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { OGLRenderingContext, BlendFunc, BlendEquation } from './Renderer'; | ||
|
||
export interface ProgramOptions { | ||
vertex: string; | ||
fragment: string; | ||
uniforms: Record<string, any>; | ||
transparent: boolean; | ||
cullFace: GLenum | false | null; | ||
frontFace: GLenum; | ||
depthTest: boolean; | ||
depthWrite: boolean; | ||
depthFunc: GLenum; | ||
} | ||
|
||
export interface UniformInfo extends WebGLActiveInfo { | ||
uniformName: string; | ||
nameComponents: string[]; | ||
isStruct: boolean; | ||
isStructArray: boolean; | ||
structIndex: number; | ||
structProperty: string; | ||
} | ||
|
||
/** | ||
* A WebGL program. | ||
* @see {@link https://github.com/oframe/ogl/blob/master/src/core/Program.js | Source} | ||
*/ | ||
export class Program { | ||
gl: OGLRenderingContext; | ||
uniforms: Record<string, any>; | ||
id: number; | ||
|
||
transparent: boolean; | ||
cullFace: GLenum | false | null; | ||
frontFace: GLenum; | ||
depthTest: boolean; | ||
depthWrite: boolean; | ||
depthFunc: GLenum; | ||
blendFunc: BlendFunc; | ||
blendEquation: BlendEquation; | ||
|
||
program: WebGLProgram; | ||
uniformLocations: Map<UniformInfo, WebGLUniformLocation>; | ||
attributeLocations: Map<WebGLActiveInfo, GLint>; | ||
attributeOrder: string; | ||
|
||
constructor(gl: OGLRenderingContext, options?: Partial<ProgramOptions>); | ||
|
||
setBlendFunc(src: GLenum, dst: GLenum, srcAlpha?: GLenum, dstAlpha?: GLenum): void; | ||
|
||
setBlendEquation(modeRGB: GLenum, modeAlpha: GLenum): void; | ||
|
||
applyState(): void; | ||
|
||
use(options?: { flipFaces?: boolean }): void; | ||
|
||
remove(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Texture } from './Texture.js'; | ||
|
||
import type { OGLRenderingContext } from './Renderer.js'; | ||
|
||
export interface RenderTargetOptions { | ||
width: number; | ||
height: number; | ||
target: GLenum; | ||
color: number; | ||
depth: boolean; | ||
stencil: boolean; | ||
depthTexture: boolean; | ||
wrapS: GLenum; | ||
wrapT: GLenum; | ||
minFilter: GLenum; | ||
magFilter: GLenum; | ||
type: GLenum; | ||
format: GLenum; | ||
internalFormat: GLenum; | ||
unpackAlignment: number; | ||
premultiplyAlpha: boolean; | ||
} | ||
|
||
/** | ||
* A render target. | ||
* @see {@link https://github.com/oframe/ogl/blob/master/src/core/RenderTarget.js | Source} | ||
*/ | ||
export class RenderTarget { | ||
gl: OGLRenderingContext; | ||
width: number; | ||
height: number; | ||
depth: boolean; | ||
buffer: WebGLFramebuffer; | ||
target: number; | ||
|
||
textures: Texture[]; | ||
texture: Texture; | ||
depthTexture: Texture; | ||
depthBuffer: WebGLRenderbuffer; | ||
stencilBuffer: WebGLRenderbuffer; | ||
depthStencilBuffer: WebGLRenderbuffer; | ||
|
||
constructor(gl: OGLRenderingContext, options?: Partial<RenderTargetOptions>); | ||
|
||
setSize(width: number, height: number): void; | ||
} |
Oops, something went wrong.