three加载三维模型obj风车及材质mtl贴图效果代码
代码语言:html
所属分类:三维
代码描述:three加载三维模型obj风车及材质mtl贴图效果代码
代码标签: three 加载 三维 模型 obj 风车 材质 mtl 贴图
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html, body { margin: 0; height: 100%; } #c { width: 100%; height: 100%; display: block; } </style> </head> <body > <canvas id="c"></canvas> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.103.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.103.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/LoaderSupport.103.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OBJLoader2.103.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/MTLLoader.103.js"></script> <script > 'use strict'; /* global THREE */ function main() { const canvas = document.querySelector('#c'); const renderer = new THREE.WebGLRenderer({ canvas: canvas }); const fov = 45; const aspect = 2; // the canvas default const near = 0.1; const far = 100; const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); camera.position.set(0, 10, 20); const controls = new THREE.OrbitControls(camera, canvas); controls.target.set(0, 5, 0); controls.update(); const scene = new THREE.Scene(); scene.background = new THREE.Color('black'); { const planeSize = 4000; const loader = new THREE.TextureLoader(); const texture = loader.load('//repo.bfw.wiki/bfwrepo/threemodel/checker.png'); texture.wrapS = THREE.RepeatWrapping; texture.wrapT = THREE.RepeatWrapping; texture.magFilter = THREE.NearestFilter; const repeats = planeSize / 200; texture.repeat.set(repeats, repeats); const planeGeo = new THREE.PlaneBufferGeometry(planeSize, planeSize); const planeMat = new THREE.MeshPhongMaterial({ map: texture, side: THREE.DoubleSide }); const mesh = new THREE.Mesh(planeGeo, planeMat); mesh.rotation.x = Math.PI * -.5; scene.add(mesh); } { const skyColor = 0xB1E1FF; // light blue const groundColor = 0xB97A20; // brownish orange const intensity = 1; const light = new THREE.HemisphereLight(skyColor, groundColor, intensity); scene.add(light); } { const color = 0xFFFFFF; const intensity = 1; const light = new THREE.DirectionalLight(color, intensity); light.position.set(5, 10, 2); scene.add(light); scene.add(light.target); } funct.........完整代码请登录后点击上方下载按钮下载查看
网友评论0