diff --git a/examples-jsm/changes.patch b/examples-jsm/changes.patch index 9360c8abb..65e909227 100644 --- a/examples-jsm/changes.patch +++ b/examples-jsm/changes.patch @@ -6653,10 +6653,10 @@ index e7b389cd..53406066 100644 for (const uniform of this.uniforms) { const node = uniform.nodeUniform.node; diff --git a/examples-jsm/examples/renderers/common/nodes/Nodes.ts b/examples-jsm/examples/renderers/common/nodes/Nodes.ts -index db035f6d..e8a2a222 100644 +index db035f6d..5d4b35ba 100644 --- a/examples-jsm/examples/renderers/common/nodes/Nodes.ts +++ b/examples-jsm/examples/renderers/common/nodes/Nodes.ts -@@ -2,10 +2,20 @@ import DataMap from '../DataMap.js'; +@@ -2,10 +2,19 @@ import DataMap from '../DataMap.js'; import ChainMap from '../ChainMap.js'; import NodeBuilderState from './NodeBuilderState.js'; import { @@ -6666,7 +6666,6 @@ index db035f6d..e8a2a222 100644 EquirectangularReflectionMapping, EquirectangularRefractionMapping, + Fog, -+ FogBase, + FogExp2, + Material, NoToneMapping, @@ -6677,7 +6676,7 @@ index db035f6d..e8a2a222 100644 } from 'three'; import { NodeFrame, -@@ -22,21 +32,66 @@ import { +@@ -22,21 +31,66 @@ import { normalWorld, pmremTexture, viewportTopLeft, @@ -6712,7 +6711,7 @@ index db035f6d..e8a2a222 100644 +interface SceneData { + background?: Color | Texture | CubeTexture | undefined; + backgroundNode?: Node | undefined; -+ fog?: FogBase | undefined; ++ fog?: Fog | FogExp2 | undefined; + fogNode?: Node | undefined; + environment?: Texture | undefined; + environmentNode?: Node | undefined; @@ -6748,7 +6747,7 @@ index db035f6d..e8a2a222 100644 const groupNode = nodeUniformsGroup.groupNode; const name = groupNode.name; -@@ -76,7 +131,7 @@ class Nodes extends DataMap { +@@ -76,7 +130,7 @@ class Nodes extends DataMap { // other groups are updated just when groupNode.needsUpdate is true @@ -6757,7 +6756,7 @@ index db035f6d..e8a2a222 100644 let groupData = this.groupsData.get(groupChain); if (groupData === undefined) this.groupsData.set(groupChain, (groupData = {})); -@@ -90,11 +145,11 @@ class Nodes extends DataMap { +@@ -90,11 +144,11 @@ class Nodes extends DataMap { return false; } @@ -6771,7 +6770,7 @@ index db035f6d..e8a2a222 100644 const renderObjectData = this.get(renderObject); let nodeBuilderState = renderObjectData.nodeBuilderState; -@@ -131,20 +186,20 @@ class Nodes extends DataMap { +@@ -131,20 +185,20 @@ class Nodes extends DataMap { return nodeBuilderState; } @@ -6797,7 +6796,7 @@ index db035f6d..e8a2a222 100644 const computeData = this.get(computeNode); let nodeBuilderState = computeData.nodeBuilderState; -@@ -161,7 +216,7 @@ class Nodes extends DataMap { +@@ -161,7 +215,7 @@ class Nodes extends DataMap { return nodeBuilderState; } @@ -6806,7 +6805,7 @@ index db035f6d..e8a2a222 100644 return new NodeBuilderState( nodeBuilder.vertexShader, nodeBuilder.fragmentShader, -@@ -176,20 +231,28 @@ class Nodes extends DataMap { +@@ -176,20 +230,28 @@ class Nodes extends DataMap { ); } @@ -6843,7 +6842,7 @@ index db035f6d..e8a2a222 100644 const callId = this.renderer.info.calls; let cacheKeyData = this.callHashCache.get(chain); -@@ -215,7 +278,7 @@ class Nodes extends DataMap { +@@ -215,7 +277,7 @@ class Nodes extends DataMap { return cacheKeyData.cacheKey; } @@ -6852,7 +6851,7 @@ index db035f6d..e8a2a222 100644 this.updateEnvironment(scene); this.updateFog(scene); this.updateBackground(scene); -@@ -225,7 +288,7 @@ class Nodes extends DataMap { +@@ -225,7 +287,7 @@ class Nodes extends DataMap { return this.renderer.getRenderTarget() ? false : true; } @@ -6861,7 +6860,7 @@ index db035f6d..e8a2a222 100644 const sceneData = this.get(scene); const background = scene.background; -@@ -234,15 +297,15 @@ class Nodes extends DataMap { +@@ -234,15 +296,15 @@ class Nodes extends DataMap { let backgroundNode = null; if ( @@ -6884,7 +6883,7 @@ index db035f6d..e8a2a222 100644 } sceneData.backgroundNode = backgroundNode; -@@ -254,7 +317,7 @@ class Nodes extends DataMap { +@@ -254,7 +316,7 @@ class Nodes extends DataMap { } } @@ -6893,7 +6892,7 @@ index db035f6d..e8a2a222 100644 const sceneData = this.get(scene); const fog = scene.fog; -@@ -262,9 +325,9 @@ class Nodes extends DataMap { +@@ -262,9 +324,9 @@ class Nodes extends DataMap { if (sceneData.fog !== fog) { let fogNode = null; @@ -6905,7 +6904,7 @@ index db035f6d..e8a2a222 100644 fogNode = rangeFog( reference('color', 'color', fog), reference('near', 'float', fog), -@@ -283,7 +346,7 @@ class Nodes extends DataMap { +@@ -283,7 +345,7 @@ class Nodes extends DataMap { } } @@ -6914,7 +6913,7 @@ index db035f6d..e8a2a222 100644 const sceneData = this.get(scene); const environment = scene.environment; -@@ -291,7 +354,7 @@ class Nodes extends DataMap { +@@ -291,7 +353,7 @@ class Nodes extends DataMap { if (sceneData.environment !== environment) { let environmentNode = null; @@ -6923,7 +6922,7 @@ index db035f6d..e8a2a222 100644 environmentNode = cubeTexture(environment); } else if (environment.isTexture === true) { environmentNode = texture(environment); -@@ -308,7 +371,13 @@ class Nodes extends DataMap { +@@ -308,7 +370,13 @@ class Nodes extends DataMap { } } @@ -6938,7 +6937,7 @@ index db035f6d..e8a2a222 100644 const nodeFrame = this.nodeFrame; nodeFrame.renderer = renderer; nodeFrame.scene = scene; -@@ -319,7 +388,7 @@ class Nodes extends DataMap { +@@ -319,7 +387,7 @@ class Nodes extends DataMap { return nodeFrame; } @@ -6947,7 +6946,7 @@ index db035f6d..e8a2a222 100644 return this.getNodeFrame( renderObject.renderer, renderObject.scene, -@@ -329,8 +398,8 @@ class Nodes extends DataMap { +@@ -329,8 +397,8 @@ class Nodes extends DataMap { ); } @@ -6958,7 +6957,7 @@ index db035f6d..e8a2a222 100644 if (this.isToneMappingState) { if (this.renderer.toneMappingNode) { -@@ -347,7 +416,7 @@ class Nodes extends DataMap { +@@ -347,7 +415,7 @@ class Nodes extends DataMap { return output; } @@ -6967,7 +6966,7 @@ index db035f6d..e8a2a222 100644 const nodeFrame = this.getNodeFrameForRender(renderObject); const nodeBuilder = renderObject.getNodeBuilderState(); -@@ -356,7 +425,7 @@ class Nodes extends DataMap { +@@ -356,7 +424,7 @@ class Nodes extends DataMap { } } @@ -6976,7 +6975,7 @@ index db035f6d..e8a2a222 100644 const nodeFrame = this.getNodeFrameForRender(renderObject); const nodeBuilder = renderObject.getNodeBuilderState(); -@@ -365,7 +434,7 @@ class Nodes extends DataMap { +@@ -365,7 +433,7 @@ class Nodes extends DataMap { } } @@ -6985,7 +6984,7 @@ index db035f6d..e8a2a222 100644 const nodeFrame = this.getNodeFrame(); const nodeBuilder = this.getForCompute(computeNode); -@@ -374,7 +443,7 @@ class Nodes extends DataMap { +@@ -374,7 +442,7 @@ class Nodes extends DataMap { } } diff --git a/types/three/examples/jsm/renderers/common/nodes/Nodes.d.ts b/types/three/examples/jsm/renderers/common/nodes/Nodes.d.ts index 6c264cd4c..cb7da5ac2 100644 --- a/types/three/examples/jsm/renderers/common/nodes/Nodes.d.ts +++ b/types/three/examples/jsm/renderers/common/nodes/Nodes.d.ts @@ -1,4 +1,4 @@ -import { Camera, Color, CubeTexture, FogBase, Material, Object3D, Scene, Texture } from "three"; +import { Camera, Color, CubeTexture, Fog, FogExp2, Material, Object3D, Scene, Texture } from "three"; import Node from "../../../nodes/core/Node.js"; import NodeBuilder from "../../../nodes/core/NodeBuilder.js"; import UniformGroupNode from "../../../nodes/core/UniformGroupNode.js"; @@ -25,7 +25,7 @@ interface ComputeNodeData { interface SceneData { background?: Color | Texture | CubeTexture | undefined; backgroundNode?: Node | undefined; - fog?: FogBase | undefined; + fog?: Fog | FogExp2 | undefined; fogNode?: Node | undefined; environment?: Texture | undefined; environmentNode?: Node | undefined; diff --git a/types/three/src/animation/AnimationClip.d.ts b/types/three/src/animation/AnimationClip.d.ts index a80c448fd..4efc3df72 100644 --- a/types/three/src/animation/AnimationClip.d.ts +++ b/types/three/src/animation/AnimationClip.d.ts @@ -1,7 +1,15 @@ import { AnimationBlendMode } from "../constants.js"; import { Vector3 } from "../math/Vector3.js"; import { Bone } from "../objects/Bone.js"; -import { KeyframeTrack } from "./KeyframeTrack.js"; +import { KeyframeTrack, KeyframeTrackJSON } from "./KeyframeTrack.js"; + +export interface AnimationClipJSON { + name: string; + duration: number; + tracks: KeyframeTrackJSON[]; + uuid: string; + blendMode: AnimationBlendMode; +} export interface MorphTarget { name: string; @@ -45,7 +53,7 @@ export class AnimationClip { fps: number, noLoop: boolean, ): AnimationClip[]; - static parse(json: any): AnimationClip; - static parseAnimation(animation: any, bones: Bone[]): AnimationClip; - static toJSON(clip: AnimationClip): any; + static parse(json: AnimationClipJSON): AnimationClip; + static parseAnimation(animation: AnimationClipJSON, bones: Bone[]): AnimationClip; + static toJSON(clip: AnimationClip): AnimationClipJSON; } diff --git a/types/three/src/animation/KeyframeTrack.d.ts b/types/three/src/animation/KeyframeTrack.d.ts index 2a04bca28..4e39621de 100644 --- a/types/three/src/animation/KeyframeTrack.d.ts +++ b/types/three/src/animation/KeyframeTrack.d.ts @@ -4,22 +4,30 @@ import { CubicInterpolant } from "../math/interpolants/CubicInterpolant.js"; import { DiscreteInterpolant } from "../math/interpolants/DiscreteInterpolant.js"; import { LinearInterpolant } from "../math/interpolants/LinearInterpolant.js"; -export class KeyframeTrack { +export interface KeyframeTrackJSON { + name: string; + times: number[]; + values: V[]; + interpolation?: InterpolationModes; + type: T; +} + +export class KeyframeTrack { /** * @param name * @param times * @param values * @param [interpolation=THREE.InterpolateLinear] */ - constructor(name: string, times: ArrayLike, values: ArrayLike, interpolation?: InterpolationModes); + constructor(name: string, times: ArrayLike, values: ArrayLike, interpolation?: InterpolationModes); name: string; times: Float32Array; - values: Float32Array; + values: ArrayLike; ValueTypeName: string; - TimeBufferType: Float32Array; - ValueBufferType: Float32Array; + TimeBufferType: typeof Float32Array; + ValueBufferType: typeof Float32Array | typeof Array; /** * @default THREE.InterpolateLinear @@ -43,5 +51,7 @@ export class KeyframeTrack { optimize(): KeyframeTrack; clone(): this; - static toJSON(track: KeyframeTrack): any; + static toJSON( + track: Track, + ): KeyframeTrackJSON ? V : never, Track["ValueTypeName"]>; } diff --git a/types/three/src/animation/tracks/BooleanKeyframeTrack.d.ts b/types/three/src/animation/tracks/BooleanKeyframeTrack.d.ts index 45b65448a..c3656e75f 100644 --- a/types/three/src/animation/tracks/BooleanKeyframeTrack.d.ts +++ b/types/three/src/animation/tracks/BooleanKeyframeTrack.d.ts @@ -1,10 +1,10 @@ import { KeyframeTrack } from "../KeyframeTrack.js"; -export class BooleanKeyframeTrack extends KeyframeTrack { - constructor(name: string, times: ArrayLike, values: ArrayLike); +export class BooleanKeyframeTrack extends KeyframeTrack { + constructor(name: string, times: ArrayLike, values: ArrayLike); /** * @default 'bool' */ - ValueTypeName: string; + ValueTypeName: "bool"; } diff --git a/types/three/src/animation/tracks/ColorKeyframeTrack.d.ts b/types/three/src/animation/tracks/ColorKeyframeTrack.d.ts index 60d0fe9f7..58428a916 100644 --- a/types/three/src/animation/tracks/ColorKeyframeTrack.d.ts +++ b/types/three/src/animation/tracks/ColorKeyframeTrack.d.ts @@ -1,11 +1,11 @@ import { InterpolationModes } from "../../constants.js"; import { KeyframeTrack } from "../KeyframeTrack.js"; -export class ColorKeyframeTrack extends KeyframeTrack { +export class ColorKeyframeTrack extends KeyframeTrack { constructor(name: string, times: ArrayLike, values: ArrayLike, interpolation?: InterpolationModes); /** * @default 'color' */ - ValueTypeName: string; + ValueTypeName: "color"; } diff --git a/types/three/src/animation/tracks/NumberKeyframeTrack.d.ts b/types/three/src/animation/tracks/NumberKeyframeTrack.d.ts index e27ff0337..8e18bee74 100644 --- a/types/three/src/animation/tracks/NumberKeyframeTrack.d.ts +++ b/types/three/src/animation/tracks/NumberKeyframeTrack.d.ts @@ -1,11 +1,11 @@ import { InterpolationModes } from "../../constants.js"; import { KeyframeTrack } from "../KeyframeTrack.js"; -export class NumberKeyframeTrack extends KeyframeTrack { +export class NumberKeyframeTrack extends KeyframeTrack { constructor(name: string, times: ArrayLike, values: ArrayLike, interpolation?: InterpolationModes); /** * @default 'number' */ - ValueTypeName: string; + ValueTypeName: "number"; } diff --git a/types/three/src/animation/tracks/QuaternionKeyframeTrack.d.ts b/types/three/src/animation/tracks/QuaternionKeyframeTrack.d.ts index 29942bad5..6a60fd29c 100644 --- a/types/three/src/animation/tracks/QuaternionKeyframeTrack.d.ts +++ b/types/three/src/animation/tracks/QuaternionKeyframeTrack.d.ts @@ -1,11 +1,11 @@ import { InterpolationModes } from "../../constants.js"; import { KeyframeTrack } from "../KeyframeTrack.js"; -export class QuaternionKeyframeTrack extends KeyframeTrack { +export class QuaternionKeyframeTrack extends KeyframeTrack { constructor(name: string, times: ArrayLike, values: ArrayLike, interpolation?: InterpolationModes); /** * @default 'quaternion' */ - ValueTypeName: string; + ValueTypeName: "quaternion"; } diff --git a/types/three/src/animation/tracks/StringKeyframeTrack.d.ts b/types/three/src/animation/tracks/StringKeyframeTrack.d.ts index 9bbfd2027..a3d2c1e88 100644 --- a/types/three/src/animation/tracks/StringKeyframeTrack.d.ts +++ b/types/three/src/animation/tracks/StringKeyframeTrack.d.ts @@ -1,10 +1,10 @@ import { KeyframeTrack } from "../KeyframeTrack.js"; -export class StringKeyframeTrack extends KeyframeTrack { - constructor(name: string, times: ArrayLike, values: ArrayLike); +export class StringKeyframeTrack extends KeyframeTrack { + constructor(name: string, times: ArrayLike, values: ArrayLike); /** * @default 'string' */ - ValueTypeName: string; + ValueTypeName: "string"; } diff --git a/types/three/src/animation/tracks/VectorKeyframeTrack.d.ts b/types/three/src/animation/tracks/VectorKeyframeTrack.d.ts index 0909d4493..626dce316 100644 --- a/types/three/src/animation/tracks/VectorKeyframeTrack.d.ts +++ b/types/three/src/animation/tracks/VectorKeyframeTrack.d.ts @@ -1,11 +1,11 @@ import { InterpolationModes } from "../../constants.js"; import { KeyframeTrack } from "../KeyframeTrack.js"; -export class VectorKeyframeTrack extends KeyframeTrack { +export class VectorKeyframeTrack extends KeyframeTrack { constructor(name: string, times: ArrayLike, values: ArrayLike, interpolation?: InterpolationModes); /** * @default 'vector' */ - ValueTypeName: string; + ValueTypeName: "vector"; } diff --git a/types/three/src/cameras/OrthographicCamera.d.ts b/types/three/src/cameras/OrthographicCamera.d.ts index 5c0aafd0c..aeccdf110 100644 --- a/types/three/src/cameras/OrthographicCamera.d.ts +++ b/types/three/src/cameras/OrthographicCamera.d.ts @@ -1,5 +1,28 @@ +import { JSONMeta, Object3DJSON, Object3DJSONObject, Object3DRootJSON } from "../core/Object3D.js"; import { Camera } from "./Camera.js"; +export interface OrthographicCameraJSONObject extends Object3DJSONObject { + zoom: number; + left: number; + right: number; + top: number; + bottom: number; + near: number; + far: number; + + view?: { + enabled: boolean; + fullWidth: number; + fullHeight: number; + offsetX: number; + offsetY: number; + width: number; + height: number; + }; +} + +export type OrthographicCameraJSON = Object3DJSON; + /** * Camera that uses {@link https://en.wikipedia.org/wiki/Orthographic_projection | orthographic projection}. * In this projection mode, an object's size in the rendered image stays constant regardless of its distance from the camera. @@ -144,4 +167,7 @@ export class OrthographicCamera extends Camera { * Removes any offset set by the {@link setViewOffset | .setViewOffset} method. */ clearViewOffset(): void; + + toJSON(meta: JSONMeta): OrthographicCameraJSON; + toJSON(): Object3DRootJSON; } diff --git a/types/three/src/cameras/PerspectiveCamera.d.ts b/types/three/src/cameras/PerspectiveCamera.d.ts index ce9b70d7d..4fa04bc9b 100644 --- a/types/three/src/cameras/PerspectiveCamera.d.ts +++ b/types/three/src/cameras/PerspectiveCamera.d.ts @@ -1,6 +1,33 @@ +import { JSONMeta, Object3DJSON, Object3DJSONObject, Object3DRootJSON } from "../core/Object3D.js"; import { Vector2 } from "../math/Vector2.js"; import { Camera } from "./Camera.js"; +export interface PerspectiveCameraJSONObject extends Object3DJSONObject { + fov: number; + zoom: number; + + near: number; + far: number; + focus: number; + + aspect: number; + + view?: { + enabled: boolean; + fullWidth: number; + fullHeight: number; + offsetX: number; + offsetY: number; + width: number; + height: number; + }; + + filmGauge: number; + filmOffset: number; +} + +export type PerspectiveCameraJSON = Object3DJSON; + /** * Camera that uses {@link https://en.wikipedia.org/wiki/Perspective_(graphical) | perspective projection}. * This projection mode is designed to mimic the way the human eye sees @@ -220,4 +247,7 @@ export class PerspectiveCamera extends Camera { * @deprecated Use {@link PerspectiveCamera.setFocalLength | .setFocalLength()} and {@link PerspectiveCamera.filmGauge | .filmGauge} instead. */ setLens(focalLength: number, frameHeight?: number): void; + + toJSON(meta: JSONMeta): PerspectiveCameraJSON; + toJSON(): Object3DRootJSON; } diff --git a/types/three/src/core/BufferAttribute.d.ts b/types/three/src/core/BufferAttribute.d.ts index 40180e822..c0dbba8e0 100644 --- a/types/three/src/core/BufferAttribute.d.ts +++ b/types/three/src/core/BufferAttribute.d.ts @@ -13,6 +13,16 @@ export type TypedArray = | Float32Array | Float64Array; +export interface BufferAttributeJSON { + itemSize: number; + type: string; + array: number[]; + normalized: boolean; + + name?: string; + usage?: Usage; +} + /** * This class stores data for an attribute (such as vertex positions, face indices, normals, colors, UVs, and any custom attributes ) * associated with a {@link THREE.BufferGeometry | BufferGeometry}, which allows for more efficient passing of data to the GPU @@ -336,12 +346,7 @@ export class BufferAttribute { /** * Convert this object to three.js to the `data.attributes` part of {@link https://github.com/mrdoob/three.js/wiki/JSON-Geometry-format-4 | JSON Geometry format v4}, */ - toJSON(): { - itemSize: number; - type: string; - array: number[]; - normalized: boolean; - }; + toJSON(): BufferAttributeJSON; } /** diff --git a/types/three/src/core/BufferGeometry.d.ts b/types/three/src/core/BufferGeometry.d.ts index 7ba07cf00..82cf8ad03 100644 --- a/types/three/src/core/BufferGeometry.d.ts +++ b/types/three/src/core/BufferGeometry.d.ts @@ -3,8 +3,8 @@ import { Matrix4 } from "../math/Matrix4.js"; import { Quaternion } from "../math/Quaternion.js"; import { Sphere } from "../math/Sphere.js"; import { Vector2 } from "../math/Vector2.js"; -import { Vector3 } from "../math/Vector3.js"; -import { BufferAttribute } from "./BufferAttribute.js"; +import { Vector3, Vector3Tuple } from "../math/Vector3.js"; +import { BufferAttribute, BufferAttributeJSON } from "./BufferAttribute.js"; import { EventDispatcher } from "./EventDispatcher.js"; import { GLBufferAttribute } from "./GLBufferAttribute.js"; import { InterleavedBufferAttribute } from "./InterleavedBufferAttribute.js"; @@ -15,6 +15,29 @@ export type NormalOrGLBufferAttributes = Record< BufferAttribute | InterleavedBufferAttribute | GLBufferAttribute >; +export interface BufferGeometryJSON { + metadata?: { version: number; type: string; generator: string }; + + uuid: string; + type: string; + + name?: string; + userData?: Record; + + data?: { + attributes: Record; + + index?: { type: string; array: number[] }; + + morphAttributes?: Record; + morphTargetsRelative?: boolean; + + groups?: GeometryGroup[]; + + boundingSphere?: { center: Vector3Tuple; radius: number }; + }; +} + export interface GeometryGroup { /** * Specifies the first element in this draw call – the first vertex for non-indexed geometry, otherwise the first triangle index. @@ -378,7 +401,7 @@ export class BufferGeometry< /** * Convert the buffer geometry to three.js {@link https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 | JSON Object/Scene format}. */ - toJSON(): {}; + toJSON(): BufferGeometryJSON; /** * Creates a clone of this BufferGeometry diff --git a/types/three/src/core/Object3D.d.ts b/types/three/src/core/Object3D.d.ts index 62a03bcbc..ab0363ead 100644 --- a/types/three/src/core/Object3D.d.ts +++ b/types/three/src/core/Object3D.d.ts @@ -1,19 +1,74 @@ -import { AnimationClip } from "../animation/AnimationClip.js"; +import { AnimationClip, AnimationClipJSON } from "../animation/AnimationClip.js"; import { Camera } from "../cameras/Camera.js"; import { Material } from "../materials/Material.js"; import { Euler } from "../math/Euler.js"; import { Matrix3 } from "../math/Matrix3.js"; -import { Matrix4 } from "../math/Matrix4.js"; +import { Matrix4, Matrix4Tuple } from "../math/Matrix4.js"; import { Quaternion } from "../math/Quaternion.js"; -import { Vector3 } from "../math/Vector3.js"; +import { Vector3, Vector3Tuple } from "../math/Vector3.js"; import { Group } from "../objects/Group.js"; +import { SkeletonJSON } from "../objects/Skeleton.js"; import { WebGLRenderer } from "../renderers/WebGLRenderer.js"; import { Scene } from "../scenes/Scene.js"; -import { BufferGeometry } from "./BufferGeometry.js"; +import { SourceJSON } from "../textures/Source.js"; +import { TextureJSON } from "../textures/Texture.js"; +import { BufferGeometry, BufferGeometryJSON } from "./BufferGeometry.js"; import { EventDispatcher } from "./EventDispatcher.js"; import { Layers } from "./Layers.js"; import { Intersection, Raycaster } from "./Raycaster.js"; +export interface Object3DJSONObject { + uuid: string; + type: string; + + name?: string; + castShadow?: boolean; + receiveShadow?: boolean; + visible?: boolean; + frustumCulled?: boolean; + renderOrder?: number; + userData?: Record; + + layers: number; + matrix: Matrix4Tuple; + up: Vector3Tuple; + + matrixAutoUpdate?: boolean; + + material?: string | string[]; + + children?: string[]; + + animations?: string[]; +} + +export interface Object3DJSON { + object: O; +} + +export interface Object3DRootJSON extends Object3DJSON { + metadata?: { version: number; type: string; generator: string }; + geometries?: Omit[]; + materials?: unknown[]; + textures?: Omit[]; + images?: SourceJSON[]; + shapes?: unknown[]; + skeletons?: Omit[]; + animations?: AnimationClipJSON[]; + nodes?: unknown[]; +} + +export interface JSONMeta { + geometries: Record; + materials: Record; + textures: Record; + images: Record; + shapes: Record; + skeletons: Record; + animations: Record; + nodes: Record; +} + export interface Object3DEventMap { /** * Fires when the object has been added to its parent object. @@ -608,7 +663,8 @@ export class Object3D ext * Convert the object to three.js {@link https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 | JSON Object/Scene format}. * @param meta Object containing metadata such as materials, textures or images for the object. */ - toJSON(meta?: { geometries: any; materials: any; textures: any; images: any }): any; + toJSON(): Object3DJSON; + toJSON(meta: JSONMeta): Object3DRootJSON; /** * Returns a clone of `this` object and optionally all descendants. diff --git a/types/three/src/extras/core/Curve.d.ts b/types/three/src/extras/core/Curve.d.ts index 49afb6753..9e3610903 100644 --- a/types/three/src/extras/core/Curve.d.ts +++ b/types/three/src/extras/core/Curve.d.ts @@ -1,6 +1,12 @@ import { Vector2 } from "../../math/Vector2.js"; import { Vector3 } from "../../math/Vector3.js"; +export interface CurveJSON { + metadata: { version: number; type: string; generator: string }; + arcLengthDivisions: number; + type: string; +} + /** * An abstract base class for creating a {@link Curve} object that contains methods for interpolation * @remarks @@ -146,11 +152,11 @@ export abstract class Curve { /** * Returns a JSON object representation of this instance. */ - toJSON(): {}; + toJSON(): CurveJSON; /** * Copies the data from the given JSON object to this instance. * @param json */ - fromJSON(json: {}): this; + fromJSON(json: CurveJSON): this; } diff --git a/types/three/src/extras/core/CurvePath.d.ts b/types/three/src/extras/core/CurvePath.d.ts index 65b04a252..3a8577fd1 100644 --- a/types/three/src/extras/core/CurvePath.d.ts +++ b/types/three/src/extras/core/CurvePath.d.ts @@ -1,6 +1,11 @@ import { Vector2 } from "../../math/Vector2.js"; import { Vector3 } from "../../math/Vector3.js"; -import { Curve } from "./Curve.js"; +import { Curve, CurveJSON } from "./Curve.js"; + +export interface CurvePathJSON extends CurveJSON { + autoClose: boolean; + curves: CurveJSON[]; +} /** * Curved Path - a curve path is simply a array of connected curves, but retains the api of a curve. @@ -66,4 +71,7 @@ export class CurvePath extends Curve * @param divisions Number of pieces to divide the curve into. Expects a `Integer`. Default `40` */ override getSpacedPoints(divisions?: number): TVector[]; + + toJSON(): CurvePathJSON; + fromJSON(json: CurvePathJSON): this; } diff --git a/types/three/src/extras/core/Path.d.ts b/types/three/src/extras/core/Path.d.ts index 88a175c39..28be15b9c 100644 --- a/types/three/src/extras/core/Path.d.ts +++ b/types/three/src/extras/core/Path.d.ts @@ -1,5 +1,9 @@ -import { Vector2 } from "../../math/Vector2.js"; -import { CurvePath } from "./CurvePath.js"; +import { Vector2, Vector2Tuple } from "../../math/Vector2.js"; +import { CurvePath, CurvePathJSON } from "./CurvePath.js"; + +export interface PathJSON extends CurvePathJSON { + currentPoint: Vector2Tuple; +} /** * A 2D {@link Path} representation. @@ -156,4 +160,7 @@ export class Path extends CurvePath { * @param points An array of {@link Vector2 | Vector2's} */ splineThru(pts: Vector2[]): this; + + toJSON(): PathJSON; + fromJSON(json: PathJSON): this; } diff --git a/types/three/src/lights/Light.d.ts b/types/three/src/lights/Light.d.ts index 403b84ab3..3ae757e3b 100644 --- a/types/three/src/lights/Light.d.ts +++ b/types/three/src/lights/Light.d.ts @@ -1,6 +1,21 @@ -import { Object3D } from "../core/Object3D.js"; +import { JSONMeta, Object3D, Object3DJSON } from "../core/Object3D.js"; import { Color, ColorRepresentation } from "../math/Color.js"; -import { LightShadow } from "./LightShadow.js"; +import { LightShadow, LightShadowJSON } from "./LightShadow.js"; + +export interface LightJSON extends Object3DJSON { + color: number; + intensity: number; + + groundColor?: number; + + distance?: number; + angle?: number; + decay?: number; + penumbra?: number; + + shadow?: LightShadowJSON; + target?: string; +} /** * Abstract base class for lights. @@ -62,4 +77,6 @@ export abstract class Light; +} + /** * Serves as a base class for the other shadow classes. * @see {@link https://threejs.org/docs/index.html#api/en/lights/shadows/LightShadow | Official Documentation} @@ -127,7 +138,7 @@ export class LightShadow { /** * Serialize this LightShadow. */ - toJSON(): {}; + toJSON(): LightShadowJSON; /** * Gets the shadow cameras frustum diff --git a/types/three/src/math/Euler.d.ts b/types/three/src/math/Euler.d.ts index e4a516dc8..81be13d82 100644 --- a/types/three/src/math/Euler.d.ts +++ b/types/three/src/math/Euler.d.ts @@ -4,6 +4,8 @@ import { Vector3 } from "./Vector3.js"; export type EulerOrder = "XYZ" | "YXZ" | "ZXY" | "ZYX" | "YZX" | "XZY"; +export type EulerTuple = [x: number, y: number, z: number, order?: EulerOrder]; + export class Euler { constructor(x?: number, y?: number, z?: number, order?: EulerOrder); @@ -38,8 +40,8 @@ export class Euler { setFromVector3(v: Vector3, order?: EulerOrder): Euler; reorder(newOrder: EulerOrder): Euler; equals(euler: Euler): boolean; - fromArray(xyzo: [number, number, number, EulerOrder?, ...any[]]): Euler; - toArray(array?: Array, offset?: number): Array; + fromArray(array: EulerTuple): Euler; + toArray(array?: Partial, offset?: number): EulerTuple; _onChange(callback: () => void): this; static DEFAULT_ORDER: "XYZ"; diff --git a/types/three/src/math/Matrix3.d.ts b/types/three/src/math/Matrix3.d.ts index 0d2a0448b..d2dbb91f3 100644 --- a/types/three/src/math/Matrix3.d.ts +++ b/types/three/src/math/Matrix3.d.ts @@ -4,7 +4,17 @@ import { Matrix4 } from "./Matrix4.js"; import { Vector2 } from "./Vector2.js"; import { Vector3 } from "./Vector3.js"; -export type Matrix3Tuple = [number, number, number, number, number, number, number, number, number]; +export type Matrix3Tuple = [ + n11: number, + n12: number, + n13: number, + n21: number, + n22: number, + n23: number, + n31: number, + n32: number, + n33: number, +]; /** * ( interface Matrix ) diff --git a/types/three/src/math/Matrix4.d.ts b/types/three/src/math/Matrix4.d.ts index 68490151b..584eb91ae 100644 --- a/types/three/src/math/Matrix4.d.ts +++ b/types/three/src/math/Matrix4.d.ts @@ -5,22 +5,22 @@ import { Quaternion } from "./Quaternion.js"; import { Vector3 } from "./Vector3.js"; export type Matrix4Tuple = [ - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, + n11: number, + n12: number, + n13: number, + n14: number, + n21: number, + n22: number, + n23: number, + n24: number, + n31: number, + n32: number, + n33: number, + n34: number, + n41: number, + n42: number, + n43: number, + n44: number, ]; /** diff --git a/types/three/src/math/Quaternion.d.ts b/types/three/src/math/Quaternion.d.ts index ef084024d..c8adc8f11 100644 --- a/types/three/src/math/Quaternion.d.ts +++ b/types/three/src/math/Quaternion.d.ts @@ -11,6 +11,8 @@ export interface QuaternionLike { readonly w: number; } +export type QuaternionTuple = [x: number, y: number, z: number, w: number]; + /** * Implementation of a quaternion. This is used for rotating things without incurring in the dreaded gimbal lock issue, amongst other advantages. * @@ -127,7 +129,7 @@ export class Quaternion { * @param array the source array or array-like. * @param offset (optional) offset into the array. Default is 0. */ - fromArray(array: number[] | ArrayLike, offset?: number): this; + fromArray(array: QuaternionTuple, offset?: number): this; /** * Returns an array [x, y, z, w], or copies x, y, z and w into the provided array. @@ -135,7 +137,7 @@ export class Quaternion { * @param offset (optional) optional offset into the array. * @return The created or provided array. */ - toArray(array?: number[], offset?: number): number[]; + toArray(array?: number[], offset?: number): QuaternionTuple; /** * Copies x, y, z and w into the provided array-like. @@ -143,7 +145,7 @@ export class Quaternion { * @param offset (optional) optional offset into the array. * @return The provided array-like. */ - toArray(array: ArrayLike, offset?: number): ArrayLike; + toArray(array: ArrayLike, offset?: number): QuaternionTuple; /** * This method defines the serialization result of Quaternion. diff --git a/types/three/src/math/Vector2.d.ts b/types/three/src/math/Vector2.d.ts index fa7684676..fd2a84a1d 100644 --- a/types/three/src/math/Vector2.d.ts +++ b/types/three/src/math/Vector2.d.ts @@ -1,7 +1,7 @@ import { BufferAttribute } from "../core/BufferAttribute.js"; import { Matrix3 } from "./Matrix3.js"; -export type Vector2Tuple = [number, number]; +export type Vector2Tuple = [x: number, y: number]; export interface Vector2Like { readonly x: number; diff --git a/types/three/src/objects/InstancedMesh.d.ts b/types/three/src/objects/InstancedMesh.d.ts index 4f212fb76..afcc8a924 100644 --- a/types/three/src/objects/InstancedMesh.d.ts +++ b/types/three/src/objects/InstancedMesh.d.ts @@ -1,13 +1,22 @@ +import { BufferAttributeJSON } from "./../core/BufferAttribute.js"; import { BufferGeometry } from "../core/BufferGeometry.js"; import { InstancedBufferAttribute } from "../core/InstancedBufferAttribute.js"; -import { Object3DEventMap } from "../core/Object3D.js"; +import { JSONMeta, Object3DEventMap, Object3DJSON, Object3DRootJSON } from "../core/Object3D.js"; import { Material } from "../materials/Material.js"; import { Box3 } from "../math/Box3.js"; import { Color } from "../math/Color.js"; import { Matrix4 } from "../math/Matrix4.js"; import { Sphere } from "../math/Sphere.js"; import { DataTexture } from "../textures/DataTexture.js"; -import { Mesh } from "./Mesh.js"; +import { Mesh, MeshJSONObject } from "./Mesh.js"; + +export interface InstancedMeshJSONObject extends MeshJSONObject { + count: number; + instanceMatrix: BufferAttributeJSON; + instanceColor?: BufferAttributeJSON; +} + +export type InstancedMeshJSON = Object3DJSON; export interface InstancedMeshEventMap extends Object3DEventMap { dispose: {}; @@ -163,4 +172,7 @@ export class InstancedMesh< * Call this method whenever this instance is no longer used in your app. */ dispose(): this; + + toJSON(meta: JSONMeta): InstancedMeshJSON; + toJSON(): Object3DRootJSON; } diff --git a/types/three/src/objects/LOD.d.ts b/types/three/src/objects/LOD.d.ts index 013ce60a7..9119b89aa 100644 --- a/types/three/src/objects/LOD.d.ts +++ b/types/three/src/objects/LOD.d.ts @@ -1,5 +1,24 @@ import { Camera } from "../cameras/Camera.js"; -import { Object3D, Object3DEventMap } from "../core/Object3D.js"; +import { + JSONMeta, + Object3D, + Object3DEventMap, + Object3DJSON, + Object3DJSONObject, + Object3DRootJSON, +} from "../core/Object3D.js"; + +export interface LODJSONObject extends Object3DJSONObject { + autoUpdate?: boolean; + + levels: Array<{ + object: string; + distance: number; + hysteresis: number; + }>; +} + +export type LODJSON = Object3DJSON; /** * Every level is associated with an object, and rendering can be switched between them at the distances specified @@ -85,4 +104,7 @@ export class LOD extends * @param camera */ update(camera: Camera): void; + + toJSON(meta: JSONMeta): LODJSON; + toJSON(): Object3DRootJSON; } diff --git a/types/three/src/objects/Mesh.d.ts b/types/three/src/objects/Mesh.d.ts index b1fc8db57..7f6f01db7 100644 --- a/types/three/src/objects/Mesh.d.ts +++ b/types/three/src/objects/Mesh.d.ts @@ -1,8 +1,21 @@ import { BufferGeometry } from "../core/BufferGeometry.js"; -import { Object3D, Object3DEventMap } from "../core/Object3D.js"; +import { + JSONMeta, + Object3D, + Object3DEventMap, + Object3DJSON, + Object3DJSONObject, + Object3DRootJSON, +} from "../core/Object3D.js"; import { Material } from "../materials/Material.js"; import { Vector3 } from "../math/Vector3.js"; +export interface MeshJSONObject extends Object3DJSONObject { + geometry: string; +} + +export type MeshJSON = Object3DJSON; + /** * Class representing triangular {@link https://en.wikipedia.org/wiki/Polygon_mesh | polygon mesh} based objects. * @remarks @@ -81,4 +94,7 @@ export class Mesh< * @param target */ getVertexPosition(index: number, target: Vector3): Vector3; + + toJSON(meta: JSONMeta): MeshJSON; + toJSON(): Object3DRootJSON; } diff --git a/types/three/src/objects/Points.d.ts b/types/three/src/objects/Points.d.ts index ab6b172c6..3cba2c74b 100644 --- a/types/three/src/objects/Points.d.ts +++ b/types/three/src/objects/Points.d.ts @@ -1,7 +1,4 @@ -import { BufferAttribute } from "../core/BufferAttribute.js"; import { BufferGeometry, NormalOrGLBufferAttributes } from "../core/BufferGeometry.js"; -import { GLBufferAttribute } from "../core/GLBufferAttribute.js"; -import { InterleavedBufferAttribute } from "../core/InterleavedBufferAttribute.js"; import { Object3D, Object3DEventMap } from "../core/Object3D.js"; import { Material } from "../materials/Material.js"; diff --git a/types/three/src/objects/Skeleton.d.ts b/types/three/src/objects/Skeleton.d.ts index c83f35560..aaeb3198b 100644 --- a/types/three/src/objects/Skeleton.d.ts +++ b/types/three/src/objects/Skeleton.d.ts @@ -1,7 +1,14 @@ -import { Matrix4 } from "../math/Matrix4.js"; +import { Matrix4, Matrix4Tuple } from "../math/Matrix4.js"; import { DataTexture } from "../textures/DataTexture.js"; import { Bone } from "./Bone.js"; +export interface SkeletonJSON { + metadata: { version: number; type: string; generator: string }; + bones: string[]; + boneInverses: Matrix4Tuple[]; + uuid: string; +} + /** * Use an array of {@link Bone | bones} to create a {@link Skeleton} that can be used by a {@link THREE.SkinnedMesh | SkinnedMesh}. * @example @@ -107,7 +114,7 @@ export class Skeleton { */ dispose(): void; - toJSON(): unknown; + toJSON(): SkeletonJSON; - fromJSON(json: unknown, bones: Record): void; + fromJSON(json: SkeletonJSON, bones: Record): void; } diff --git a/types/three/src/objects/SkinnedMesh.d.ts b/types/three/src/objects/SkinnedMesh.d.ts index 49a644f2b..60bd224b6 100644 --- a/types/three/src/objects/SkinnedMesh.d.ts +++ b/types/three/src/objects/SkinnedMesh.d.ts @@ -1,14 +1,22 @@ import { BindMode } from "../constants.js"; import { BufferGeometry } from "../core/BufferGeometry.js"; -import { Object3DEventMap } from "../core/Object3D.js"; +import { JSONMeta, Object3DEventMap, Object3DJSON, Object3DRootJSON } from "../core/Object3D.js"; import { Material } from "../materials/Material.js"; import { Box3 } from "../math/Box3.js"; -import { Matrix4 } from "../math/Matrix4.js"; +import { Matrix4, Matrix4Tuple } from "../math/Matrix4.js"; import { Sphere } from "../math/Sphere.js"; import { Vector3 } from "../math/Vector3.js"; -import { Mesh } from "./Mesh.js"; +import { Mesh, MeshJSONObject } from "./Mesh.js"; import { Skeleton } from "./Skeleton.js"; +export interface SkinnedMeshJSONObject extends MeshJSONObject { + bindMode: BindMode; + bindMatrix: Matrix4Tuple; + skeleton?: string; +} + +export type SkinnedMeshJSON = Object3DJSON; + /** * A mesh that has a {@link THREE.Skeleton | Skeleton} with {@link Bone | bones} that can then be used to animate the vertices of the geometry. * @example @@ -145,4 +153,7 @@ export class SkinnedMesh< * @param vector */ applyBoneTransform(index: number, vector: Vector3): Vector3; + + toJSON(meta: JSONMeta): SkinnedMeshJSON; + toJSON(): Object3DRootJSON; } diff --git a/types/three/src/scenes/Fog.d.ts b/types/three/src/scenes/Fog.d.ts index 857607987..fc0f18019 100644 --- a/types/three/src/scenes/Fog.d.ts +++ b/types/three/src/scenes/Fog.d.ts @@ -1,28 +1,11 @@ import { Color, ColorRepresentation } from "../math/Color.js"; -export interface FogBase { - /** - * Optional name of the `Fog` object - * @remarks _(doesn't need to be unique)_. - * @defaultValue `""` - */ +export interface FogJSON { + type: string; name: string; - - /** - * Fog color. - * @remarks If set to black, far away objects will be rendered black. - */ - color: Color; - - /** - * Returns a new Fog instance with the same parameters as this one. - */ - clone(): FogBase; - - /** - * Return Fog data in JSON format. - */ - toJSON(): any; + color: number; + near: number; + far: number; } /** @@ -35,7 +18,7 @@ export interface FogBase { * @see {@link https://threejs.org/docs/index.html#api/en/scenes/Fog | Official Documentation} * @see {@link https://github.com/mrdoob/three.js/blob/master/src/scenes/Fog.js | Source} */ -export class Fog implements FogBase { +export class Fog { /** * The color parameter is passed to the {@link THREE.Color | Color} constructor to set the color property * @remarks @@ -90,5 +73,5 @@ export class Fog implements FogBase { /** * Return {@link Fog} data in JSON format. */ - toJSON(): any; + toJSON(): FogJSON; } diff --git a/types/three/src/scenes/FogExp2.d.ts b/types/three/src/scenes/FogExp2.d.ts index df60aad31..af00981e6 100644 --- a/types/three/src/scenes/FogExp2.d.ts +++ b/types/three/src/scenes/FogExp2.d.ts @@ -1,5 +1,11 @@ import { Color, ColorRepresentation } from "../math/Color.js"; -import { FogBase } from "./Fog.js"; + +export interface FogExp2JSON { + type: string; + name: string; + color: number; + density: number; +} /** * This class contains the parameters that define exponential squared fog, which gives a clear view near the camera and a faster than exponentially densening fog farther from the camera. @@ -12,7 +18,7 @@ import { FogBase } from "./Fog.js"; * @see {@link https://threejs.org/docs/index.html#api/en/scenes/FogExp2 | Official Documentation} * @see {@link https://github.com/mrdoob/three.js/blob/master/src/scenes/FogExp2.js | Source} */ -export class FogExp2 implements FogBase { +export class FogExp2 { /** * The color parameter is passed to the {@link THREE.Color | Color} constructor to set the color property * @remarks Color can be a hexadecimal integer or a CSS-style string. @@ -56,5 +62,5 @@ export class FogExp2 implements FogBase { /** * Return {@link FogExp2} data in JSON format. */ - toJSON(): any; + toJSON(): FogExp2JSON; } diff --git a/types/three/src/scenes/Scene.d.ts b/types/three/src/scenes/Scene.d.ts index 565356c8d..bcbe8b88e 100644 --- a/types/three/src/scenes/Scene.d.ts +++ b/types/three/src/scenes/Scene.d.ts @@ -1,10 +1,24 @@ -import { Object3D } from "../core/Object3D.js"; +import { JSONMeta, Object3D, Object3DJSON, Object3DJSONObject, Object3DRootJSON } from "../core/Object3D.js"; import { Material } from "../materials/Material.js"; import { Color } from "../math/Color.js"; -import { Euler } from "../math/Euler.js"; +import { Euler, EulerTuple } from "../math/Euler.js"; import { CubeTexture } from "../textures/CubeTexture.js"; import { Texture } from "../textures/Texture.js"; -import { FogBase } from "./Fog.js"; +import { Fog, FogJSON } from "./Fog.js"; +import { FogExp2, FogExp2JSON } from "./FogExp2.js"; + +export interface SceneJSONObject extends Object3DJSONObject { + fog?: FogJSON | FogExp2JSON; + + backgroundBlurriness?: number; + backgroundIntensity?: number; + backgroundRotation: EulerTuple; + + environmentIntensity?: number; + environmentRotation: EulerTuple; +} + +export type SceneJSON = Object3DJSON; /** * Scenes allow you to set up what and where is to be rendered by three.js @@ -37,7 +51,7 @@ export class Scene extends Object3D { * A {@link Fog | fog} instance defining the type of fog that affects everything rendered in the scene. * @defaultValue `null` */ - fog: FogBase | null; + fog: Fog | FogExp2 | null; /** * Sets the blurriness of the background. Only influences environment maps assigned to {@link THREE.Scene.background | Scene.background}. @@ -98,5 +112,6 @@ export class Scene extends Object3D { * Convert the {@link Scene} to three.js {@link https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 | JSON Object/Scene format}. * @param meta Object containing metadata such as textures or images for the scene. */ - toJSON(meta?: any): any; + toJSON(meta: JSONMeta): SceneJSON; + toJSON(): Object3DRootJSON; } diff --git a/types/three/src/textures/Source.d.ts b/types/three/src/textures/Source.d.ts index f14b70555..6a95dd1dd 100644 --- a/types/three/src/textures/Source.d.ts +++ b/types/three/src/textures/Source.d.ts @@ -1,3 +1,19 @@ +import { JSONMeta } from "../Three.js"; + +export type SerializedImage = + | string + | { + data: number[]; + width: number; + height: number; + type: string; + }; + +export class SourceJSON { + uuid: string; + url: SerializedImage | SerializedImage[]; +} + /** * Represents the data {@link Source} of a texture. * @see {@link https://threejs.org/docs/index.html#api/en/textures/Source | Official Documentation} @@ -57,5 +73,5 @@ export class Source { * Convert the data {@link Source} to three.js {@link https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 | JSON Object/Scene format}. * @param meta Optional object containing metadata. */ - toJSON(meta?: string | {}): {}; + toJSON(meta?: string | JSONMeta): SourceJSON; } diff --git a/types/three/src/textures/Texture.d.ts b/types/three/src/textures/Texture.d.ts index c1fc6706b..80699218e 100644 --- a/types/three/src/textures/Texture.d.ts +++ b/types/three/src/textures/Texture.d.ts @@ -13,13 +13,50 @@ import { import { EventDispatcher } from "../core/EventDispatcher.js"; import { Matrix3 } from "../math/Matrix3.js"; import { Vector2 } from "../math/Vector2.js"; +import { JSONMeta } from "../Three.js"; import { CompressedTextureMipmap } from "./CompressedTexture.js"; import { CubeTexture } from "./CubeTexture.js"; import { Source } from "./Source.js"; +export interface TextureJSON { + metadata: { version: number; type: string; generator: string }; + + uuid: string; + name: string; + + image: string; + + mapping: AnyMapping; + channel: number; + + repeat: [x: number, y: number]; + offset: [x: number, y: number]; + center: [x: number, y: number]; + rotation: number; + + wrap: [wrapS: number, wrapT: number]; + + format: AnyPixelFormat; + internalFormat: PixelFormatGPU | null; + type: TextureDataType; + colorSpace: ColorSpace; + + minFilter: MinificationTextureFilter; + magFilter: MagnificationTextureFilter; + anisotropy: number; + + flipY: boolean; + + generateMipmaps: boolean; + premultiplyAlpha: boolean; + unpackAlignment: number; + + userData?: Record; +} + /** Shim for OffscreenCanvas. */ // eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface OffscreenCanvas extends EventTarget {} +export interface OffscreenCanvas extends EventTarget { } /** * Create a {@link Texture} to apply to a surface or as a reflection or refraction map. @@ -431,7 +468,7 @@ export class Texture extends EventDispatcher<{ dispose: {} }> { * Convert the texture to three.js {@link https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 | JSON Object/Scene format}. * @param meta Optional object containing metadata. */ - toJSON(meta?: string | {}): {}; + toJSON(meta?: string | JSONMeta): TextureJSON; /** * Frees the GPU-related resources allocated by this instance