three 基础库
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.
 
 
 

197 lines
4.4 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;
}
.info {
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display: block;
color: brown;
font-size: 40px;
}
.label {
color: #ff000f;
font-family: sans-serif;
padding: 2px;
/* background: rgba(0, 0, 0, .6); */
}
.label1 {
color: #ffffff;
font-family: sans-serif;
padding: 2px;
background: rgba(0, 0, 0, .6);
}
.container {
width: 100%;
height: 100%;
}
</style>
<script type="importmap">
{
"imports": {
"three": "./libs/three/three.module.js",
"jsm/": "./libs/three/jsm/"
}
}
</script>
</head>
<body ontouchstart="">
<div class="info">2D数据表格显示 不旋转 厌氧系统 <button onclick="btnclick()">全开</button></div>
<script type="module">
import * as THREE from 'three';
import { APP } from './js/app.js';
import { OrbitControls } from 'jsm/controls/OrbitControls.js';
import { GLTFLoader } from 'jsm/loaders/GLTFLoader.js';
import { CSS3DRenderer, CSS3DObject } from 'jsm/renderers/CSS3DRenderer.js';
import { Water } from 'jsm/objects/Water.js';
import modellabel from './js/units/modellabel.js'
import css3dlabel from './js/units/css3dlabel.js'
import config from './js/config.js'
window.THREE = THREE; // Used by APP Scripts.
var player = new APP.Player();
init();
function init() {
player.play();
player.setSize(window.innerWidth, window.innerHeight);
window.addEventListener('resize', function () {
player.setSize(window.innerWidth, window.innerHeight);
});
initModel()
for (var i = 0; i < 2; i++) {
player.create3dPage(
1020, 680,
new THREE.Vector3(-2 - i, 1 + i / 3, -4.2 + i),
new THREE.Vector3(0, Math.PI, 0),
'https://zuoben.blog.csdn.net/');
}
}
// document.body.appendChild(player.dom);
function initModel() {
var loader = new GLTFLoader();
loader.load('assets/models/gallery.glb', function (gltf) {
// gltf.scene.traverse(function (child) {
// switch (child.name) {
// case 'walls':
// initWalls(child)
// break
// case 'stairs':
// initStairs(child)
// break
// }
// //设置展画边框贴图
// if (child.name.includes('paint')) {
// initFrames(child)
// }
// //设置展画图片贴图
// if (child.name.includes('draw')) {
// initDraws(child)
// }
// })
player.addModels(gltf.scene);
});
}
//
function create3dPage(w, h, position, rotation, url) {
var plane = css3dlabel.createPlane(
w, h,
position,
rotation);
window.scene.add(plane);
var cssObject = css3dlabel.createCssObject(
w, h,
position,
rotation,
url);
window.scene.add(cssObject);
}
//添加这个就可以用鼠标拖动
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(window.scene.children);
console.log(intersects);
//debugger
//将所有的相交的模型的颜色设置为红色
for (var i = 0; i < intersects.length; i++) {
let obj = intersects[i];
if (obj.object) {
if (obj.object.material[0]) {
obj.object.material[0].color.set(0xff6666);
} else if (obj.object.material) {
obj.object.material.color.set(0x006666);
}
}
}
}
</script>
</body>
</html>