github link: https://github.com/hpstream/n.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
html,
body {
margin: 0;
height: 100%;
}
canvas {
display: block;
}
</style>
</head>
<body onload="draw();">
</body>
<script src="https://johnson2heng.github.io/three.js-demo/lib/three.js"></script>
<script src="./ColladaLoader.js"></script>
<script src="https://johnson2heng.github.io/three.js-demo/lib/js/controls/OrbitControls.js"></script>
<script src="https://johnson2heng.github.io/three.js-demo/lib/js/libs/stats.min.js"></script>
<script src="https://johnson2heng.github.io/three.js-demo/lib/js/libs/dat.gui.min.js"></script>
<script>
var renderer;
function initRender() {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
//
//renderer.shadowMap.enabled = true;
//renderer.shadowMap.type = THREE.PCFSoftShadowMap; // THREE.PCFShadowMap
renderer.setClearColor(0xffffff);
document.body.appendChild(renderer.domElement);
}
var camera;
function initCamera() {
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 100);
camera.lookAt(new THREE.Vector3(0, 0, 0));
}
var scene;
function initScene() {
scene = new THREE.Scene();
}
function initLight() {
}
function initModel() {
//
var helper = new THREE.AxesHelper(10);
scene.add(helper);
var s = 25;
var cube = new THREE.CubeGeometry(s, s, s);
for (var i = 0; i < 3; iPP) {
var material = new THREE.MeshBasicMaterial({ color: randomColor() });
var mesh = new THREE.Mesh(cube, material);
mesh.position.x = 800 * (2.0 * Math.random() - 1.0);
mesh.position.y = 800 * (2.0 * Math.random() - 1.0);
mesh.position.z = 800 * (2.0 * Math.random() - 1.0);
mesh.rotation.x = Math.random() * Math.PI;
mesh.rotation.y = Math.random() * Math.PI;
mesh.rotation.z = Math.random() * Math.PI;
mesh.updateMatrix();
scene.add(mesh);
}
var loader = new THREE.ColladaLoader();
loader.load("./model/model.dae", function (collada) {
rouletteScene = collada.scene;
rouletteScene.position.set(0, 0, 80);
// rouletteScene.rotation.set(-90 * Math.PI / 180, 0, 0);
scene.add(rouletteScene);
})
}
//
function randomColor() {
var arrHex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"],
strHex = "-sharp",
index;
for (var i = 0; i < 6; iPP) {
index = Math.round(Math.random() * 15);
strHex += arrHex[index];
}
return strHex;
}
//raycastermouse
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
function onMouseClick(event) {
//raycaster-11.
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
// raycaster
raycaster.setFromCamera(mouse, camera);
// raycaster
var intersects = raycaster.intersectObjects(scene.children);
console.log(intersects);
//
for (var i = 0; i < intersects.length; iPP) {
intersects[i].object.material.color.set(0xff0000);
}
}
window.addEventListener("click", onMouseClick, false);
//dat.GUI
var gui;
function initGui() {
//
controls = {
};
var gui = new dat.GUI();
}
//
var stats;
function initStats() {
stats = new Stats();
document.body.appendChild(stats.dom);
}
//
var controls;
function initControls() {
controls = new THREE.OrbitControls(camera, renderer.domElement);
// animate
//controls.addEventListener( "change", render );
//
controls.enableDamping = true;
//
//controls.dampingFactor = 0.25;
//
controls.enableZoom = true;
//
controls.autoRotate = false;
//
controls.minDistance = 50;
//
controls.maxDistance = 200;
//
controls.enablePan = true;
}
function render() {
renderer.render(scene, camera);
}
//
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
render();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
//
render();
//
stats.update();
//controls.update();
requestAnimationFrame(animate);
}
function draw() {
initRender();
initScene();
initCamera();
initLight();
initModel();
initGui();
initControls();
initStats();
animate();
window.onresize = onWindowResize;
}
</script>
</html>
self-drawn graphics can be monitored, imported graphics can not be monitored, how to return a responsibility?