three实现室内桌上2个三维显示器显示iframe和mp4视频效果代码
代码语言:html
所属分类:三维
代码描述:three实现室内桌上2个三维显示器显示iframe和mp4视频效果代码
代码标签: three 室内 桌上 2 三维 显示器 显示 iframe mp4 视频
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>Three.js 可交互iframe和视频屏幕 - 增强版</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
margin: 0;
overflow: hidden;
}
#info {
position: absolute;
top: 10px;
width: 100%;
text-align: center;
color: white;
font-family: Arial, sans-serif;
text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}
iframe {
width: 1024px;
height: 768px;
border: 0px;
}
</style>
</head>
<body>
<div id="info">温馨的办公室 - 可交互的iframe和视频纹理显示器</div>
<video id="video" loop crossOrigin="anonymous" playsinline style="display:none" muted="muted">
<source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/127738/loremVideo.mp4" type="video/mp4">
</video>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { CSS3DRenderer, CSS3DObject } from 'three/addons/renderers/CSS3DRenderer.js';
let camera, scene, renderer;
let scene2, renderer2;
let controls;
init();
animate();
function init() {
// 场景
scene = new THREE.Scene();
scene.background = new THREE.Color(0x87CEEB); // 天蓝色背景
scene2 = new THREE.Scene();
// 相机
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(5, 3, 6);
// ========== 增强光照系统 ==========
// 环境光 - 提供整体基础亮度
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambientLight);
// 半球光 - 模拟天空和地面的反射光
const hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444444, 0.5);
hemisphereLight.position.set(0, 10, 0);
scene.add(hemisphereLight);
// 主方向光 - 模拟窗外阳光
const directionalLight = new THREE.DirectionalLight(0xfff5e6, 1.2);
directionalLight.position.set(5, 8, 3);
directionalLight.castShadow = true;
scene.add(directionalLight);
// 点光源1 - 天花板灯光
const pointLight1 = new THREE.PointLight(0xfff5e6, 1, 20);
pointLight1.position.set(0, 4.5, 0);
scene.add(pointLight1);
// 点光源2 - 左侧辅助光
const pointLight2 = new THREE.PointLight(0xffedd0, 0.6, 15);
pointLight2.position.set(-3, 3, 2);
scene.add(pointLight2);
// 点光源3 - 右侧辅助光
const pointLight3 = new THREE.PointLight(0xffedd0, 0.6, 15);
pointLight3.position.set(3, 3, 2);
scene.add(pointLight3);
// WebGL渲染器 (用于3D物体)
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
document.body.appendChild(renderer.domElement);
// CSS3DRenderer (用于iframe)
renderer2 = new CSS3DRenderer();
renderer2.setSize(window.innerWidth, window.innerHeight);
renderer2.domElement.style.position = 'absolute';
renderer2.domElement.style.top = 0;
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0