1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00
trois/build/trois.module.min.js

3 lines
12 KiB
JavaScript
Raw Normal View History

2020-09-17 05:54:14 +08:00
import{h as e}from"vue";import{Vector2 as t,Vector3 as s,Plane as i,Raycaster as r,WebGLRenderer as n,PerspectiveCamera as o,Scene as a,Color as h,BoxBufferGeometry as u,SphereBufferGeometry as c,AmbientLight as d,PointLight as m,SpotLight as l,FrontSide as f,MeshBasicMaterial as p,MeshLambertMaterial as g,MeshPhongMaterial as w,MeshPhysicalMaterial as y,MeshStandardMaterial as b,Mesh as v,PlaneBufferGeometry as S,InstancedMesh as N}from"three";import{OrbitControls as z}from"three/examples/jsm/controls/OrbitControls.js";import{EffectComposer as j}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as x}from"three/examples/jsm/postprocessing/RenderPass.js";import{BokehPass as _}from"three/examples/jsm/postprocessing/BokehPass.js";import{UnrealBloomPass as C}from"three/examples/jsm/postprocessing/UnrealBloomPass.js";function M(){var e={canvas:null,antialias:!0,alpha:!1,orbit_ctrl:!1,mouse_move:!1,mouse_raycast:!1,resize:"window",width:0,height:0},o={width:0,height:0,wWidth:0,wHeight:0,ratio:0},a=[],h=[],u=[],c=new t,d=new s,m=new i(new s(0,0,1),0),l=new r,f={conf:e,renderer:null,camera:null,cameraCtrl:null,materials:{},scene:null,size:o,mouse:c,mouseV3:d,init:function(t){if(t)for(var[s,i]of Object.entries(t))e[s]=i;if(!f.scene)return void console.error("Missing Scene");if(!f.camera)return void console.error("Missing Camera");if(f.renderer=new n({canvas:e.canvas,antialias:e.antialias,alpha:e.alpha}),e.orbit_ctrl&&(f.orbitCtrl=new z(f.camera,f.renderer.domElement),e.orbit_ctrl instanceof Object))for(var[r,o]of Object.entries(e.orbit_ctrl))f.orbitCtrl[r]=o;e.width&&e.height?b(e.width,e.height):e.resize&&(y(),window.addEventListener("resize",y));e.mouse_move&&("body"===e.mouse_move?f.mouse_move_element=document.body:f.mouse_move_element=f.renderer.domElement,f.mouse_move_element.addEventListener("mousemove",p),f.mouse_move_element.addEventListener("mouseleave",g));return a.forEach((function(e){return e()})),!0},dispose:function(){window.removeEventListener("resize",y),f.mouse_move_element&&(f.mouse_move_element.removeEventListener("mousemove",p),f.mouse_move_element.removeEventListener("mouseleave",g))},render:function(){f.orbitCtrl&&f.orbitCtrl.update();u.forEach((function(e){return e()})),f.renderer.render(f.scene,f.camera)},renderC:function(){f.orbitCtrl&&f.orbitCtrl.update();u.forEach((function(e){return e()})),f.composer.render()},setSize:b,onAfterInit:function(e){a.push(e)},onAfterResize:function(e){h.push(e)},onBeforeRender:function(e){u.push(e)}};function p(e){c.x=e.clientX/o.width*2-1,c.y=-e.clientY/o.height*2+1,w()}function g(e){c.x=0,c.y=0,w()}function w(){e.mouse_raycast&&(f.camera.getWorldDirection(m.normal),m.normal.normalize(),l.setFromCamera(c,f.camera),l.ray.intersectPlane(m,d))}function y(){"window"===e.resize?b(window.innerWidth,window.innerHeight):b(e.resize.clientWidth,e.resize.clientHeight),h.forEach((function(e){return e()}))}function b(e,t){o.width=e,o.height=t,o.ratio=e/t,f.renderer.setSize(e,t,!1),f.camera.aspect=o.ratio,f.camera.updateProjectionMatrix(),f.composer&&f.composer.setSize(e,t);var s=function(){var e=f.camera.fov*Math.PI/180,t=2*Math.tan(e/2)*Math.abs(f.camera.position.z);return[t*f.camera.aspect,t]}();o.wWidth=s[0],o.wHeight=s[1]}return f}var B={props:{antialias:{type:Boolean,default:!0},alpha:{type:Boolean,default:!1},shadow:{type:Boolean,default:!1},orbitCtrl:{type:[Boolean,Object],default:!1},mouseMove:{type:[Boolean,String],default:!1},mouseRaycast:{type:Boolean,default:!1},resize:{type:[Boolean,String,Element],default:"window"},width:String,height:String},setup:function(e){return{three:M(),raf:!0}},provide:function(){return{three:this.three}},mounted:function(){var e={canvas:this.$refs.canvas,antialias:this.antialias,alpha:this.alpha,orbit_ctrl:this.orbitCtrl,mouse_move:this.mouseMove,mouse_raycast:this.mouseRaycast,resize:this.resize,width:this.width,height:this.height};this.three.init(e)&&(this.three.renderer.shadowMap.enabled=this.shadow,this.three.composer?this.animateC():this.animate())},beforeUnmount:function(){this.raf=!1,this.three.dispose()},methods:
//# sourceMappingURL=trois.module.min.js.map