mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
1 line
36 KiB
Plaintext
1 line
36 KiB
Plaintext
|
{"version":3,"file":"trois.module.min.js","sources":["../src/core/useThree.js","../src/core/Renderer.js","../src/tools.js","../src/core/PerspectiveCamera.js","../src/core/Scene.js","../src/geometries/Geometry.js","../src/geometries/BoxGeometry.js","../src/geometries/SphereGeometry.js","../src/lights/Light.js","../src/lights/AmbientLight.js","../src/lights/PointLight.js","../src/lights/SpotLight.js","../src/materials/Material.js","../src/materials/BasicMaterial.js","../src/materials/LambertMaterial.js","../src/materials/PhongMaterial.js","../src/materials/PhysicalMaterial.js","../src/materials/StandardMaterial.js","../src/meshes/Mesh.js","../src/meshes/Box.js","../src/meshes/Plane.js","../src/meshes/Sphere.js","../src/meshes/InstancedMesh.js","../src/effects/EffectComposer.js","../src/effects/EffectPass.js","../src/effects/RenderPass.js","../src/effects/BokehPass.js","../src/effects/UnrealBloomPass.js"],"sourcesContent":["import {\r\n Plane,\r\n Raycaster,\r\n Vector2,\r\n Vector3,\r\n WebGLRenderer,\r\n} from 'three';\r\n\r\nimport { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';\r\n\r\n/**\r\n * Three.js helper\r\n */\r\nexport default function useThree() {\r\n // default conf\r\n const conf = {\r\n canvas: null,\r\n antialias: true,\r\n alpha: false,\r\n orbit_ctrl: false,\r\n mouse_move: false,\r\n mouse_raycast: false,\r\n resize: 'window',\r\n width: 0,\r\n height: 0,\r\n };\r\n\r\n // size\r\n const size = {\r\n width: 0, height: 0,\r\n wWidth: 0, wHeight: 0,\r\n ratio: 0,\r\n };\r\n\r\n // handlers\r\n const afterInitHandlers = [];\r\n const afterResizeHandlers = [];\r\n const beforeRenderHandlers = [];\r\n\r\n // mouse tracking\r\n const mouse = new Vector2();\r\n const mouseV3 = new Vector3();\r\n const mousePlane = new Plane(new Vector3(0, 0, 1), 0);\r\n const raycaster = new Raycaster();\r\n\r\n // returned object\r\n const obj = {\r\n conf,\r\n renderer: null,\r\n camera: null,\r\n cameraCtrl: null,\r\n materials: {},\r\n scene: null,\r\n size,\r\n mouse, mouseV3,\r\n init,\r\n dispose,\r\n render,\r\n renderC,\r\n setSize,\r\n onAfterInit,\r\n onAfterResize,\r\n onBeforeRender,\r\n };\r\n\r\n /**\r\n * init three\r\n */\r\n function init(params) {\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n conf[key] = value;\r\n }\r\n }\r\n\r\n if (!obj.scene) {\r\n console.error('Missing Scene');\r\n return;\r\n }\r\n\r\n if (!obj.camera) {\r\n console.error('Missing Camera');\r\n return;\r\n }\r\n\r\n obj.renderer = new WebGLRenderer({ canvas: conf.canvas, antialias: conf.antialias, alpha: conf.alpha });\r\n\r\n if (conf.orbit_ctrl) {\r\n obj.orbitCtrl = new OrbitControls(obj.camera, obj.renderer.domElement);\r\n if (conf.orbit_ctrl instanceof Object) {\r\n for (const [key, value] of Object.entries(conf.orbit_ctrl)) {\r\n obj.orbitCtrl[key] = value;\r\n }\r\n }\r\n }\r\n\r\n if (conf.width && conf.height) {\r\n setSize(conf.width, conf.height);\r\n } else if (conf.resize) {\r\n onResize();\r\n window.addEventListener('resize', onResize);\r\n }\r\n\r\n if (conf.mouse_move) {\r\n if (conf.mouse_move === 'body') {\r\n obj.mouse_move_element = document.body;\r\n } else {\r\n obj.mouse_move_element = obj.renderer.domElement;\r\n }\r\n obj.mouse_move_element.addEventListener('mousemove', onMousemove);\r\n obj.mouse_move_element.addEventListener('mouseleave', onMouseleave);\r\n }\r\n\r\n afterInitHandlers.forEach(c => c());\r\n\r\n return true;\r\n };\r\n\r\n /**\r\n * add after init handler\r\n */\r\n function onAfterInit(callback) {\r\n afterInitHandlers.push(callback);\r\n }\r\n\r\n /**\r\n * add after resize handler\r\n */\r\n function onAfterResize(callback) {\r\n afterResizeHandlers.push(callback);\r\n }\r\n\r\n /**\r\n * add before render handler\r\n */\r
|