代码拉取完成,页面将自动刷新
同步操作将从 师启明/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"
import { OBJLoader } from "./jsm/loaders/OBJLoader.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 axes = new THREE.AxesHelper(100)
scene.add(axes)
var planeGeo = new THREE.PlaneGeometry(100, 100)
var planeMat = new THREE.MeshLambertMaterial({ color: 0xAAAAAA })
var plane = new THREE.Mesh(planeGeo, planeMat)
plane.rotation.x = -0.5 * Math.PI
plane.position.set(15, 0, 0)
plane.reciverShadow = true
scene.add(plane)
//标准材质
// var material = new THREE.MeshStandardMaterial({ color: 0x7777ff })
//物理材质
var material = new THREE.MeshPhysicalMaterial({ color: 0x7777ff })
var props = {
color: material.color.getStyle(),
emissive: material.emissive.getStyle()
}
function loadModel (material) {
var loader = new OBJLoader()
loader.load("tree.obj", function (loadedMesh) {
loadedMesh.children.forEach(item => {
item.material = material
})
loadedMesh.scale.set(100, 100, 100);
scene.add(loadedMesh)
})
}
loadModel(material)
var spotLight = new THREE.SpotLight(0xffffff)
spotLight.position.set(0, 60, 60)
spotLight.castShadow = true
spotLight.intensity = 0.6
scene.add(spotLight)
// var ambientLight = new THREE.AmbientLight(0xffffff)
// scene.add(ambientLight)
var ctrl = new dat()
var meshStandardMaterialFolder = ctrl.addFolder("MeshStandardMaterial")
meshStandardMaterialFolder.addColor(props, "color").onChange((e) => {
material.color.setStyle(e)
})
meshStandardMaterialFolder.addColor(props, "emissive").onChange((e) => {
// material.emissive = new THREE.Color(e)
material.emissive.setStyle(e)
})
// 标准材质
meshStandardMaterialFolder.add(material, "metalness", 0, 1)
meshStandardMaterialFolder.add(material, "roughness", 0, 1)
meshStandardMaterialFolder.add(material, "wireframe")
meshStandardMaterialFolder.add(material, "wireframeLinewidth", 0, 20)
// 物理材质
meshStandardMaterialFolder.add(material, "clearcoat", 0, 1)
meshStandardMaterialFolder.add(material, "clearcoat", 0, 1)
meshStandardMaterialFolder.add(material, "reflectivity", 0, 1)
// meshStandardMaterialFolder.close()
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>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。