Browse Source

Add TIFFLoader. (#24420)

Michael Herzog 3 years ago
parent
commit
3bc0667e51

+ 1 - 0
examples/files.json

@@ -120,6 +120,7 @@
 		"webgl_loader_texture_pvrtc",
 		"webgl_loader_texture_rgbm",
 		"webgl_loader_texture_tga",
+		"webgl_loader_texture_tiff",
 		"webgl_loader_ttf",
 		"webgl_loader_vox",
 		"webgl_loader_vrml",

File diff suppressed because it is too large
+ 430 - 0
examples/jsm/libs/utif.module.js


+ 36 - 0
examples/jsm/loaders/TIFFLoader.js

@@ -0,0 +1,36 @@
+import {
+	DataTextureLoader,
+	LinearFilter,
+	LinearMipmapLinearFilter
+} from 'three';
+
+import UTIF from '../libs/utif.module.js';
+
+class TIFFLoader extends DataTextureLoader {
+
+	constructor( manager ) {
+
+		super( manager );
+
+	}
+
+	parse( buffer ) {
+
+		const ifds = UTIF.decode( buffer );
+		UTIF.decodeImage( buffer, ifds[ 0 ] );
+		const rgba = UTIF.toRGBA8( ifds[ 0 ] );
+
+		return {
+			width: ifds[ 0 ].width,
+			height: ifds[ 0 ].height,
+			data: rgba,
+			flipY: true,
+			magFilter: LinearFilter,
+			minFilter: LinearMipmapLinearFilter
+		};
+
+	}
+
+}
+
+export { TIFFLoader };

BIN
examples/screenshots/webgl_loader_texture_tiff.jpg


BIN
examples/textures/tiff/crate_jpeg.tif


BIN
examples/textures/tiff/crate_lzw.tif


BIN
examples/textures/tiff/crate_uncompressed.tif


+ 125 - 0
examples/webgl_loader_texture_tiff.html

@@ -0,0 +1,125 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>three.js webgl - materials - TIFF texture</title>
+		<meta charset="UTF-8">
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+		<link type="text/css" rel="stylesheet" href="main.css">
+	</head>
+	<body>
+		<div id="info">
+			<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - TIFF texture loader</a>
+		</div>
+
+		<!-- Import maps polyfill -->
+		<!-- Remove this when import maps will be widely supported -->
+		<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
+
+		<script type="importmap">
+			{
+				"imports": {
+					"three": "../build/three.module.js"
+				}
+			}
+		</script>
+
+		<script type="module">
+
+			import * as THREE from 'three';
+
+			import { TIFFLoader } from './jsm/loaders/TIFFLoader.js';
+
+			let renderer, scene, camera;
+
+			init();
+
+			function init() {
+
+				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.01, 10 );
+				camera.position.set( 0, 0, 4 );
+
+				renderer = new THREE.WebGLRenderer( { antialias: true } );
+				renderer.setPixelRatio( window.devicePixelRatio );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+				document.body.appendChild( renderer.domElement );
+
+				scene = new THREE.Scene();
+
+				const loader = new TIFFLoader();
+
+				const geometry = new THREE.PlaneGeometry();
+
+				// uncompressed
+
+				loader.load( 'textures/tiff/crate_uncompressed.tif', function ( texture ) {
+
+					const material = new THREE.MeshBasicMaterial( { map: texture } );
+
+					const mesh = new THREE.Mesh( geometry, material );
+					mesh.position.set( - 1.5, 0, 0 );
+
+					scene.add( mesh );
+
+					render();
+
+				} );
+
+				// LZW
+
+				loader.load( 'textures/tiff/crate_lzw.tif', function ( texture ) {
+
+					const material = new THREE.MeshBasicMaterial( { map: texture } );
+
+					const mesh = new THREE.Mesh( geometry, material );
+					mesh.position.set( 0, 0, 0 );
+
+					scene.add( mesh );
+
+					render();
+
+				} );
+
+				// JPEG
+
+				loader.load( 'textures/tiff/crate_jpeg.tif', function ( texture ) {
+
+					const material = new THREE.MeshBasicMaterial( { map: texture } );
+
+					const mesh = new THREE.Mesh( geometry, material );
+					mesh.position.set( 1.5, 0, 0 );
+
+					scene.add( mesh );
+
+					render();
+
+				} );
+
+				//
+
+				window.addEventListener( 'resize', onWindowResize );
+
+			}
+
+			function onWindowResize() {
+
+				camera.aspect = window.innerWidth / window.innerHeight;
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				render();
+
+			}
+
+
+			//
+
+			function render() {
+
+				renderer.render( scene, camera );
+
+			}
+
+		</script>
+	</body>
+</html>

Some files were not shown because too many files changed in this diff