You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
earthquake_3d_viewer_front/three/examples/webgl_morphtargets_sphere.html

152 lines
3.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - morph targets - sphere</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="container"></div>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - WebGL morph target example
</div>
<script type="importmap">
{
"imports": {
"three": "../build/three.module.js",
"three/addons/": "./jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { Timer } from 'three/addons/misc/Timer.js';
let camera, scene, renderer, timer;
let mesh;
let sign = 1;
const speed = 0.5;
init();
function init() {
const container = document.getElementById( 'container' );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.2, 100 );
camera.position.set( 0, 5, 5 );
scene = new THREE.Scene();
timer = new Timer();
timer.connect( document );
const light1 = new THREE.PointLight( 0xff2200, 50000 );
light1.position.set( 100, 100, 100 );
scene.add( light1 );
const light2 = new THREE.PointLight( 0x22ff00, 10000 );
light2.position.set( - 100, - 100, - 100 );
scene.add( light2 );
scene.add( new THREE.AmbientLight( 0x111111 ) );
const loader = new GLTFLoader();
loader.load( 'models/gltf/AnimatedMorphSphere/glTF/AnimatedMorphSphere.gltf', function ( gltf ) {
mesh = gltf.scene.getObjectByName( 'AnimatedMorphSphere' );
mesh.rotation.z = Math.PI / 2;
scene.add( mesh );
//
const pointsMaterial = new THREE.PointsMaterial( {
size: 10,
sizeAttenuation: false,
map: new THREE.TextureLoader().load( 'textures/sprites/disc.png' ),
alphaTest: 0.5
} );
const points = new THREE.Points( mesh.geometry, pointsMaterial );
points.morphTargetInfluences = mesh.morphTargetInfluences;
points.morphTargetDictionary = mesh.morphTargetDictionary;
mesh.add( points );
} );
//
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
container.appendChild( renderer.domElement );
//
const controls = new OrbitControls( camera, renderer.domElement );
controls.minDistance = 1;
controls.maxDistance = 20;
//
window.addEventListener( 'resize', onWindowResize );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
timer.update();
render();
}
function render() {
const delta = timer.getDelta();
if ( mesh !== undefined ) {
const step = delta * speed;
mesh.rotation.y += step;
mesh.morphTargetInfluences[ 1 ] = mesh.morphTargetInfluences[ 1 ] + step * sign;
if ( mesh.morphTargetInfluences[ 1 ] <= 0 || mesh.morphTargetInfluences[ 1 ] >= 1 ) {
sign *= - 1;
}
}
renderer.render( scene, camera );
}
</script>
</body>
</html>