mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-14 15:35:57 +10:00
191 lines
5.1 KiB
HTML
Executable File
191 lines
5.1 KiB
HTML
Executable File
<!DOCTYPE HTML>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js - geometry - c4d mesh</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
|
|
<style type="text/css">
|
|
body {
|
|
font-family: Monospace;
|
|
background-color: #f0f0f0;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<script type="text/javascript" src="../build/Three.js"></script>
|
|
<script type="text/javascript" src="geometry/DodecaEdges.js"></script>
|
|
<script type="text/javascript" src="js/Stats.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
//*
|
|
var SCREEN_WIDTH = window.innerWidth;
|
|
var SCREEN_HEIGHT = window.innerHeight;
|
|
|
|
var container;
|
|
var stats;
|
|
|
|
var camera;
|
|
var scene;
|
|
var renderer;
|
|
|
|
var model,model2,model3,material;
|
|
|
|
var targetRotation = 0;
|
|
var targetRotationOnMouseDown = 0;
|
|
|
|
var mouseX = 0;
|
|
var mouseXOnMouseDown = 0;
|
|
|
|
var windowHalfX = window.innerWidth / 2;
|
|
var windowHalfY = window.innerHeight / 2;
|
|
|
|
init();
|
|
setInterval(loop, 1000/60);
|
|
|
|
function init() {
|
|
|
|
container = document.createElement('div');
|
|
document.body.appendChild(container);
|
|
|
|
var info = document.createElement('div');
|
|
info.style.position = 'absolute';
|
|
info.style.top = '10px';
|
|
info.style.width = '100%';
|
|
info.style.textAlign = 'center';
|
|
info.innerHTML = 'Drag to spin dodecahedrons';
|
|
container.appendChild(info);
|
|
|
|
camera = new THREE.Camera( 70, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
|
|
camera.position.y = 350;
|
|
camera.position.z = 750;
|
|
camera.target.position.y = 150;
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
//model
|
|
var geometry = new DodecaEdges();
|
|
for (var i = 0; i < geometry.faces.length; i++) geometry.faces[i].material = [ new THREE.MeshBasicMaterial( {color:Math.random() * 0xffffff} ) ];
|
|
model = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial());
|
|
var s = 3;
|
|
model.scale = new THREE.Vector3(s,s,s);
|
|
|
|
|
|
model2 = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial());
|
|
model2.rotation.x = Math.PI;
|
|
model2.scale = new THREE.Vector3(s*1.610833,s*1.610833,s*1.610833);
|
|
model3 = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial());
|
|
model3.scale = new THREE.Vector3(s*3.2216,s*3.2216,s*3.2216);
|
|
|
|
|
|
|
|
scene.addObject(model3);
|
|
scene.addObject(model2);
|
|
scene.addObject(model);
|
|
|
|
renderer = new THREE.CanvasRenderer();
|
|
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
|
|
container.appendChild( renderer.domElement );
|
|
|
|
stats = new Stats();
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.top = '0px';
|
|
container.appendChild( stats.domElement );
|
|
|
|
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
|
|
document.addEventListener( 'touchstart', onDocumentTouchStart, false );
|
|
document.addEventListener( 'touchmove', onDocumentTouchMove, false );
|
|
}
|
|
|
|
//
|
|
|
|
function onDocumentMouseDown( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
document.addEventListener( 'mouseup', onDocumentMouseUp, false );
|
|
document.addEventListener( 'mouseout', onDocumentMouseOut, false );
|
|
|
|
mouseXOnMouseDown = event.clientX - windowHalfX;
|
|
targetRotationOnMouseDown = targetRotation;
|
|
}
|
|
|
|
function onDocumentMouseMove( event ) {
|
|
|
|
mouseX = event.clientX - windowHalfX;
|
|
|
|
targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.02;
|
|
}
|
|
|
|
function onDocumentMouseUp( event ) {
|
|
|
|
document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
|
|
document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
|
|
}
|
|
|
|
function onDocumentMouseOut( event ) {
|
|
|
|
document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
|
|
document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
|
|
}
|
|
|
|
function onDocumentTouchStart( event ) {
|
|
|
|
if ( event.touches.length == 1 ) {
|
|
|
|
event.preventDefault();
|
|
|
|
mouseXOnMouseDown = event.touches[ 0 ].pageX - windowHalfX;
|
|
targetRotationOnMouseDown = targetRotation;
|
|
|
|
}
|
|
}
|
|
|
|
function onDocumentTouchMove( event ) {
|
|
|
|
if ( event.touches.length == 1 ) {
|
|
|
|
event.preventDefault();
|
|
|
|
mouseX = event.touches[ 0 ].pageX - windowHalfX;
|
|
targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05;
|
|
|
|
}
|
|
}
|
|
|
|
//
|
|
|
|
function loop() {
|
|
|
|
model3.rotation.y = model2.rotation.y = model.rotation.y += ( targetRotation - model.rotation.y ) * 0.05;
|
|
|
|
renderer.render(scene, camera);
|
|
stats.update();
|
|
}
|
|
function initBitmapMaterial(url) {
|
|
|
|
texture = document.createElement( 'canvas' );
|
|
texture.width = 128;
|
|
texture.height = 128;
|
|
|
|
material = new THREE.MeshBitmapMaterial( texture );
|
|
|
|
var temp = new Image();
|
|
temp.onload = function () {
|
|
material.bitmap = this;
|
|
renderer.render(scene, camera);
|
|
};
|
|
temp.src = url;
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|