|
@@ -30,6 +30,8 @@
|
|
|
|
|
|
import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';
|
|
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
|
+ import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
|
|
|
+ import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
|
|
|
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
|
|
|
|
|
function exportGLTF( input ) {
|
|
@@ -99,7 +101,7 @@
|
|
|
let container;
|
|
|
|
|
|
let camera, object, object2, material, geometry, scene1, scene2, renderer;
|
|
|
- let gridHelper, sphere, model;
|
|
|
+ let gridHelper, sphere, model, coffeemat;
|
|
|
|
|
|
const params = {
|
|
|
trs: false,
|
|
@@ -111,7 +113,8 @@
|
|
|
exportSphere: exportSphere,
|
|
|
exportModel: exportModel,
|
|
|
exportObjects: exportObjects,
|
|
|
- exportSceneObject: exportSceneObject
|
|
|
+ exportSceneObject: exportSceneObject,
|
|
|
+ exportCompressedObject: exportCompressedObject,
|
|
|
};
|
|
|
|
|
|
init();
|
|
@@ -451,6 +454,29 @@
|
|
|
|
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
|
|
|
|
+ // ---------------------------------------------------------------------
|
|
|
+ // Exporting compressed textures and meshes (KTX2 / Draco / Meshopt)
|
|
|
+ // ---------------------------------------------------------------------
|
|
|
+ const ktx2Loader = new KTX2Loader()
|
|
|
+ .setTranscoderPath( 'jsm/libs/basis/' )
|
|
|
+ .detectSupport( renderer );
|
|
|
+
|
|
|
+ const gltfLoader = new GLTFLoader().setPath( 'models/gltf/' );
|
|
|
+ gltfLoader.setKTX2Loader( ktx2Loader );
|
|
|
+ gltfLoader.setMeshoptDecoder( MeshoptDecoder );
|
|
|
+ gltfLoader.load( 'coffeemat.glb', function ( gltf ) {
|
|
|
+
|
|
|
+ gltf.scene.position.x = 400;
|
|
|
+ gltf.scene.position.z = - 200;
|
|
|
+
|
|
|
+ scene1.add( gltf.scene );
|
|
|
+
|
|
|
+ coffeemat = gltf.scene;
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
const gui = new GUI();
|
|
|
|
|
|
let h = gui.addFolder( 'Settings' );
|
|
@@ -466,6 +492,7 @@
|
|
|
h.add( params, 'exportModel' ).name( 'Export Model' );
|
|
|
h.add( params, 'exportObjects' ).name( 'Export Sphere With Grid' );
|
|
|
h.add( params, 'exportSceneObject' ).name( 'Export Scene 1 and Object' );
|
|
|
+ h.add( params, 'exportCompressedObject' ).name( 'Export Coffeemat (from compressed data)' );
|
|
|
|
|
|
gui.open();
|
|
|
|
|
@@ -507,6 +534,12 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function exportCompressedObject() {
|
|
|
+
|
|
|
+ exportGLTF( [ coffeemat ] );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
function onWindowResize() {
|
|
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|