|
@@ -4,12 +4,12 @@ import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
|
|
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
|
|
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
|
|
import { TGALoader } from 'three/addons/loaders/TGALoader.js';
|
|
import { TGALoader } from 'three/addons/loaders/TGALoader.js';
|
|
|
|
|
|
-import { UIElement, UISpan, UIDiv, UIRow, UIButton, UICheckbox, UIText, UINumber } from './ui.js';
|
|
|
|
|
|
+import { UISpan, UIDiv, UIRow, UIButton, UICheckbox, UIText, UINumber } from './ui.js';
|
|
import { MoveObjectCommand } from '../commands/MoveObjectCommand.js';
|
|
import { MoveObjectCommand } from '../commands/MoveObjectCommand.js';
|
|
|
|
|
|
class UITexture extends UISpan {
|
|
class UITexture extends UISpan {
|
|
|
|
|
|
- constructor( mapping ) {
|
|
|
|
|
|
+ constructor( editor ) {
|
|
|
|
|
|
super();
|
|
super();
|
|
|
|
|
|
@@ -100,10 +100,9 @@ class UITexture extends UISpan {
|
|
|
|
|
|
const arrayBuffer = event.target.result;
|
|
const arrayBuffer = event.target.result;
|
|
const blobURL = URL.createObjectURL( new Blob( [ arrayBuffer ] ) );
|
|
const blobURL = URL.createObjectURL( new Blob( [ arrayBuffer ] ) );
|
|
- const tempRenderer = new THREE.WebGLRenderer();
|
|
|
|
const ktx2Loader = new KTX2Loader();
|
|
const ktx2Loader = new KTX2Loader();
|
|
ktx2Loader.setTranscoderPath( '../../examples/jsm/libs/basis/' );
|
|
ktx2Loader.setTranscoderPath( '../../examples/jsm/libs/basis/' );
|
|
- ktx2Loader.detectSupport( tempRenderer );
|
|
|
|
|
|
+ editor.signals.rendererDetectKTX2Support.dispatch( ktx2Loader );
|
|
|
|
|
|
ktx2Loader.load( blobURL, function ( texture ) {
|
|
ktx2Loader.load( blobURL, function ( texture ) {
|
|
|
|
|
|
@@ -114,7 +113,6 @@ class UITexture extends UISpan {
|
|
|
|
|
|
if ( scope.onChangeCallback ) scope.onChangeCallback( texture );
|
|
if ( scope.onChangeCallback ) scope.onChangeCallback( texture );
|
|
ktx2Loader.dispose();
|
|
ktx2Loader.dispose();
|
|
- tempRenderer.dispose();
|
|
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
@@ -129,7 +127,7 @@ class UITexture extends UISpan {
|
|
const image = document.createElement( 'img' );
|
|
const image = document.createElement( 'img' );
|
|
image.addEventListener( 'load', function () {
|
|
image.addEventListener( 'load', function () {
|
|
|
|
|
|
- const texture = new THREE.Texture( this, mapping );
|
|
|
|
|
|
+ const texture = new THREE.Texture( this );
|
|
texture.sourceFile = file.name;
|
|
texture.sourceFile = file.name;
|
|
texture.needsUpdate = true;
|
|
texture.needsUpdate = true;
|
|
|
|
|
|
@@ -235,145 +233,6 @@ class UITexture extends UISpan {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-class UICubeTexture extends UIElement {
|
|
|
|
-
|
|
|
|
- constructor() {
|
|
|
|
-
|
|
|
|
- const container = new UIDiv();
|
|
|
|
-
|
|
|
|
- super( container.dom );
|
|
|
|
-
|
|
|
|
- this.cubeTexture = null;
|
|
|
|
- this.onChangeCallback = null;
|
|
|
|
-
|
|
|
|
- this.textures = [];
|
|
|
|
-
|
|
|
|
- const scope = this;
|
|
|
|
-
|
|
|
|
- const pRow = new UIRow();
|
|
|
|
- const nRow = new UIRow();
|
|
|
|
-
|
|
|
|
- pRow.add( new UIText( 'P:' ).setWidth( '35px' ) );
|
|
|
|
- nRow.add( new UIText( 'N:' ).setWidth( '35px' ) );
|
|
|
|
-
|
|
|
|
- const posXTexture = new UITexture().onChange( onTextureChanged );
|
|
|
|
- const negXTexture = new UITexture().onChange( onTextureChanged );
|
|
|
|
- const posYTexture = new UITexture().onChange( onTextureChanged );
|
|
|
|
- const negYTexture = new UITexture().onChange( onTextureChanged );
|
|
|
|
- const posZTexture = new UITexture().onChange( onTextureChanged );
|
|
|
|
- const negZTexture = new UITexture().onChange( onTextureChanged );
|
|
|
|
-
|
|
|
|
- this.textures.push( posXTexture, negXTexture, posYTexture, negYTexture, posZTexture, negZTexture );
|
|
|
|
-
|
|
|
|
- pRow.add( posXTexture );
|
|
|
|
- pRow.add( posYTexture );
|
|
|
|
- pRow.add( posZTexture );
|
|
|
|
-
|
|
|
|
- nRow.add( negXTexture );
|
|
|
|
- nRow.add( negYTexture );
|
|
|
|
- nRow.add( negZTexture );
|
|
|
|
-
|
|
|
|
- container.add( pRow, nRow );
|
|
|
|
-
|
|
|
|
- function onTextureChanged() {
|
|
|
|
-
|
|
|
|
- const images = [];
|
|
|
|
-
|
|
|
|
- for ( let i = 0; i < scope.textures.length; i ++ ) {
|
|
|
|
-
|
|
|
|
- const texture = scope.textures[ i ].getValue();
|
|
|
|
-
|
|
|
|
- if ( texture !== null ) {
|
|
|
|
-
|
|
|
|
- images.push( texture.isHDRTexture ? texture : texture.image );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ( images.length === 6 ) {
|
|
|
|
-
|
|
|
|
- const cubeTexture = new THREE.CubeTexture( images );
|
|
|
|
- cubeTexture.needsUpdate = true;
|
|
|
|
-
|
|
|
|
- if ( images[ 0 ].isHDRTexture ) cubeTexture.isHDRTexture = true;
|
|
|
|
-
|
|
|
|
- scope.cubeTexture = cubeTexture;
|
|
|
|
-
|
|
|
|
- if ( scope.onChangeCallback ) scope.onChangeCallback( cubeTexture );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- setColorSpace( colorSpace ) {
|
|
|
|
-
|
|
|
|
- const cubeTexture = this.getValue();
|
|
|
|
- if ( cubeTexture !== null ) {
|
|
|
|
-
|
|
|
|
- cubeTexture.colorSpace = colorSpace;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return this;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- getValue() {
|
|
|
|
-
|
|
|
|
- return this.cubeTexture;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- setValue( cubeTexture ) {
|
|
|
|
-
|
|
|
|
- this.cubeTexture = cubeTexture;
|
|
|
|
-
|
|
|
|
- if ( cubeTexture !== null ) {
|
|
|
|
-
|
|
|
|
- const images = cubeTexture.image;
|
|
|
|
-
|
|
|
|
- if ( Array.isArray( images ) === true && images.length === 6 ) {
|
|
|
|
-
|
|
|
|
- for ( let i = 0; i < images.length; i ++ ) {
|
|
|
|
-
|
|
|
|
- const image = images[ i ];
|
|
|
|
-
|
|
|
|
- const texture = new THREE.Texture( image );
|
|
|
|
- this.textures[ i ].setValue( texture );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- const textures = this.textures;
|
|
|
|
-
|
|
|
|
- for ( let i = 0; i < textures.length; i ++ ) {
|
|
|
|
-
|
|
|
|
- textures[ i ].setValue( null );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return this;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- onChange( callback ) {
|
|
|
|
-
|
|
|
|
- this.onChangeCallback = callback;
|
|
|
|
-
|
|
|
|
- return this;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
class UIOutliner extends UIDiv {
|
|
class UIOutliner extends UIDiv {
|
|
|
|
|
|
constructor( editor ) {
|
|
constructor( editor ) {
|
|
@@ -980,4 +839,4 @@ function renderToCanvas( texture ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-export { UITexture, UICubeTexture, UIOutliner, UIPoints, UIPoints2, UIPoints3, UIBoolean };
|
|
|
|
|
|
+export { UITexture, UIOutliner, UIPoints, UIPoints2, UIPoints3, UIBoolean };
|