You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.1 KiB
149 lines
4.1 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<title></title>
|
|
<meta charset="utf-8">
|
|
<meta name="generator" content="Three.js Editor">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
body {
|
|
font-family: sans-serif;
|
|
font-size: 11px;
|
|
background-color: #000;
|
|
margin: 0px;
|
|
}
|
|
|
|
canvas {
|
|
display: block;
|
|
}
|
|
|
|
.label {
|
|
color: #FFF;
|
|
font-family: sans-serif;
|
|
padding: 2px;
|
|
background: rgba(0, 0, 0, .6);
|
|
}
|
|
|
|
</style>
|
|
<script type="importmap">
|
|
{
|
|
"imports": {
|
|
"three": "../build/three.module.js",
|
|
"jsm/": "../examples/jsm/"
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body ontouchstart="">
|
|
<script type="module">
|
|
|
|
import * as THREE from 'three';
|
|
import { APP } from './js/app.js';
|
|
import { VRButton } from './js/VRButton.js';
|
|
|
|
import { OrbitControls } from 'jsm/controls/OrbitControls.js';
|
|
|
|
|
|
|
|
window.THREE = THREE; // Used by APP Scripts.
|
|
window.VRButton = VRButton; // Used by APP Scripts.
|
|
|
|
var loader = new THREE.FileLoader();
|
|
loader.load('app1.json', function (text) {
|
|
|
|
var player = new APP.Player();
|
|
player.load(JSON.parse(text));
|
|
player.setSize(window.innerWidth, window.innerHeight);
|
|
player.play();
|
|
|
|
document.body.appendChild(player.dom);
|
|
|
|
window.addEventListener('resize', function () {
|
|
|
|
player.setSize(window.innerWidth, window.innerHeight);
|
|
|
|
});
|
|
var orbitControls = new OrbitControls(window.camera, player.dom);
|
|
|
|
});
|
|
|
|
//添加这个就可以用鼠标拖动
|
|
|
|
var raycaster = new THREE.Raycaster()
|
|
var mouse = new THREE.Vector2()
|
|
//点击模型
|
|
window.addEventListener('click', onMouseClick);
|
|
|
|
function onMouseClick(event) {
|
|
|
|
//将鼠标点击位置的屏幕坐标转换成threejs中的标准坐标
|
|
mouse.x = (event.clientX / window.innerWidth) * 2 - 1
|
|
mouse.y = -((event.clientY / window.innerHeight) * 2 - 1)
|
|
//console.log("mouse:"+mouse.x+","+mouse.y)
|
|
|
|
// 通过鼠标点的位置和当前相机的矩阵计算出raycaster
|
|
raycaster.setFromCamera(mouse, window.camera);
|
|
|
|
// 获取raycaster直线和所有模型相交的数组集合
|
|
var intersects = raycaster.intersectObjects(scene.children);
|
|
console.log(intersects);
|
|
//debugger
|
|
//将所有的相交的模型的颜色设置为红色
|
|
for (var i = 0; i < intersects.length; i++) {
|
|
let obj = intersects[i];
|
|
if (obj.object) {
|
|
|
|
if (obj.object.name == "camera") {
|
|
alert("视频");
|
|
} else {
|
|
obj.object.material.color.set(0xff0000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
</script>
|
|
<!-- Code injected by live-server -->
|
|
<script>
|
|
// <![CDATA[ <-- For SVG support
|
|
if ('WebSocket' in window) {
|
|
(function () {
|
|
function refreshCSS() {
|
|
var sheets = [].slice.call(document.getElementsByTagName("link"));
|
|
var head = document.getElementsByTagName("head")[0];
|
|
for (var i = 0; i < sheets.length; ++i) {
|
|
var elem = sheets[i];
|
|
var parent = elem.parentElement || head;
|
|
parent.removeChild(elem);
|
|
var rel = elem.rel;
|
|
if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
|
|
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
|
|
elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
|
|
}
|
|
parent.appendChild(elem);
|
|
}
|
|
}
|
|
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
|
|
var address = protocol + window.location.host + window.location.pathname + '/ws';
|
|
var socket = new WebSocket(address);
|
|
socket.onmessage = function (msg) {
|
|
if (msg.data == 'reload') window.location.reload();
|
|
else if (msg.data == 'refreshcss') refreshCSS();
|
|
};
|
|
if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) {
|
|
console.log('Live reload enabled.');
|
|
sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true);
|
|
}
|
|
})();
|
|
}
|
|
else {
|
|
console.error('Upgrade your browser. This Browser is NOT supported WebSocket for Live-Reloading.');
|
|
}
|
|
// ]]>
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|
|
|