代码拉取完成,页面将自动刷新
同步操作将从 师启明/threejs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<!--本课视频地址 15 -->
<!DOCTYPE html>
<html>
<head>
<title>动力IT实训-threejs-015</title>
<meta charset="UTF-8" />
<!-- <script type="module" charset="UTF-8" src="../../libs/three.js/Three.js"></script> -->
<style>
body {
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script type="importmap">
{
"imports": {
"three": "./src/Three.js"
}
}
</script>
<!--我们将把threejs渲染的效果显示在这个div中-->
<div id="puiedu-webgl-output">
</div>
<div id="myStats"></div>
<script type="module">
import dat from "./libs/lil-gui.module.min.js";
import * as THREE from './src/Three.js'
import { OrbitControls } from "./jsm/controls/OrbitControls.js"
var scene = new THREE.Scene();
scene.background = new THREE.Color(0x333333)
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.x = 50;
camera.position.y = 50;
camera.position.z = 50;
camera.lookAt(scene.position);
scene.add(camera);
var render = new THREE.WebGLRenderer();
render.setClearColor(new THREE.Color(0xffffff));
render.setSize(window.innerWidth, window.innerHeight);
render.shadowMap.enabled = true;
document.getElementById("puiedu-webgl-output").appendChild(render.domElement);
var controls = new OrbitControls(camera, render.domElement);
controls.update();
var cubeGeo = new THREE.BoxGeometry(20, 20, 20)
var cubeMat = new THREE.MeshNormalMaterial()
var cube = new THREE.Mesh(cubeGeo, cubeMat)
scene.add(cube)
var dir = new THREE.Vector3(0, 0, 5)
console.log(dir)
dir.normalize()
console.log(dir)
var origin = new THREE.Vector3(0, 5, 0)
var length = 30;
var color = 0xffffff
var arrowHelper = new THREE.ArrowHelper(dir, origin, length, color)
cube.add(arrowHelper)
var sphereGeo = new THREE.SphereGeometry(14, 20, 20)
var sphereMat = new THREE.MeshNormalMaterial()
// sphereMat.flatShading = true
var sphere = new THREE.Mesh(sphereGeo, sphereMat)
sphere.position.set(40, 0, 0)
scene.add(sphere)
var textloader = new THREE.TextureLoader()
textloader.load("alphaMap.jpg", function (map) {
sphereMat.bumpMap = map
// sphereMat.normalMap = map
sphereMat.bumpScale = 0.5
sphereMat.displacementMap = map
sphereMat.displacementScale = 25
sphereMat.needsUpdate = true
})
var axes = new THREE.AxesHelper(100)
scene.add(axes)
var ctrl = new dat()
renderScene();
function renderScene () {
controls.update();
requestAnimationFrame(renderScene);
render.render(scene, camera);
}
window.addEventListener('resize', onWindowResize, false);
function onWindowResize () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
render.setSize(window.innerWidth, window.innerHeight);
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。