Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strongly type Texture.mipmaps #1025

Merged
merged 6 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8121,7 +8121,7 @@ index 8c025071..a47c4832 100644
mouseY = (event.clientY - windowHalfY) * 4;
}
diff --git a/examples-testing/examples/webgl_materials_cubemap_render_to_mipmaps.ts b/examples-testing/examples/webgl_materials_cubemap_render_to_mipmaps.ts
index 599a1369..fa4f85c1 100644
index 599a1369..a23a0582 100644
--- a/examples-testing/examples/webgl_materials_cubemap_render_to_mipmaps.ts
+++ b/examples-testing/examples/webgl_materials_cubemap_render_to_mipmaps.ts
@@ -1,8 +1,8 @@
Expand Down Expand Up @@ -8154,7 +8154,14 @@ index 599a1369..fa4f85c1 100644
const params = {
magFilter: THREE.LinearFilter,
minFilter: THREE.LinearMipMapLinearFilter,
@@ -83,7 +83,7 @@ function allocateCubemapRenderTarget(cubeMapSize) {
@@ -77,13 +77,13 @@ function allocateCubemapRenderTarget(cubeMapSize) {
const rt = new THREE.WebGLCubeRenderTarget(cubeMapSize, params);

const mipLevels = Math.log(cubeMapSize) * Math.LOG2E + 1.0;
- for (let i = 0; i < mipLevels; i++) rt.texture.mipmaps.push({});
+ for (let i = 0; i < mipLevels; i++) (rt.texture.mipmaps as THREE.CubeTexture[]).push({} as THREE.CubeTexture);

rt.texture.mapping = THREE.CubeReflectionMapping;
return rt;
}

Expand Down Expand Up @@ -8732,7 +8739,7 @@ index 178c2ce4..fb67cabe 100644
mouseY = event.clientY - windowHalfY;
}
diff --git a/examples-testing/examples/webgl_materials_texture_manualmipmap.ts b/examples-testing/examples/webgl_materials_texture_manualmipmap.ts
index 24bd4eb9..5d5e77b6 100644
index 24bd4eb9..2dad75e8 100644
--- a/examples-testing/examples/webgl_materials_texture_manualmipmap.ts
+++ b/examples-testing/examples/webgl_materials_texture_manualmipmap.ts
@@ -3,9 +3,9 @@ import * as THREE from 'three';
Expand All @@ -8759,6 +8766,29 @@ index 24bd4eb9..5d5e77b6 100644

imageCanvas.width = imageCanvas.height = size;

@@ -49,14 +49,14 @@ function init() {

const canvas = mipmap(128, '#f00');
const textureCanvas1 = new THREE.CanvasTexture(canvas);
- textureCanvas1.mipmaps[0] = canvas;
- textureCanvas1.mipmaps[1] = mipmap(64, '#0f0');
- textureCanvas1.mipmaps[2] = mipmap(32, '#00f');
- textureCanvas1.mipmaps[3] = mipmap(16, '#400');
- textureCanvas1.mipmaps[4] = mipmap(8, '#040');
- textureCanvas1.mipmaps[5] = mipmap(4, '#004');
- textureCanvas1.mipmaps[6] = mipmap(2, '#044');
- textureCanvas1.mipmaps[7] = mipmap(1, '#404');
+ textureCanvas1.mipmaps![0] = canvas;
+ textureCanvas1.mipmaps![1] = mipmap(64, '#0f0');
+ textureCanvas1.mipmaps![2] = mipmap(32, '#00f');
+ textureCanvas1.mipmaps![3] = mipmap(16, '#400');
+ textureCanvas1.mipmaps![4] = mipmap(8, '#040');
+ textureCanvas1.mipmaps![5] = mipmap(4, '#004');
+ textureCanvas1.mipmaps![6] = mipmap(2, '#044');
+ textureCanvas1.mipmaps![7] = mipmap(1, '#404');
textureCanvas1.colorSpace = THREE.SRGBColorSpace;
textureCanvas1.repeat.set(1000, 1000);
textureCanvas1.wrapS = THREE.RepeatWrapping;
@@ -97,7 +97,7 @@ function init() {
addPainting(scene1, mesh1);
addPainting(scene2, mesh2);
Expand Down
10 changes: 8 additions & 2 deletions types/three/examples/jsm/loaders/DDSLoader.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { CompressedPixelFormat, CompressedTextureLoader, LoadingManager, PixelFormat } from "three";
import {
CompressedPixelFormat,
CompressedTextureLoader,
CompressedTextureMipmap,
LoadingManager,
PixelFormat,
} from "three";

export interface DDS {
mipmaps: object[];
mipmaps: CompressedTextureMipmap[];
width: number;
height: number;
format: PixelFormat | CompressedPixelFormat;
Expand Down
10 changes: 8 additions & 2 deletions types/three/examples/jsm/loaders/KTXLoader.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { CompressedPixelFormat, CompressedTextureLoader, LoadingManager, PixelFormat } from "three";
import {
CompressedPixelFormat,
CompressedTextureLoader,
CompressedTextureMipmap,
LoadingManager,
PixelFormat,
} from "three";

export interface KTX {
mipmaps: object[];
mipmaps: CompressedTextureMipmap[];
width: number;
height: number;
format: PixelFormat | CompressedPixelFormat;
Expand Down
4 changes: 2 additions & 2 deletions types/three/examples/jsm/loaders/PVRLoader.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CompressedPixelFormat, CompressedTextureLoader, LoadingManager } from "three";
import { CompressedPixelFormat, CompressedTextureLoader, CompressedTextureMipmap, LoadingManager } from "three";

export interface PVR {
mipmaps: object[];
mipmaps: CompressedTextureMipmap[];
width: number;
height: number;
format: CompressedPixelFormat;
Expand Down
10 changes: 5 additions & 5 deletions types/three/src/textures/CompressedTexture.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export class CompressedTexture extends Texture {
* @param colorSpace See {@link Texture.colorSpace .colorSpace}. Default {@link NoColorSpace}
*/
constructor(
mipmaps: CompressedTextureMipmap[],
width: number,
height: number,
format: CompressedPixelFormat,
mipmaps?: CompressedTextureMipmap[],
width?: number,
height?: number,
format?: CompressedPixelFormat,
type?: TextureDataType,
mapping?: Mapping,
wrapS?: Wrapping,
Expand Down Expand Up @@ -72,7 +72,7 @@ export class CompressedTexture extends Texture {
* The mipmaps array should contain objects with data, width and height. The mipmaps should be of the correct
* format and type.
*/
mipmaps: CompressedTextureMipmap[];
mipmaps: CompressedTextureMipmap[] | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CompressedCubeTexture sets it to undefined here. 😢

Copy link
Contributor

@HunterLarco HunterLarco Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is deeply unfortunate 😢 but nice catch!


/**
* @override
Expand Down
4 changes: 3 additions & 1 deletion types/three/src/textures/Texture.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import { EventDispatcher } from "../core/EventDispatcher.js";
import { Matrix3 } from "../math/Matrix3.js";
import { Vector2 } from "../math/Vector2.js";
import { CompressedTextureMipmap } from "./CompressedTexture.js";
import { CubeTexture } from "./CubeTexture.js";
import { Source } from "./Source.js";

/** Shim for OffscreenCanvas. */
Expand Down Expand Up @@ -127,7 +129,7 @@ export class Texture extends EventDispatcher<{ dispose: {} }> {
* Array of user-specified mipmaps
* @defaultValue `[]`
*/
mipmaps: any[]; // CompressedTextureMipmap[] for 2D textures and CubeTexture[] for cube textures;
mipmaps: CompressedTextureMipmap[] | CubeTexture[] | HTMLCanvasElement[] | undefined;

/**
* How the image is applied to the object.
Expand Down
Loading