Skip to content

Add THREE.CompressedCubeTexture #26369

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

Merged
merged 1 commit into from
Jul 5, 2023
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
6 changes: 2 additions & 4 deletions examples/jsm/loaders/KTX2Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import {
CompressedTexture,
CompressedArrayTexture,
CompressedCubeTexture,
Data3DTexture,
DataTexture,
FileLoader,
Expand Down Expand Up @@ -261,10 +262,7 @@ class KTX2Loader extends Loader {

if ( container.faceCount === 6 ) {

texture = new CompressedTexture();
texture.image = faces;
texture.format = format;
texture.type = UnsignedByteType;
texture = new CompressedCubeTexture( faces, format, UnsignedByteType );

} else {

Expand Down
1 change: 1 addition & 0 deletions src/Three.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export { DataArrayTexture } from './textures/DataArrayTexture.js';
export { Data3DTexture } from './textures/Data3DTexture.js';
export { CompressedTexture } from './textures/CompressedTexture.js';
export { CompressedArrayTexture } from './textures/CompressedArrayTexture.js';
export { CompressedCubeTexture } from './textures/CompressedCubeTexture.js';
export { CubeTexture } from './textures/CubeTexture.js';
export { CanvasTexture } from './textures/CanvasTexture.js';
export { DepthTexture } from './textures/DepthTexture.js';
Expand Down
19 changes: 19 additions & 0 deletions src/textures/CompressedCubeTexture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { CubeReflectionMapping } from '../constants.js';
import { CompressedTexture } from './CompressedTexture.js';

class CompressedCubeTexture extends CompressedTexture {

constructor( images, format, type ) {

super( undefined, images[ 0 ].width, images[ 0 ].height, format, type, CubeReflectionMapping );
Copy link
Contributor

@Methuselah96 Methuselah96 Dec 5, 2023

Choose a reason for hiding this comment

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

@donmccurdy Would it work to pass in [] for mipmaps instead of undefined? I'm working on the types for this. If taken strictly, Texture.mipmaps and CompressedTexture.mipmaps would now need to be ImageData[] | undefined instead of ImageData[], which is more disruptive of a change for the users of the types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe it's correct that the .mipmaps property is a non-nullable array, but not safe to pass an empty array up to the constructor here... I would just assume that mipmaps gets populated correctly during texture initialization, and not make the property nullable in the TS definitions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, thanks, good to know. For my own education, where do the mipmaps end up getting set for the CompressedCubeTexture in KTX2Loader?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see mipmaps getting set for other textures in createRawTexture, but don't do something similar in _createTextureFrom where CompressedCubeTexture is used.

Copy link
Collaborator Author

@donmccurdy donmccurdy Dec 5, 2023

Choose a reason for hiding this comment

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

You can see where it would be set in #26642, but I can't promise that KTX2Loader sets up all texture types correctly today. Constructing compressed array, cube, and 3D textures is not a fully-documented API, and we don't have many test cases for it, so I'm kind of trial-and-erroring my through this part. Maybe once #26642 is working we'll have a better idea how to construct textures for each of these cases...


this.isCompressedCubeTexture = true;
this.isCubeTexture = true;

this.image = images;

}

}

export { CompressedCubeTexture };