ris-framework 0.1.0-dev.9 → 0.2.0-dev.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -1
- package/README.md +15 -4
- package/dist/Framework.d.ts +9 -3
- package/dist/Framework.d.ts.map +1 -1
- package/dist/api/IFramework.d.ts +7 -6
- package/dist/api/IFramework.d.ts.map +1 -1
- package/dist/api/_export.d.ts +2 -0
- package/dist/api/_export.d.ts.map +1 -1
- package/dist/api/camera/CameraFactory.d.ts +3 -2
- package/dist/api/camera/CameraFactory.d.ts.map +1 -1
- package/dist/api/camera/ICamera.d.ts +5 -0
- package/dist/api/camera/ICamera.d.ts.map +1 -1
- package/dist/api/camera/ICameraFactory.d.ts +5 -6
- package/dist/api/camera/ICameraFactory.d.ts.map +1 -1
- package/dist/api/camera/OrthographicCamera.d.ts +7 -0
- package/dist/api/camera/OrthographicCamera.d.ts.map +1 -1
- package/dist/api/camera/PerspectiveCamera.d.ts +30 -6
- package/dist/api/camera/PerspectiveCamera.d.ts.map +1 -1
- package/dist/api/content/ContentManager.d.ts +67 -2
- package/dist/api/content/ContentManager.d.ts.map +1 -1
- package/dist/api/content/IContentManager.d.ts +32 -1
- package/dist/api/content/IContentManager.d.ts.map +1 -1
- package/dist/api/content/ShaderModuleContent.d.ts.map +1 -1
- package/dist/api/data/Color.d.ts +5 -0
- package/dist/api/data/Color.d.ts.map +1 -1
- package/dist/api/geometry/BaseGeometry.d.ts +9 -0
- package/dist/api/geometry/BaseGeometry.d.ts.map +1 -1
- package/dist/api/geometry/GeometryBuilder.d.ts +3 -1
- package/dist/api/geometry/GeometryBuilder.d.ts.map +1 -1
- package/dist/api/geometry/IGeometryBuilder.d.ts +24 -0
- package/dist/api/geometry/IGeometryBuilder.d.ts.map +1 -1
- package/dist/api/geometry/_export-geometry.d.ts +1 -0
- package/dist/api/geometry/_export-geometry.d.ts.map +1 -1
- package/dist/api/input/InputManager.d.ts +4 -0
- package/dist/api/input/InputManager.d.ts.map +1 -1
- package/dist/api/lights/AmbientLight.d.ts +35 -0
- package/dist/api/lights/AmbientLight.d.ts.map +1 -0
- package/dist/api/lights/DirectionalLight.d.ts +40 -0
- package/dist/api/lights/DirectionalLight.d.ts.map +1 -0
- package/dist/api/lights/LightFactory.d.ts +18 -0
- package/dist/api/lights/LightFactory.d.ts.map +1 -0
- package/dist/api/lights/LightId.d.ts +6 -0
- package/dist/api/lights/LightId.d.ts.map +1 -0
- package/dist/api/lights/LightsBuffer.d.ts +70 -0
- package/dist/api/lights/LightsBuffer.d.ts.map +1 -0
- package/dist/api/lights/PointLight.d.ts +59 -0
- package/dist/api/lights/PointLight.d.ts.map +1 -0
- package/dist/api/lights/_export.d.ts +6 -0
- package/dist/api/lights/_export.d.ts.map +1 -0
- package/dist/api/loaders/ObjGeometryMapper.d.ts +19 -0
- package/dist/api/loaders/ObjGeometryMapper.d.ts.map +1 -0
- package/dist/api/loaders/_export.d.ts +1 -0
- package/dist/api/loaders/_export.d.ts.map +1 -1
- package/dist/api/loaders/obj/ObjLoader.d.ts +29 -0
- package/dist/api/loaders/obj/ObjLoader.d.ts.map +1 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts +103 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -0
- package/dist/api/loaders/obj/index.d.ts +3 -0
- package/dist/api/loaders/obj/index.d.ts.map +1 -0
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +127 -0
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -0
- package/dist/api/material/IMaterial.d.ts +15 -6
- package/dist/api/material/IMaterial.d.ts.map +1 -1
- package/dist/api/material/IMaterialFactory.d.ts +17 -2
- package/dist/api/material/IMaterialFactory.d.ts.map +1 -1
- package/dist/api/material/InspectTextureMipsMaterial.d.ts +16 -7
- package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
- package/dist/api/material/MaterialFactory.d.ts +6 -0
- package/dist/api/material/MaterialFactory.d.ts.map +1 -1
- package/dist/api/material/SpriteMaterial.d.ts +51 -0
- package/dist/api/material/SpriteMaterial.d.ts.map +1 -0
- package/dist/api/material/UnlitMaterial.d.ts +28 -10
- package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
- package/dist/api/material/_export.d.ts +2 -0
- package/dist/api/material/_export.d.ts.map +1 -1
- package/dist/api/meshes/IMesh.d.ts +35 -5
- package/dist/api/meshes/IMesh.d.ts.map +1 -1
- package/dist/api/meshes/IMeshFactory.d.ts +25 -4
- package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/Mesh.d.ts +58 -6
- package/dist/api/meshes/Mesh.d.ts.map +1 -1
- package/dist/api/meshes/MeshFactory.d.ts +7 -3
- package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/QuadMesh.d.ts +5 -1
- package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
- package/dist/api/meshes/SubMesh.d.ts +47 -0
- package/dist/api/meshes/SubMesh.d.ts.map +1 -0
- package/dist/api/meshes/_export.d.ts +1 -0
- package/dist/api/meshes/_export.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts +56 -0
- package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts.map +1 -0
- package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts +3 -0
- package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts +29 -0
- package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts +1 -0
- package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts.map +1 -1
- package/dist/api/scene/Scene.d.ts +104 -0
- package/dist/api/scene/Scene.d.ts.map +1 -0
- package/dist/api/shader/IShaderModuleLoader.d.ts +4 -1
- package/dist/api/shader/IShaderModuleLoader.d.ts.map +1 -1
- package/dist/api/shader/{shader-loader.d.ts → ShaderLoader.d.ts} +1 -1
- package/dist/api/shader/ShaderLoader.d.ts.map +1 -0
- package/dist/api/sprites/SpriteBatchDrawable.d.ts +1 -1
- package/dist/api/sprites/SpriteBatchDrawable.d.ts.map +1 -1
- package/dist/api/sprites/SpriteBatchMesh.d.ts +14 -1
- package/dist/api/sprites/SpriteBatchMesh.d.ts.map +1 -1
- package/dist/api/utilities/GeometryUtilities.d.ts.map +1 -1
- package/dist/api/window/WindowManager.d.ts +4 -0
- package/dist/api/window/WindowManager.d.ts.map +1 -1
- package/dist/core/rendering/vertex-buffer-layout.d.ts +1 -0
- package/dist/core/rendering/vertex-buffer-layout.d.ts.map +1 -1
- package/dist/index.js +2252 -260
- package/dist/webgl/WebGlGraphicsDevice.d.ts.map +1 -1
- package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts +17 -0
- package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts.map +1 -0
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts +55 -0
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -0
- package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +3 -0
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts +3 -1
- package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts +88 -0
- package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts.map +1 -0
- package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/shader/WebGlShaderModule.d.ts +4 -1
- package/dist/webgl/shader/WebGlShaderModule.d.ts.map +1 -1
- package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts +16 -5
- package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTexture2D.d.ts +8 -1
- package/dist/webgl/texture/WebGlTexture2D.d.ts.map +1 -1
- package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts +0 -1
- package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts.map +1 -1
- package/package.json +4 -4
- package/shaders/glsl/forward_blinn_phong_material_fs.glsl +110 -0
- package/shaders/glsl/forward_blinn_phong_material_vs.glsl +32 -0
- package/shaders/glsl/sprite_fs.glsl +1 -1
- package/shaders/glsl/unlit_material_fs.glsl +1 -1
- package/src/Framework.ts +37 -13
- package/src/api/IFramework.ts +8 -6
- package/src/api/_export.ts +2 -0
- package/src/api/camera/CameraFactory.ts +6 -6
- package/src/api/camera/ICamera.ts +6 -0
- package/src/api/camera/ICameraFactory.ts +5 -10
- package/src/api/camera/OrthographicCamera.ts +23 -1
- package/src/api/camera/PerspectiveCamera.ts +60 -15
- package/src/api/content/ContentManager.ts +201 -5
- package/src/api/content/IContentManager.ts +33 -1
- package/src/api/content/ShaderModuleContent.ts +9 -0
- package/src/api/data/Color.ts +7 -1
- package/src/api/geometry/BaseGeometry.ts +23 -0
- package/src/api/geometry/GeometryBuilder.ts +14 -2
- package/src/api/geometry/IGeometryBuilder.ts +31 -1
- package/src/api/geometry/_export-geometry.ts +2 -1
- package/src/api/input/InputManager.ts +14 -5
- package/src/api/lights/AmbientLight.ts +53 -0
- package/src/api/lights/DirectionalLight.ts +60 -0
- package/src/api/lights/LightFactory.ts +21 -0
- package/src/api/lights/LightId.ts +9 -0
- package/src/api/lights/LightsBuffer.ts +87 -0
- package/src/api/lights/PointLight.ts +91 -0
- package/src/api/lights/_export.ts +5 -0
- package/src/api/loaders/ObjGeometryMapper.ts +28 -0
- package/src/api/loaders/_export.ts +2 -1
- package/src/api/loaders/obj/ObjLoader.ts +270 -0
- package/src/api/loaders/obj/ObjTypes.ts +124 -0
- package/src/api/loaders/obj/index.ts +5 -0
- package/src/api/material/ForwardBlinnPhongMaterial.ts +302 -0
- package/src/api/material/IMaterial.ts +16 -6
- package/src/api/material/IMaterialFactory.ts +19 -2
- package/src/api/material/InspectTextureMipsMaterial.ts +63 -24
- package/src/api/material/MaterialFactory.ts +12 -0
- package/src/api/material/SpriteMaterial.ts +83 -0
- package/src/api/material/UnlitMaterial.ts +101 -29
- package/src/api/material/_export.ts +3 -1
- package/src/api/meshes/IMesh.ts +45 -6
- package/src/api/meshes/IMeshFactory.ts +27 -4
- package/src/api/meshes/Mesh.ts +163 -41
- package/src/api/meshes/MeshFactory.ts +30 -6
- package/src/api/meshes/QuadMesh.ts +6 -2
- package/src/api/meshes/SubMesh.ts +71 -0
- package/src/api/meshes/_export.ts +1 -0
- package/src/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts +66 -0
- package/src/api/rendering/render-pipelines/IRenderPipeline.ts +4 -0
- package/src/api/rendering/render-pipelines/IRenderPipelineFactory.ts +39 -0
- package/src/api/rendering/render-pipelines/_export-render-pipelines.ts +2 -1
- package/src/api/scene/Scene.ts +264 -0
- package/src/api/shader/IShaderModuleLoader.ts +2 -1
- package/src/api/sprites/SpriteBatchDrawable.ts +12 -16
- package/src/api/sprites/SpriteBatchMesh.ts +23 -4
- package/src/api/utilities/GeometryUtilities.ts +2 -0
- package/src/api/window/WindowManager.ts +22 -2
- package/src/core/rendering/vertex-buffer-layout.ts +32 -1
- package/src/main.ts +0 -1
- package/src/webgl/WebGlGraphicsDevice.ts +0 -1
- package/src/webgl/lights/WebGlAmbientLightFactory.ts +35 -0
- package/src/webgl/lights/WebGlLightsBuffer.ts +215 -0
- package/src/webgl/render-pipelines/AWebGlRenderPipeline.ts +7 -1
- package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +3 -0
- package/src/webgl/render-pipelines/WebGlRenderPipelineFactory.ts +24 -2
- package/src/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.ts +16 -6
- package/src/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.ts +300 -0
- package/src/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.ts +16 -6
- package/src/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.ts +11 -7
- package/src/webgl/shader/WebGlShaderModule.ts +11 -4
- package/src/webgl/shader/WebGlShaderModuleLoader.ts +29 -10
- package/src/webgl/texture/WebGlTexture2D.ts +19 -5
- package/src/webgl/utilities/webgl-filter-anisotropic-utilities.ts +9 -6
- package/dist/api/shader/shader-loader.d.ts.map +0 -1
- /package/src/api/shader/{shader-loader.ts → ShaderLoader.ts} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type {AmbientLight} from "./AmbientLight.ts";
|
|
2
|
+
import type {DirectionalLight} from "./DirectionalLight.ts";
|
|
3
|
+
import type {PointLight} from "./PointLight.ts";
|
|
4
|
+
import type {IUniformBuffer} from "../rendering/buffers/IUniformBuffer.ts";
|
|
5
|
+
import type {IDisposable} from "../core/IDisposable.ts";
|
|
6
|
+
|
|
7
|
+
/** The number of directional lights the lights buffer and the Blinn-Phong shader hold by default. */
|
|
8
|
+
export const DEFAULT_DIRECTIONAL_LIGHTS_COUNT = 3;
|
|
9
|
+
|
|
10
|
+
/** The number of point lights the lights buffer and the Blinn-Phong shader hold by default. */
|
|
11
|
+
export const DEFAULT_POINT_LIGHTS_COUNT = 3;
|
|
12
|
+
|
|
13
|
+
/** The descriptor for a lights buffer. */
|
|
14
|
+
export interface LightsBufferDescriptor {
|
|
15
|
+
|
|
16
|
+
/** The ambient light. Defaults to a black ambient light. */
|
|
17
|
+
ambientLight?: AmbientLight;
|
|
18
|
+
|
|
19
|
+
/** The initial directional lights. More than {@link maxDirectionalLights} throws. */
|
|
20
|
+
directionalLights?: DirectionalLight[];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The number of directional light slots. Must match `DIRECTIONAL_LIGHTS_COUNT` in the shader.
|
|
24
|
+
* Defaults to {@link DEFAULT_DIRECTIONAL_LIGHTS_COUNT}.
|
|
25
|
+
*/
|
|
26
|
+
maxDirectionalLights?: number;
|
|
27
|
+
|
|
28
|
+
/** The initial point lights. More than {@link maxPointLights} throws. */
|
|
29
|
+
pointLights?: PointLight[];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The number of point light slots. Must match `POINT_LIGHTS_COUNT` in the shader.
|
|
33
|
+
* Defaults to {@link DEFAULT_POINT_LIGHTS_COUNT}.
|
|
34
|
+
*/
|
|
35
|
+
maxPointLights?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Holds the lights of a scene and owns the uniform buffer that shaders read them from.
|
|
40
|
+
* Assign it to lit materials, e.g. `ForwardBlinnPhongMaterial.lightsBuffer`.
|
|
41
|
+
*
|
|
42
|
+
* std140 layout of the `LightsBuffer` block:
|
|
43
|
+
* Every light colour is written premultiplied by its intensity, so the layout has no intensity field.
|
|
44
|
+
* - `vec3 u_ambientLight` at offset 0, padded to 16 bytes.
|
|
45
|
+
* - `DirectionalLight u_directionalLight[N]` from offset 16, 32 bytes each:
|
|
46
|
+
* `vec3 light` at +0 and `vec3 direction` at +16.
|
|
47
|
+
* - `PointLight u_pointLight[M]` after the directional lights, 48 bytes each:
|
|
48
|
+
* `vec3 light` at +0, `float constant` at +12, `vec3 position` at +16, `float linear` at +28, `float quadratic` at +32.
|
|
49
|
+
*/
|
|
50
|
+
export interface LightsBuffer extends IDisposable {
|
|
51
|
+
|
|
52
|
+
/** The ambient light written to the buffer. */
|
|
53
|
+
ambientLight: AmbientLight;
|
|
54
|
+
|
|
55
|
+
/** The directional lights written to the buffer. Read-only; use {@link add} and {@link remove}. Unused slots are black. */
|
|
56
|
+
readonly directionalLights: readonly DirectionalLight[];
|
|
57
|
+
|
|
58
|
+
/** The number of directional light slots in the buffer. */
|
|
59
|
+
readonly maxDirectionalLights: number;
|
|
60
|
+
|
|
61
|
+
/** The point lights written to the buffer. Read-only; use {@link add} and {@link remove}. Unused slots are black. */
|
|
62
|
+
readonly pointLights: readonly PointLight[];
|
|
63
|
+
|
|
64
|
+
/** The number of point light slots in the buffer. */
|
|
65
|
+
readonly maxPointLights: number;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The uniform buffer holding the lights for shaders.
|
|
69
|
+
* NOTE: Intended to be used internally, never set this value manually.
|
|
70
|
+
*/
|
|
71
|
+
readonly buffer: IUniformBuffer;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Adds a directional or point light. Adding a light that is already in the buffer does nothing.
|
|
75
|
+
* @throws Error when all slots for that kind of light are in use.
|
|
76
|
+
*/
|
|
77
|
+
add(light: DirectionalLight | PointLight): void;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Removes a directional or point light.
|
|
81
|
+
* @returns True when the light was in the buffer.
|
|
82
|
+
*/
|
|
83
|
+
remove(light: DirectionalLight | PointLight): boolean;
|
|
84
|
+
|
|
85
|
+
/** Writes the lights to {@link buffer} if anything changed since the last update. Call once per frame before rendering. */
|
|
86
|
+
update(): void;
|
|
87
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {vec3} from "gl-matrix";
|
|
2
|
+
import {Color} from "../data/Color.ts";
|
|
3
|
+
import {createLightId} from "./LightId.ts";
|
|
4
|
+
import type {Scene} from "../scene/Scene.ts";
|
|
5
|
+
|
|
6
|
+
/** The descriptor for a point light. All fields are optional. */
|
|
7
|
+
export interface PointLightDescriptor {
|
|
8
|
+
/** The unique id. Assigned automatically when omitted. */
|
|
9
|
+
id?: number;
|
|
10
|
+
|
|
11
|
+
/** The optional name for a light. */
|
|
12
|
+
name?: string;
|
|
13
|
+
|
|
14
|
+
/** The light colour. Alpha is ignored. Defaults to white. */
|
|
15
|
+
color?: Color;
|
|
16
|
+
|
|
17
|
+
/** Multiplies the colour. Defaults to 1. */
|
|
18
|
+
intensity?: number;
|
|
19
|
+
|
|
20
|
+
/** World-space position. Defaults to the origin. */
|
|
21
|
+
position?: vec3;
|
|
22
|
+
|
|
23
|
+
/** Constant attenuation term. Defaults to 1. */
|
|
24
|
+
constant?: number;
|
|
25
|
+
|
|
26
|
+
/** Linear attenuation term. Defaults to 0.09 (about 50 units of range). */
|
|
27
|
+
linear?: number;
|
|
28
|
+
|
|
29
|
+
/** Quadratic attenuation term. Defaults to 0.032 (about 50 units of range). */
|
|
30
|
+
quadratic?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The point light. Plain data: it has no GPU resources.
|
|
35
|
+
* Attenuation is `1 / (constant + linear * d + quadratic * d²)` for distance `d`.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export class PointLight {
|
|
39
|
+
|
|
40
|
+
/** The default constant attenuation. */
|
|
41
|
+
public static readonly DEFAULT_CONSTANT = 1;
|
|
42
|
+
|
|
43
|
+
/** The default linear attenuation. */
|
|
44
|
+
public static readonly DEFAULT_LINEAR = 0.09;
|
|
45
|
+
|
|
46
|
+
/** The default quadratic attenuation. */
|
|
47
|
+
public static readonly DEFAULT_QUADRATIC = 0.032;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The constructor.
|
|
51
|
+
* @param descriptor The optional descriptor. Colour and position are copied.
|
|
52
|
+
* @param scene The optional scene; the light adds itself via {@link Scene.add}.
|
|
53
|
+
* @throws Error when the scene has no free point light slot left (the light is then not in the scene).
|
|
54
|
+
*/
|
|
55
|
+
public constructor(descriptor?: PointLightDescriptor, scene?: Scene) {
|
|
56
|
+
this.id = descriptor?.id ?? createLightId();
|
|
57
|
+
this.name = descriptor?.name;
|
|
58
|
+
this.color = descriptor?.color?.copy() ?? Color.white();
|
|
59
|
+
this.intensity = descriptor?.intensity ?? 1;
|
|
60
|
+
this.position = descriptor?.position ? vec3.clone(descriptor.position) : vec3.create();
|
|
61
|
+
this.constant = descriptor?.constant ?? PointLight.DEFAULT_CONSTANT;
|
|
62
|
+
this.linear = descriptor?.linear ?? PointLight.DEFAULT_LINEAR;
|
|
63
|
+
this.quadratic = descriptor?.quadratic ?? PointLight.DEFAULT_QUADRATIC;
|
|
64
|
+
|
|
65
|
+
scene?.add(this);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The unique id of this light. */
|
|
69
|
+
public readonly id: number;
|
|
70
|
+
|
|
71
|
+
/** The optional name for a light. */
|
|
72
|
+
public name?: string;
|
|
73
|
+
|
|
74
|
+
/** The light colour. Alpha is ignored. */
|
|
75
|
+
public color: Color;
|
|
76
|
+
|
|
77
|
+
/** Multiplies {@link color} when written to the lights buffer. */
|
|
78
|
+
public intensity: number;
|
|
79
|
+
|
|
80
|
+
/** World-space position of the light. */
|
|
81
|
+
public position: vec3;
|
|
82
|
+
|
|
83
|
+
/** Constant attenuation term. */
|
|
84
|
+
public constant: number;
|
|
85
|
+
|
|
86
|
+
/** Linear attenuation term. */
|
|
87
|
+
public linear: number;
|
|
88
|
+
|
|
89
|
+
/** Quadratic attenuation term. */
|
|
90
|
+
public quadratic: number;
|
|
91
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {GeometryDescriptor} from "../geometry/IGeometryBuilder.ts";
|
|
2
|
+
import type {ObjGeometryDefinition} from "./obj/index.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Maps plain OBJ geometry definitions from {@link ObjLoader} onto the framework's {@link GeometryDescriptor}.
|
|
6
|
+
* Pass the result to `geometryBuilder.create`.
|
|
7
|
+
* Not part of the public API: `content.loadMeshAsync` and `content.loadBlinnPhongMeshAsync` use it.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class ObjGeometryMapper {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a geometry descriptor from an OBJ geometry definition.
|
|
14
|
+
* @param definition The geometry definition, e.g. `result.geometry` from `ObjLoader.loadAsync`.
|
|
15
|
+
* @param useMaterialColors True keeps the loader's per-vertex `Kd` colours; false (the default) uses white,
|
|
16
|
+
* for when each submesh's material carries the colour instead.
|
|
17
|
+
* @returns The descriptor. It references the definition's arrays; `geometryBuilder.create` copies them.
|
|
18
|
+
*/
|
|
19
|
+
public static toDescriptor(definition: ObjGeometryDefinition, useMaterialColors = false): GeometryDescriptor {
|
|
20
|
+
return {
|
|
21
|
+
positions: definition.positions,
|
|
22
|
+
indices: definition.indices,
|
|
23
|
+
normals: definition.normals,
|
|
24
|
+
textureCoords: definition.textureCoords,
|
|
25
|
+
colors: useMaterialColors ? definition.colors : undefined,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ObjMaterialDefinition,
|
|
3
|
+
type ObjColor,
|
|
4
|
+
type ObjLoadResult,
|
|
5
|
+
type ObjLoadOptions,
|
|
6
|
+
type ObjMaterialRange,
|
|
7
|
+
} from "./ObjTypes.ts";
|
|
8
|
+
|
|
9
|
+
function tokens(line: string): string[] {
|
|
10
|
+
return line.trim().split(/\s+/);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function readColor(parts: string[]): ObjColor | undefined {
|
|
14
|
+
// "Kd spectral ..." and "Kd xyz ..." are not supported.
|
|
15
|
+
if (parts.length < 2 || isNaN(parseFloat(parts[1]))) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const r = parseFloat(parts[1]);
|
|
19
|
+
const g = parts.length > 2 ? parseFloat(parts[2]) : r;
|
|
20
|
+
const b = parts.length > 3 ? parseFloat(parts[3]) : r;
|
|
21
|
+
return [r, g, b];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Loads .obj models (and their .mtl materials) from text or a URL into plain data.
|
|
26
|
+
* Engine-independent; uses only `fetch` and `URL`. `content.loadMeshAsync` turns the result into a framework mesh.
|
|
27
|
+
*/
|
|
28
|
+
export class ObjLoader {
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parses .mtl text.
|
|
32
|
+
* @param text The .mtl contents.
|
|
33
|
+
* @returns The material definitions, in file order.
|
|
34
|
+
*/
|
|
35
|
+
public parseMtl(text: string): ObjMaterialDefinition[] {
|
|
36
|
+
const materials: ObjMaterialDefinition[] = [];
|
|
37
|
+
let current: ObjMaterialDefinition | undefined;
|
|
38
|
+
|
|
39
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
40
|
+
const line = rawLine.trim();
|
|
41
|
+
if (line.length == 0 || line.startsWith("#")) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const parts = tokens(line);
|
|
45
|
+
const keyword = parts[0];
|
|
46
|
+
|
|
47
|
+
if (keyword == "newmtl") {
|
|
48
|
+
current = new ObjMaterialDefinition(line.substring(keyword.length).trim());
|
|
49
|
+
materials.push(current);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (!current) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
switch (keyword) {
|
|
57
|
+
case "Ka":
|
|
58
|
+
current.ambientColor = readColor(parts);
|
|
59
|
+
break;
|
|
60
|
+
case "Kd":
|
|
61
|
+
current.diffuseColor = readColor(parts);
|
|
62
|
+
break;
|
|
63
|
+
case "Ks":
|
|
64
|
+
current.specularColor = readColor(parts);
|
|
65
|
+
break;
|
|
66
|
+
case "Ke":
|
|
67
|
+
current.emissiveColor = readColor(parts);
|
|
68
|
+
break;
|
|
69
|
+
case "Ns":
|
|
70
|
+
current.specularExponent = parseFloat(parts[1]);
|
|
71
|
+
break;
|
|
72
|
+
case "Ni":
|
|
73
|
+
current.opticalDensity = parseFloat(parts[1]);
|
|
74
|
+
break;
|
|
75
|
+
case "illum":
|
|
76
|
+
current.illuminationModel = parseInt(parts[1]);
|
|
77
|
+
break;
|
|
78
|
+
case "d":
|
|
79
|
+
current.opacity = parseFloat(parts[parts.length - 1]);
|
|
80
|
+
break;
|
|
81
|
+
case "Tr":
|
|
82
|
+
// "d" wins when both are present.
|
|
83
|
+
if (current.opacity === undefined) {
|
|
84
|
+
current.opacity = 1 - parseFloat(parts[1]);
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
if (keyword.startsWith("map_") || keyword == "bump" || keyword == "disp"
|
|
89
|
+
|| keyword == "decal" || keyword == "refl" || keyword == "norm") {
|
|
90
|
+
if (parts.length >= 2) {
|
|
91
|
+
current.maps[keyword] = parts[parts.length - 1];
|
|
92
|
+
if (parts.length > 2) {
|
|
93
|
+
current.mapOptions[keyword] = parts.slice(1, -1).join(" ");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return materials;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Parses .obj text.
|
|
106
|
+
* @param text The .obj contents.
|
|
107
|
+
* @param materials Material definitions to use for `usemtl`, e.g. from {@link parseMtl}. Default none.
|
|
108
|
+
* @returns The geometry, materials and raw data.
|
|
109
|
+
*/
|
|
110
|
+
public fromText(text: string, materials: ObjMaterialDefinition[] = []): ObjLoadResult {
|
|
111
|
+
const rawPositions: number[] = [];
|
|
112
|
+
const rawTextureCoords: number[] = [];
|
|
113
|
+
const rawNormals: number[] = [];
|
|
114
|
+
const faceIndices: number[] = [];
|
|
115
|
+
const materialLibraries: string[] = [];
|
|
116
|
+
const materialRanges: ObjMaterialRange[] = [];
|
|
117
|
+
|
|
118
|
+
const positions: number[] = [];
|
|
119
|
+
const textureCoords: number[] = [];
|
|
120
|
+
const normals: number[] = [];
|
|
121
|
+
const colors: number[] = [];
|
|
122
|
+
const indices: number[] = [];
|
|
123
|
+
const vertexLookup = new Map<string, number>();
|
|
124
|
+
|
|
125
|
+
const materialsByName = new Map(materials.map(m => [m.name, m]));
|
|
126
|
+
let materialName: string | undefined;
|
|
127
|
+
let rangeStart = 0;
|
|
128
|
+
|
|
129
|
+
const closeRange = () => {
|
|
130
|
+
if (indices.length > rangeStart) {
|
|
131
|
+
materialRanges.push({materialName, indexStart: rangeStart, indexCount: indices.length - rangeStart});
|
|
132
|
+
}
|
|
133
|
+
rangeStart = indices.length;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const resolve = (value: string | undefined, count: number): number => {
|
|
137
|
+
if (value === undefined || value.length == 0) {
|
|
138
|
+
return -1;
|
|
139
|
+
}
|
|
140
|
+
const index = parseInt(value);
|
|
141
|
+
// OBJ indices are one-based; negative values count back from the end.
|
|
142
|
+
return index < 0 ? count + index : index - 1;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const addCorner = (p: number, t: number, n: number): void => {
|
|
146
|
+
faceIndices.push(p, t, n);
|
|
147
|
+
const key = `${p}/${t}/${n}/${materialName ?? ""}`;
|
|
148
|
+
let vertex = vertexLookup.get(key);
|
|
149
|
+
if (vertex === undefined) {
|
|
150
|
+
vertex = positions.length / 3;
|
|
151
|
+
vertexLookup.set(key, vertex);
|
|
152
|
+
positions.push(rawPositions[p * 3], rawPositions[p * 3 + 1], rawPositions[p * 3 + 2]);
|
|
153
|
+
textureCoords.push(t >= 0 ? rawTextureCoords[t * 2] : 0, t >= 0 ? rawTextureCoords[t * 2 + 1] : 0);
|
|
154
|
+
normals.push(n >= 0 ? rawNormals[n * 3] : 0, n >= 0 ? rawNormals[n * 3 + 1] : 0, n >= 0 ? rawNormals[n * 3 + 2] : 0);
|
|
155
|
+
const material = materialName !== undefined ? materialsByName.get(materialName) : undefined;
|
|
156
|
+
const kd = material?.diffuseColor ?? [1, 1, 1];
|
|
157
|
+
colors.push(kd[0], kd[1], kd[2], material?.opacity ?? 1);
|
|
158
|
+
}
|
|
159
|
+
indices.push(vertex);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
163
|
+
const line = rawLine.trim();
|
|
164
|
+
if (line.length == 0 || line.startsWith("#")) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const parts = tokens(line);
|
|
168
|
+
|
|
169
|
+
switch (parts[0]) {
|
|
170
|
+
case "v":
|
|
171
|
+
rawPositions.push(parseFloat(parts[1]), parseFloat(parts[2]), parseFloat(parts[3]));
|
|
172
|
+
break;
|
|
173
|
+
case "vt":
|
|
174
|
+
rawTextureCoords.push(parseFloat(parts[1]), parts.length > 2 ? parseFloat(parts[2]) : 0);
|
|
175
|
+
break;
|
|
176
|
+
case "vn":
|
|
177
|
+
rawNormals.push(parseFloat(parts[1]), parseFloat(parts[2]), parseFloat(parts[3]));
|
|
178
|
+
break;
|
|
179
|
+
case "f": {
|
|
180
|
+
const corners = parts.slice(1).map(corner => {
|
|
181
|
+
const [p, t, n] = corner.split("/");
|
|
182
|
+
return [
|
|
183
|
+
resolve(p, rawPositions.length / 3),
|
|
184
|
+
resolve(t, rawTextureCoords.length / 2),
|
|
185
|
+
resolve(n, rawNormals.length / 3),
|
|
186
|
+
];
|
|
187
|
+
});
|
|
188
|
+
// Triangulate polygons as a fan.
|
|
189
|
+
for (let i = 1; i + 1 < corners.length; i++) {
|
|
190
|
+
addCorner(corners[0][0], corners[0][1], corners[0][2]);
|
|
191
|
+
addCorner(corners[i][0], corners[i][1], corners[i][2]);
|
|
192
|
+
addCorner(corners[i + 1][0], corners[i + 1][1], corners[i + 1][2]);
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case "mtllib":
|
|
197
|
+
materialLibraries.push(...parts.slice(1));
|
|
198
|
+
break;
|
|
199
|
+
case "usemtl":
|
|
200
|
+
closeRange();
|
|
201
|
+
materialName = line.substring(parts[0].length).trim();
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
closeRange();
|
|
206
|
+
|
|
207
|
+
if(positions.length == 0){
|
|
208
|
+
throw new Error("Invalid obj file.");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
geometry: {
|
|
213
|
+
positions, textureCoords, normals, colors, indices,
|
|
214
|
+
vertexCount: positions.length / 3,
|
|
215
|
+
materialRanges,
|
|
216
|
+
},
|
|
217
|
+
materials,
|
|
218
|
+
materialLibraries,
|
|
219
|
+
raw: {positions: rawPositions, textureCoords: rawTextureCoords, normals: rawNormals, faceIndices},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Loads an .obj file and the .mtl files it references with `mtllib`.
|
|
225
|
+
* A missing or failing .mtl is skipped (logged as a warning); the model still loads with white vertex colours.
|
|
226
|
+
* @param filePath The .obj URL.
|
|
227
|
+
* @param options Optional: how to resolve `mtllib` names, or skip materials.
|
|
228
|
+
* @returns The geometry, materials and raw data.
|
|
229
|
+
*/
|
|
230
|
+
public async loadAsync(filePath: string, options?: ObjLoadOptions): Promise<ObjLoadResult> {
|
|
231
|
+
const response = await fetch(filePath);
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
throw new Error(`Failed to load OBJ '${filePath}': ${response.status} ${response.statusText}`);
|
|
234
|
+
}
|
|
235
|
+
const text = await response.text();
|
|
236
|
+
|
|
237
|
+
const materials: ObjMaterialDefinition[] = [];
|
|
238
|
+
|
|
239
|
+
const libraries = options?.ignoreMaterials ? [] : text.split(/\r?\n/)
|
|
240
|
+
.map(line => tokens(line))
|
|
241
|
+
.filter(parts => parts[0] == "mtllib")
|
|
242
|
+
.flatMap(parts => parts.slice(1));
|
|
243
|
+
|
|
244
|
+
// data: and blob: URLs have no directory, so relative names cannot be resolved against them.
|
|
245
|
+
const opaqueUrl = /^(data|blob):/i.test(filePath);
|
|
246
|
+
for (const library of libraries) {
|
|
247
|
+
try {
|
|
248
|
+
let mtlUrl: string;
|
|
249
|
+
if (options?.resolveMaterialUrl) {
|
|
250
|
+
mtlUrl = options.resolveMaterialUrl(library);
|
|
251
|
+
} else if (opaqueUrl) {
|
|
252
|
+
throw new Error("the OBJ was loaded from a data: or blob: URL (e.g. a bundler-inlined asset), so the name cannot be resolved; pass options.resolveMaterialUrl");
|
|
253
|
+
} else {
|
|
254
|
+
mtlUrl = filePath.substring(0, filePath.lastIndexOf("/") + 1) + library;
|
|
255
|
+
}
|
|
256
|
+
const mtlResponse = await fetch(mtlUrl);
|
|
257
|
+
|
|
258
|
+
if (!mtlResponse.ok) {
|
|
259
|
+
throw new Error(`${mtlResponse.status} ${mtlResponse.statusText}`);
|
|
260
|
+
}
|
|
261
|
+
materials.push(...this.parseMtl(await mtlResponse.text()));
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.warn(`ObjLoader: could not load material library '${library}'.`, error);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
return this.fromText(text, materials);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Plain-data types produced by the OBJ loader.
|
|
3
|
+
* This folder is self-contained: files here import only each other, so it can move to its own package.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** An RGB colour as read from an .mtl file, each channel usually in 0..1. */
|
|
7
|
+
export type ObjColor = [r: number, g: number, b: number];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A material definition read from an .mtl file (`newmtl` block).
|
|
11
|
+
* This is plain data, not a GPU material; map it onto a framework material yourself.
|
|
12
|
+
*/
|
|
13
|
+
export class ObjMaterialDefinition {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The constructor.
|
|
17
|
+
* @param name The material name from `newmtl`.
|
|
18
|
+
*/
|
|
19
|
+
public constructor(public name: string) {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Ambient colour (`Ka`). */
|
|
23
|
+
public ambientColor?: ObjColor;
|
|
24
|
+
|
|
25
|
+
/** Diffuse colour (`Kd`). */
|
|
26
|
+
public diffuseColor?: ObjColor;
|
|
27
|
+
|
|
28
|
+
/** Specular colour (`Ks`). */
|
|
29
|
+
public specularColor?: ObjColor;
|
|
30
|
+
|
|
31
|
+
/** Emissive colour (`Ke`). */
|
|
32
|
+
public emissiveColor?: ObjColor;
|
|
33
|
+
|
|
34
|
+
/** Specular exponent (`Ns`). */
|
|
35
|
+
public specularExponent?: number;
|
|
36
|
+
|
|
37
|
+
/** Opacity, from `d`, or `1 - Tr` when only `Tr` is given. */
|
|
38
|
+
public opacity?: number;
|
|
39
|
+
|
|
40
|
+
/** Optical density / index of refraction (`Ni`). */
|
|
41
|
+
public opticalDensity?: number;
|
|
42
|
+
|
|
43
|
+
/** Illumination model (`illum`). */
|
|
44
|
+
public illuminationModel?: number;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Texture maps by statement name, e.g. `map_Kd`, `map_Ks`, `map_Bump`, `bump`, `disp`, `decal`, `refl`.
|
|
48
|
+
* The value is the file name (last token); map options such as `-bm 1` are kept in {@link mapOptions}.
|
|
49
|
+
*/
|
|
50
|
+
public maps: Record<string, string> = {};
|
|
51
|
+
|
|
52
|
+
/** Options written before the file name of a map statement, e.g. `{ map_Bump: "-bm 0.5" }`. */
|
|
53
|
+
public mapOptions: Record<string, string> = {};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A run of triangles in the geometry's index buffer drawn with one material (`usemtl`). */
|
|
57
|
+
export interface ObjMaterialRange {
|
|
58
|
+
/** The material name from `usemtl`, or undefined for faces before any `usemtl`. */
|
|
59
|
+
readonly materialName?: string;
|
|
60
|
+
/** First index in `geometry.indices`. */
|
|
61
|
+
readonly indexStart: number;
|
|
62
|
+
/** Number of indices (3 per triangle). */
|
|
63
|
+
readonly indexCount: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The OBJ data exactly as listed in the file, before expansion. */
|
|
67
|
+
export interface ObjRawData {
|
|
68
|
+
/** `v` values, 3 per position. */
|
|
69
|
+
readonly positions: number[];
|
|
70
|
+
/** `vt` values, 2 per texture coordinate (a third `w` value is dropped). */
|
|
71
|
+
readonly textureCoords: number[];
|
|
72
|
+
/** `vn` values, 3 per normal. */
|
|
73
|
+
readonly normals: number[];
|
|
74
|
+
/**
|
|
75
|
+
* Triangulated face corners as zero-based `position, texcoord, normal` triplets.
|
|
76
|
+
* A missing texcoord or normal is -1.
|
|
77
|
+
*/
|
|
78
|
+
readonly faceIndices: number[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Renderable geometry as plain data: one vertex per unique position/texcoord/normal/material corner.
|
|
83
|
+
* Has no dependency on any engine; convert it to engine geometry yourself.
|
|
84
|
+
*/
|
|
85
|
+
export interface ObjGeometryDefinition {
|
|
86
|
+
/** Positions, 3 per vertex. */
|
|
87
|
+
readonly positions: number[];
|
|
88
|
+
/** Texture coordinates, 2 per vertex (0,0 when the corner has none). */
|
|
89
|
+
readonly textureCoords: number[];
|
|
90
|
+
/** Normals, 3 per vertex (0,0,0 when the corner has none). */
|
|
91
|
+
readonly normals: number[];
|
|
92
|
+
/** RGBA colours, 4 per vertex: the material's `Kd` with alpha from `d`, white without a material. */
|
|
93
|
+
readonly colors: number[];
|
|
94
|
+
/** Triangle indices, 3 per triangle. */
|
|
95
|
+
readonly indices: number[];
|
|
96
|
+
/** Number of vertices (`positions.length / 3`). */
|
|
97
|
+
readonly vertexCount: number;
|
|
98
|
+
/** Index ranges per `usemtl`, in file order. */
|
|
99
|
+
readonly materialRanges: ObjMaterialRange[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The result of loading an OBJ file. */
|
|
103
|
+
export interface ObjLoadResult {
|
|
104
|
+
/** The renderable geometry as plain data. */
|
|
105
|
+
readonly geometry: ObjGeometryDefinition;
|
|
106
|
+
/** Material definitions from the referenced .mtl files. Empty when there is no `mtllib` or it could not be loaded. */
|
|
107
|
+
readonly materials: ObjMaterialDefinition[];
|
|
108
|
+
/** Library file names from `mtllib`, in order. */
|
|
109
|
+
readonly materialLibraries: string[];
|
|
110
|
+
/** The raw OBJ lists. */
|
|
111
|
+
readonly raw: ObjRawData;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Options for {@link ObjLoader.loadAsync}. */
|
|
115
|
+
export interface ObjLoadOptions {
|
|
116
|
+
/**
|
|
117
|
+
* Maps an `mtllib` name to the URL to fetch.
|
|
118
|
+
* By default, the name is resolved relative to the OBJ URL, which fails for `data:` or `blob:` URLs
|
|
119
|
+
* (for example a bundler-inlined asset); use this to point at the real file.
|
|
120
|
+
*/
|
|
121
|
+
resolveMaterialUrl?: (libraryName: string) => string;
|
|
122
|
+
/** Skip fetching .mtl files. */
|
|
123
|
+
ignoreMaterials?: boolean;
|
|
124
|
+
}
|