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

2960 lines
88 KiB
JavaScript
Raw Normal View History

2021-03-08 04:17:46 +08:00
import { h, toRef, watch, createApp as createApp$1 } from 'vue';
import { Vector2, Vector3, Plane as Plane$1, Raycaster, WebGLRenderer, OrthographicCamera as OrthographicCamera$1, PerspectiveCamera as PerspectiveCamera$1, Group as Group$1, Scene as Scene$1, Color, BoxGeometry as BoxGeometry$1, CircleGeometry as CircleGeometry$1, ConeGeometry as ConeGeometry$1, CylinderGeometry as CylinderGeometry$1, DodecahedronGeometry as DodecahedronGeometry$1, IcosahedronGeometry as IcosahedronGeometry$1, LatheGeometry as LatheGeometry$1, OctahedronGeometry as OctahedronGeometry$1, PolyhedronGeometry as PolyhedronGeometry$1, RingGeometry as RingGeometry$1, SphereGeometry as SphereGeometry$1, TetrahedronGeometry as TetrahedronGeometry$1, TorusGeometry as TorusGeometry$1, TorusKnotGeometry as TorusKnotGeometry$1, Curve, TubeGeometry as TubeGeometry$1, AmbientLight as AmbientLight$1, DirectionalLight as DirectionalLight$1, HemisphereLight as HemisphereLight$1, PointLight as PointLight$1, RectAreaLight as RectAreaLight$1, SpotLight as SpotLight$1, FrontSide, MeshBasicMaterial, MeshLambertMaterial, TextureLoader, MeshMatcapMaterial, MeshPhongMaterial, MeshStandardMaterial, MeshPhysicalMaterial, ShaderChunk, UniformsUtils, ShaderLib, ShaderMaterial as ShaderMaterial$1, MeshToonMaterial, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipmapLinearFilter, CubeTextureLoader, CubeRefractionMapping, Mesh as Mesh$1, BoxBufferGeometry, CircleBufferGeometry, ConeBufferGeometry, CylinderBufferGeometry, DodecahedronBufferGeometry, IcosahedronBufferGeometry, LatheBufferGeometry, OctahedronBufferGeometry, PlaneBufferGeometry, PolyhedronBufferGeometry, RingBufferGeometry, SphereBufferGeometry, TetrahedronBufferGeometry, FontLoader, TextBufferGeometry, TorusBufferGeometry, TorusKnotBufferGeometry, CatmullRomCurve3, WebGLCubeRenderTarget, RGBFormat, CubeCamera, BackSide, DoubleSide, InstancedMesh as InstancedMesh$1, SpriteMaterial, Sprite as Sprite$1 } from 'three';
2020-09-17 05:54:14 +08:00
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
2021-03-08 04:17:46 +08:00
import { RectAreaLightUniformsLib } from 'three/examples/jsm/lights/RectAreaLightUniformsLib.js';
import { RectAreaLightHelper } from 'three/examples/jsm/helpers/RectAreaLightHelper.js';
2020-09-17 05:54:14 +08:00
import { EffectComposer as EffectComposer$1 } from 'three/examples/jsm/postprocessing/EffectComposer.js';
import { RenderPass as RenderPass$1 } from 'three/examples/jsm/postprocessing/RenderPass.js';
import { BokehPass as BokehPass$1 } from 'three/examples/jsm/postprocessing/BokehPass.js';
2020-10-04 06:49:05 +08:00
import { FilmPass as FilmPass$1 } from 'three/examples/jsm/postprocessing/FilmPass.js';
2021-02-26 05:55:44 +08:00
import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js';
import { FXAAShader } from 'three/examples/jsm/shaders/FXAAShader.js';
2020-10-04 06:49:05 +08:00
import { HalftonePass as HalftonePass$1 } from 'three/examples/jsm/postprocessing/HalftonePass.js';
2021-02-26 05:55:44 +08:00
import { SMAAPass as SMAAPass$1 } from 'three/examples/jsm/postprocessing/SMAAPass.js';
2020-09-17 05:54:14 +08:00
import { UnrealBloomPass as UnrealBloomPass$1 } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';
/**
* Three.js helper
*/
function useThree() {
// default conf
var conf = {
canvas: null,
antialias: true,
alpha: false,
2020-10-04 06:49:05 +08:00
autoClear: true,
2020-09-17 05:54:14 +08:00
orbit_ctrl: false,
mouse_move: false,
mouse_raycast: false,
2021-02-26 05:55:44 +08:00
mouse_over: false,
click: false,
resize: true,
2020-09-17 05:54:14 +08:00
width: 0,
height: 0,
};
// size
var size = {
2021-02-26 05:55:44 +08:00
width: 1, height: 1,
wWidth: 1, wHeight: 1,
ratio: 1,
2020-09-17 05:54:14 +08:00
};
// handlers
2020-10-04 06:49:05 +08:00
var afterInitCallbacks = [];
var afterResizeCallbacks = [];
var beforeRenderCallbacks = [];
2020-09-17 05:54:14 +08:00
// mouse tracking
var mouse = new Vector2();
var mouseV3 = new Vector3();
var mousePlane = new Plane$1(new Vector3(0, 0, 1), 0);
var raycaster = new Raycaster();
2021-02-26 05:55:44 +08:00
// raycast objects
var intersectObjects = [];
2020-09-17 05:54:14 +08:00
// returned object
var obj = {
conf: conf,
renderer: null,
camera: null,
cameraCtrl: null,
materials: {},
scene: null,
size: size,
mouse: mouse, mouseV3: mouseV3,
init: init,
dispose: dispose,
render: render,
renderC: renderC,
setSize: setSize,
onAfterInit: onAfterInit,
2020-10-04 06:49:05 +08:00
onAfterResize: onAfterResize, offAfterResize: offAfterResize,
onBeforeRender: onBeforeRender, offBeforeRender: offBeforeRender,
2021-02-26 05:55:44 +08:00
addIntersectObject: addIntersectObject, removeIntersectObject: removeIntersectObject,
2020-09-17 05:54:14 +08:00
};
/**
* init three
*/
function init(params) {
if (params) {
2020-10-04 06:49:05 +08:00
Object.entries(params).forEach(function (ref) {
var key = ref[0];
var value = ref[1];
2020-09-17 05:54:14 +08:00
conf[key] = value;
2020-10-04 06:49:05 +08:00
});
2020-09-17 05:54:14 +08:00
}
if (!obj.scene) {
console.error('Missing Scene');
return;
}
if (!obj.camera) {
console.error('Missing Camera');
return;
}
obj.renderer = new WebGLRenderer({ canvas: conf.canvas, antialias: conf.antialias, alpha: conf.alpha });
2020-10-04 06:49:05 +08:00
obj.renderer.autoClear = conf.autoClear;
2020-09-17 05:54:14 +08:00
if (conf.orbit_ctrl) {
obj.orbitCtrl = new OrbitControls(obj.camera, obj.renderer.domElement);
if (conf.orbit_ctrl instanceof Object) {
2020-10-04 06:49:05 +08:00
Object.entries(conf.orbit_ctrl).forEach(function (ref) {
var key = ref[0];
var value = ref[1];
obj.orbitCtrl[key] = value;
});
2020-09-17 05:54:14 +08:00
}
}
2021-03-05 16:17:16 +08:00
if (conf.resize) {
2020-09-17 05:54:14 +08:00
onResize();
window.addEventListener('resize', onResize);
2021-03-05 16:17:16 +08:00
} else {
setSize(conf.width | 300, conf.height | 150);
2020-09-17 05:54:14 +08:00
}
2021-02-26 05:55:44 +08:00
conf.mouse_move = conf.mouse_move || conf.mouse_over;
2020-09-17 05:54:14 +08:00
if (conf.mouse_move) {
if (conf.mouse_move === 'body') {
obj.mouse_move_element = document.body;
} else {
obj.mouse_move_element = obj.renderer.domElement;
}
obj.mouse_move_element.addEventListener('mousemove', onMousemove);
obj.mouse_move_element.addEventListener('mouseleave', onMouseleave);
}
2021-02-26 05:55:44 +08:00
if (conf.click) {
obj.renderer.domElement.addEventListener('click', onClick);
}
2020-10-04 06:49:05 +08:00
afterInitCallbacks.forEach(function (c) { return c(); });
2020-09-17 05:54:14 +08:00
return true;
}
/**
2020-10-04 06:49:05 +08:00
* add after init callback
2020-09-17 05:54:14 +08:00
*/
function onAfterInit(callback) {
2020-10-04 06:49:05 +08:00
afterInitCallbacks.push(callback);
2020-09-17 05:54:14 +08:00
}
/**
2020-10-04 06:49:05 +08:00
* add after resize callback
2020-09-17 05:54:14 +08:00
*/
function onAfterResize(callback) {
2020-10-04 06:49:05 +08:00
afterResizeCallbacks.push(callback);
}
/**
* remove after resize callback
*/
function offAfterResize(callback) {
afterResizeCallbacks = afterResizeCallbacks.filter(function (c) { return c !== callback; });
2020-09-17 05:54:14 +08:00
}
/**
2020-10-04 06:49:05 +08:00
* add before render callback
2020-09-17 05:54:14 +08:00
*/
function onBeforeRender(callback) {
2020-10-04 06:49:05 +08:00
beforeRenderCallbacks.push(callback);
}
/**
* remove before render callback
*/
function offBeforeRender(callback) {
beforeRenderCallbacks = beforeRenderCallbacks.filter(function (c) { return c !== callback; });
2020-09-17 05:54:14 +08:00
}
/**
* default render
*/
function render() {
if (obj.orbitCtrl) { obj.orbitCtrl.update(); }
2020-10-04 06:49:05 +08:00
beforeRenderCallbacks.forEach(function (c) { return c(); });
2020-09-17 05:54:14 +08:00
obj.renderer.render(obj.scene, obj.camera);
}
/**
* composer render
*/
function renderC() {
if (obj.orbitCtrl) { obj.orbitCtrl.update(); }
2020-10-04 06:49:05 +08:00
beforeRenderCallbacks.forEach(function (c) { return c(); });
2020-09-17 05:54:14 +08:00
obj.composer.render();
}
2021-02-26 05:55:44 +08:00
/**
* add intersect object
*/
function addIntersectObject(o) {
if (intersectObjects.indexOf(o) === -1) {
intersectObjects.push(o);
}
}
/**
* remove intersect object
*/
function removeIntersectObject(o) {
var i = intersectObjects.indexOf(o);
if (i !== -1) {
intersectObjects.splice(i, 1);
}
}
2020-09-17 05:54:14 +08:00
/**
* remove listeners
*/
function dispose() {
2020-10-04 06:49:05 +08:00
beforeRenderCallbacks = [];
2020-09-17 05:54:14 +08:00
window.removeEventListener('resize', onResize);
if (obj.mouse_move_element) {
obj.mouse_move_element.removeEventListener('mousemove', onMousemove);
2020-10-04 06:49:05 +08:00
obj.mouse_move_element.removeEventListener('mouseleave', onMouseleave);
2020-09-17 05:54:14 +08:00
}
2021-02-26 05:55:44 +08:00
obj.renderer.domElement.removeEventListener('click', onClick);
2020-10-04 06:49:05 +08:00
if (obj.orbitCtrl) { obj.orbitCtrl.dispose(); }
this.renderer.dispose();
2020-09-17 05:54:14 +08:00
}
2021-02-28 23:56:24 +08:00
/**
*/
function updateMouse(e) {
var rect = e.target.getBoundingClientRect();
mouse.x = ((e.clientX - rect.left) / size.width) * 2 - 1;
mouse.y = -((e.clientY - rect.top) / size.height) * 2 + 1;
}
2021-02-26 05:55:44 +08:00
/**
* click listener
*/
function onClick(e) {
2021-02-28 23:56:24 +08:00
updateMouse(e);
2021-02-26 05:55:44 +08:00
raycaster.setFromCamera(mouse, obj.camera);
var objects = raycaster.intersectObjects(intersectObjects);
for (var i = 0; i < objects.length; i++) {
var o = objects[i].object;
if (o.onClick) { o.onClick(e); }
}
}
2020-09-17 05:54:14 +08:00
/**
* mousemove listener
*/
function onMousemove(e) {
2021-02-28 23:56:24 +08:00
updateMouse(e);
2021-02-26 05:55:44 +08:00
onMousechange();
2020-09-17 05:54:14 +08:00
}
/**
* mouseleave listener
*/
function onMouseleave(e) {
2021-02-26 05:55:44 +08:00
// mouse.x = 0;
// mouse.y = 0;
onMousechange();
2020-09-17 05:54:14 +08:00
}
/**
2021-02-26 05:55:44 +08:00
* mouse change
2020-09-17 05:54:14 +08:00
*/
2021-02-26 05:55:44 +08:00
function onMousechange(e) {
if (conf.mouse_over || conf.mouse_raycast) {
2020-09-17 05:54:14 +08:00
raycaster.setFromCamera(mouse, obj.camera);
2021-02-26 05:55:44 +08:00
if (conf.mouse_raycast) {
// get mouse 3d position
obj.camera.getWorldDirection(mousePlane.normal);
mousePlane.normal.normalize();
raycaster.ray.intersectPlane(mousePlane, mouseV3);
}
if (conf.mouse_over) {
var onObjects = raycaster.intersectObjects(intersectObjects);
var offObjects = [].concat( intersectObjects );
for (var i = 0; i < onObjects.length; i++) {
var o = onObjects[i].object;
if (!o.hover && o.onHover) {
o.hover = true;
o.onHover(true);
}
offObjects.splice(offObjects.indexOf(o), 1);
}
for (var i$1 = 0; i$1 < offObjects.length; i$1++) {
var o$1 = offObjects[i$1];
if (o$1.hover && o$1.onHover) {
o$1.hover = false;
o$1.onHover(false);
}
}
}
2020-09-17 05:54:14 +08:00
}
}
/**
* resize listener
*/
function onResize() {
if (conf.resize === 'window') {
setSize(window.innerWidth, window.innerHeight);
} else {
2021-02-26 05:55:44 +08:00
var elt = obj.renderer.domElement.parentNode;
setSize(elt.clientWidth, elt.clientHeight);
2020-09-17 05:54:14 +08:00
}
2020-10-04 06:49:05 +08:00
afterResizeCallbacks.forEach(function (c) { return c(); });
2020-09-17 05:54:14 +08:00
}
/**
* update renderer size and camera
*/
function setSize(width, height) {
size.width = width;
size.height = height;
size.ratio = width / height;
obj.renderer.setSize(width, height, false);
obj.camera.aspect = size.ratio;
obj.camera.updateProjectionMatrix();
if (obj.composer) {
obj.composer.setSize(width, height);
}
2021-02-26 05:55:44 +08:00
if (obj.camera.type === 'OrthographicCamera') {
size.wWidth = obj.camera.right - obj.camera.left;
size.wHeight = obj.camera.top - obj.camera.bottom;
} else {
var wsize = getCameraSize();
size.wWidth = wsize[0]; size.wHeight = wsize[1];
}
2020-09-17 05:54:14 +08:00
}
/**
* calculate camera visible area size
*/
function getCameraSize() {
var vFOV = (obj.camera.fov * Math.PI) / 180;
var h = 2 * Math.tan(vFOV / 2) * Math.abs(obj.camera.position.z);
var w = h * obj.camera.aspect;
return [w, h];
}
return obj;
}
var Renderer = {
2021-03-08 04:17:46 +08:00
name: 'Renderer',
2020-09-17 05:54:14 +08:00
props: {
2021-02-26 05:55:44 +08:00
antialias: Boolean,
alpha: Boolean,
autoClear: { type: Boolean, default: true },
mouseMove: { type: [Boolean, String], default: false },
mouseRaycast: { type: Boolean, default: false },
mouseOver: { type: Boolean, default: false },
click: { type: Boolean, default: false },
orbitCtrl: { type: [Boolean, Object], default: false },
2021-03-05 16:17:16 +08:00
resize: { type: [Boolean, String], default: false },
2021-02-26 05:55:44 +08:00
shadow: Boolean,
2020-09-17 05:54:14 +08:00
width: String,
height: String,
},
2020-10-04 06:49:05 +08:00
setup: function setup() {
2020-09-17 05:54:14 +08:00
return {
three: useThree(),
raf: true,
2020-10-04 06:49:05 +08:00
onMountedCallbacks: [],
2020-09-17 05:54:14 +08:00
};
},
provide: function provide() {
return {
three: this.three,
2020-10-04 06:49:05 +08:00
// renderer: this.three.renderer,
rendererComponent: this,
2020-09-17 05:54:14 +08:00
};
},
mounted: function mounted() {
var params = {
2021-02-26 05:55:44 +08:00
canvas: this.$el,
2020-09-17 05:54:14 +08:00
antialias: this.antialias,
alpha: this.alpha,
2020-10-04 06:49:05 +08:00
autoClear: this.autoClear,
2020-09-17 05:54:14 +08:00
orbit_ctrl: this.orbitCtrl,
mouse_move: this.mouseMove,
mouse_raycast: this.mouseRaycast,
2021-02-26 05:55:44 +08:00
mouse_over: this.mouseOver,
click: this.click,
2020-09-17 05:54:14 +08:00
resize: this.resize,
width: this.width,
height: this.height,
};
if (this.three.init(params)) {
2021-03-08 04:17:46 +08:00
this.renderer = this.three.renderer;
this.renderer.shadowMap.enabled = this.shadow;
2020-09-17 05:54:14 +08:00
if (this.three.composer) { this.animateC(); }
else { this.animate(); }
2020-10-04 06:49:05 +08:00
}
this.onMountedCallbacks.forEach(function (c) { return c(); });
},
2020-09-17 05:54:14 +08:00
beforeUnmount: function beforeUnmount() {
this.raf = false;
this.three.dispose();
},
methods: {
2020-10-04 06:49:05 +08:00
onMounted: function onMounted(callback) {
this.onMountedCallbacks.push(callback);
},
2020-09-17 05:54:14 +08:00
onBeforeRender: function onBeforeRender(callback) {
this.three.onBeforeRender(callback);
},
onAfterResize: function onAfterResize(callback) {
this.three.onAfterResize(callback);
},
animate: function animate() {
if (this.raf) { requestAnimationFrame(this.animate); }
this.three.render();
},
animateC: function animateC() {
if (this.raf) { requestAnimationFrame(this.animateC); }
this.three.renderC();
},
},
render: function render() {
2021-02-26 05:55:44 +08:00
return h('canvas', {}, this.$slots.default());
2020-09-17 05:54:14 +08:00
},
2021-03-08 04:17:46 +08:00
__hmrId: 'Renderer',
2020-09-17 05:54:14 +08:00
};
function setFromProp(o, prop) {
if (prop instanceof Object) {
2020-10-04 06:49:05 +08:00
Object.entries(prop).forEach(function (ref) {
var key = ref[0];
var value = ref[1];
2020-09-17 05:54:14 +08:00
o[key] = value;
2020-10-04 06:49:05 +08:00
});
2020-09-17 05:54:14 +08:00
}
}
2021-03-08 04:17:46 +08:00
function bindProp(src, srcProp, dst, dstProp) {
if (!dstProp) { dstProp = srcProp; }
var ref = toRef(src, srcProp);
if (ref.value instanceof Object) {
setFromProp(dst[dstProp], ref.value);
watch(ref, function (value) { setFromProp(dst[dstProp], value); }, { deep: true });
} else {
if (ref.value) { dst[dstProp] = src[srcProp]; }
watch(ref, function (value) { dst[dstProp] = value; });
}
}
2020-10-04 06:49:05 +08:00
function propsValues(props, exclude) {
var values = {};
Object.entries(props).forEach(function (ref) {
var key = ref[0];
var value = ref[1];
if (!exclude || (exclude && !exclude.includes(key))) {
values[key] = value;
}
});
return values;
}
2020-09-17 05:54:14 +08:00
function lerp(value1, value2, amount) {
amount = amount < 0 ? 0 : amount;
amount = amount > 1 ? 1 : amount;
return value1 + (value2 - value1) * amount;
}
2021-02-26 05:55:44 +08:00
function lerpv2(v1, v2, amount) {
v1.x = lerp(v1.x, v2.x, amount);
v1.y = lerp(v1.y, v2.y, amount);
}
2020-09-17 05:54:14 +08:00
function lerpv3(v1, v2, amount) {
v1.x = lerp(v1.x, v2.x, amount);
v1.y = lerp(v1.y, v2.y, amount);
v1.z = lerp(v1.z, v2.z, amount);
}
2020-10-04 06:49:05 +08:00
function limit(val, min, max) {
return val < min ? min : (val > max ? max : val);
}
2021-02-26 05:55:44 +08:00
// from https://github.com/pmndrs/drei/blob/master/src/useMatcapTexture.tsx
var MATCAP_ROOT = 'https://rawcdn.githack.com/emmelleppi/matcaps/9b36ccaaf0a24881a39062d05566c9e92be4aa0d';
function getMatcapUrl(hash, format) {
if ( format === void 0 ) format = 1024;
var fileName = "" + hash + (getMatcapFormatString(format)) + ".png";
return (MATCAP_ROOT + "/" + format + "/" + fileName);
}
function getMatcapFormatString(format) {
switch (format) {
case 64:
return '-64px';
case 128:
return '-128px';
case 256:
return '-256px';
case 512:
return '-512px';
default:
return '';
}
}
2020-10-04 06:49:05 +08:00
2021-02-26 05:55:44 +08:00
var OrthographicCamera = {
2021-03-08 04:17:46 +08:00
name: 'OrthographicCamera',
2021-02-26 05:55:44 +08:00
inject: ['three'],
props: {
left: { type: Number, default: -1 },
right: { type: Number, default: 1 },
top: { type: Number, default: 1 },
bottom: { type: Number, default: -1 },
near: { type: Number, default: 0.1 },
far: { type: Number, default: 2000 },
zoom: { type: Number, default: 1 },
2021-03-08 04:17:46 +08:00
position: { type: Object, default: { x: 0, y: 0, z: 0 } },
2021-02-26 05:55:44 +08:00
},
created: function created() {
var this$1 = this;
this.camera = new OrthographicCamera$1(this.left, this.right, this.top, this.bottom, this.near, this.far);
2021-03-08 04:17:46 +08:00
bindProp(this, 'position', this.camera);
2021-02-26 05:55:44 +08:00
['left', 'right', 'top', 'bottom', 'near', 'far', 'zoom'].forEach(function (p) {
watch(function () { return this$1[p]; }, function () {
this$1.camera[p] = this$1[p];
this$1.camera.updateProjectionMatrix();
});
});
this.three.camera = this.camera;
},
2021-03-08 04:17:46 +08:00
render: function render() { return []; },
2021-02-26 05:55:44 +08:00
__hmrId: 'OrthographicCamera',
};
2020-09-17 05:54:14 +08:00
var PerspectiveCamera = {
2021-03-08 04:17:46 +08:00
name: 'PerspectiveCamera',
2020-09-17 05:54:14 +08:00
inject: ['three'],
props: {
2021-02-26 05:55:44 +08:00
aspect: { type: Number, default: 1 },
far: { type: Number, default: 2000 },
fov: { type: Number, default: 50 },
near: { type: Number, default: 0.1 },
2021-03-08 04:17:46 +08:00
position: { type: Object, default: { x: 0, y: 0, z: 0 } },
lookAt: { type: Object, default: null },
2020-09-17 05:54:14 +08:00
},
created: function created() {
2020-10-04 06:49:05 +08:00
var this$1 = this;
this.camera = new PerspectiveCamera$1(this.fov, this.aspect, this.near, this.far);
2021-03-08 04:17:46 +08:00
bindProp(this, 'position', this.camera);
2020-10-04 06:49:05 +08:00
2021-03-05 16:17:16 +08:00
if (this.lookAt) { this.camera.lookAt(this.lookAt.x, this.lookAt.y, this.lookAt.z); }
watch(function () { return this$1.lookAt; }, function (v) { this$1.camera.lookAt(v.x, v.y, v.z); }, { deep: true });
2020-10-04 06:49:05 +08:00
['aspect', 'far', 'fov', 'near'].forEach(function (p) {
watch(function () { return this$1[p]; }, function () {
this$1.camera[p] = this$1[p];
this$1.camera.updateProjectionMatrix();
});
});
this.three.camera = this.camera;
2020-09-17 05:54:14 +08:00
},
2021-03-08 04:17:46 +08:00
render: function render() { return []; },
2020-10-04 06:49:05 +08:00
__hmrId: 'PerspectiveCamera',
2020-09-17 05:54:14 +08:00
};
2021-03-08 04:17:46 +08:00
var Object3D = {
name: 'Object3D',
inject: ['three', 'scene', 'rendererComponent'],
2021-02-26 05:55:44 +08:00
props: {
2021-03-08 04:17:46 +08:00
position: { type: Object, default: { x: 0, y: 0, z: 0 } },
rotation: { type: Object, default: { x: 0, y: 0, z: 0 } },
scale: { type: Object, default: { x: 1, y: 1, z: 1 } },
lookAt: { type: Object, default: null },
2021-02-26 05:55:44 +08:00
},
2021-03-08 04:17:46 +08:00
// can't use setup because it will not be used in sub components
// setup() {},
unmounted: function unmounted() {
if (this.$parent.remove) { this.$parent.remove(this.o3d); }
2021-02-26 05:55:44 +08:00
},
2021-03-08 04:17:46 +08:00
methods: {
initObject3D: function initObject3D(o3d) {
var this$1 = this;
2021-03-04 06:23:57 +08:00
2021-03-08 04:17:46 +08:00
this.o3d = o3d;
2021-03-04 06:23:57 +08:00
2021-03-08 04:17:46 +08:00
bindProp(this, 'position', this.o3d);
bindProp(this, 'rotation', this.o3d);
bindProp(this, 'scale', this.o3d);
// fix lookat.x
if (this.lookAt) { this.o3d.lookAt(this.lookAt.x, this.lookAt.y, this.lookAt.z); }
watch(function () { return this$1.lookAt; }, function (v) { this$1.o3d.lookAt(v.x, v.y, v.z); }, { deep: true });
if (this.$parent.add) { this.$parent.add(this.o3d); }
},
add: function add(o) { this.o3d.add(o); },
remove: function remove(o) { this.o3d.remove(o); },
2021-02-26 05:55:44 +08:00
},
render: function render() {
2021-03-08 04:17:46 +08:00
return this.$slots.default ? this.$slots.default() : [];
},
__hmrId: 'Object3D',
};
var Group = {
name: 'Group',
extends: Object3D,
created: function created() {
this.group = new Group$1();
this.initObject3D(this.group);
2021-02-26 05:55:44 +08:00
},
__hmrId: 'Group',
};
2020-09-17 05:54:14 +08:00
var Scene = {
2021-03-08 04:17:46 +08:00
name: 'Scene',
2020-09-17 05:54:14 +08:00
inject: ['three'],
props: {
id: String,
background: [String, Number],
},
2020-10-04 06:49:05 +08:00
setup: function setup(props) {
2020-09-17 05:54:14 +08:00
var scene = new Scene$1();
if (props.background) { scene.background = new Color(props.background); }
2020-10-04 06:49:05 +08:00
watch(function () { return props.background; }, function (value) { scene.background = new Color(value); });
2020-09-17 05:54:14 +08:00
return { scene: scene };
},
provide: function provide() {
return {
scene: this.scene,
};
},
mounted: function mounted() {
if (!this.three.scene) {
this.three.scene = this.scene;
}
},
2020-10-04 06:49:05 +08:00
methods: {
2021-03-08 04:17:46 +08:00
add: function add(o) { this.scene.add(o); },
remove: function remove(o) { this.scene.remove(o); },
2020-10-04 06:49:05 +08:00
},
2020-09-17 05:54:14 +08:00
render: function render() {
2021-03-08 04:17:46 +08:00
return this.$slots.default ? this.$slots.default() : [];
2020-09-17 05:54:14 +08:00
},
2021-03-08 04:17:46 +08:00
__hmrId: 'Scene',
2020-09-17 05:54:14 +08:00
};
var Geometry = {
2020-10-04 06:49:05 +08:00
inject: ['mesh'],
props: {
rotateX: Number,
rotateY: Number,
rotateZ: Number,
},
created: function created() {
var this$1 = this;
if (!this.mesh) {
2020-09-17 05:54:14 +08:00
console.error('Missing parent Mesh');
}
2021-03-08 04:17:46 +08:00
2020-10-04 06:49:05 +08:00
this.watchProps = [];
Object.entries(this.$props).forEach(function (e) { return this$1.watchProps.push(e[0]); });
2021-03-08 04:17:46 +08:00
2020-10-04 06:49:05 +08:00
this.createGeometry();
this.rotateGeometry();
this.mesh.setGeometry(this.geometry);
2021-03-08 04:17:46 +08:00
2020-10-04 06:49:05 +08:00
this.addWatchers();
2020-09-17 05:54:14 +08:00
},
unmounted: function unmounted() {
2020-10-04 06:49:05 +08:00
this.geometry.dispose();
},
methods: {
addWatchers: function addWatchers() {
var this$1 = this;
this.watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
2021-03-08 04:17:46 +08:00
rotateGeometry: function rotateGeometry() {
if (this.rotateX) { this.geometry.rotateX(this.rotateX); }
if (this.rotateY) { this.geometry.rotateY(this.rotateY); }
if (this.rotateZ) { this.geometry.rotateZ(this.rotateZ); }
},
2020-10-04 06:49:05 +08:00
refreshGeometry: function refreshGeometry() {
var oldGeo = this.geometry;
this.createGeometry();
this.rotateGeometry();
this.mesh.setGeometry(this.geometry);
oldGeo.dispose();
},
2020-09-17 05:54:14 +08:00
},
2021-03-08 04:17:46 +08:00
render: function render() { return []; },
2020-09-17 05:54:14 +08:00
};
var BoxGeometry = {
extends: Geometry,
props: {
2020-10-04 06:49:05 +08:00
size: Number,
width: { type: Number, default: 1 },
height: { type: Number, default: 1 },
depth: { type: Number, default: 1 },
widthSegments: { type: Number, default: 1 },
heightSegments: { type: Number, default: 1 },
depthSegments: { type: Number, default: 1 },
},
methods: {
createGeometry: function createGeometry() {
var w = this.width, h = this.height, d = this.depth;
if (this.size) {
w = this.size; h = this.size; d = this.size;
}
2021-03-08 04:17:46 +08:00
this.geometry = new BoxGeometry$1(w, h, d, this.widthSegments, this.heightSegments, this.depthSegments);
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
},
};
var CircleGeometry = {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
segments: { type: Number, default: 8 },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new CircleGeometry$1(this.radius, this.segments, this.thetaStart, this.thetaLength);
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
},
};
var ConeGeometry = {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
height: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
heightSegments: { type: Number, default: 1 },
openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new ConeGeometry$1(this.radius, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
},
};
var CylinderGeometry = {
extends: Geometry,
props: {
radiusTop: { type: Number, default: 1 },
radiusBottom: { type: Number, default: 1 },
height: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
heightSegments: { type: Number, default: 1 },
openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new CylinderGeometry$1(this.radiusTop, this.radiusBottom, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
2020-09-17 05:54:14 +08:00
},
},
2020-10-04 06:49:05 +08:00
};
var DodecahedronGeometry = {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new DodecahedronGeometry$1(this.radius, this.detail);
2020-10-04 06:49:05 +08:00
},
},
};
var IcosahedronGeometry = {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new IcosahedronGeometry$1(this.radius, this.detail);
2020-10-04 06:49:05 +08:00
},
},
};
var LatheGeometry = {
extends: Geometry,
props: {
points: Array,
segments: { type: Number, default: 12 },
phiStart: { type: Number, default: 0 },
phiLength: { type: Number, default: Math.PI * 2 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new LatheGeometry$1(this.points, this.segments, this.phiStart, this.phiLength);
2020-10-04 06:49:05 +08:00
},
},
};
var OctahedronGeometry = {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new OctahedronGeometry$1(this.radius, this.detail);
2020-10-04 06:49:05 +08:00
},
},
};
var PolyhedronGeometry = {
extends: Geometry,
props: {
vertices: Array,
indices: Array,
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new PolyhedronGeometry$1(this.vertices, this.indices, this.radius, this.detail);
2020-10-04 06:49:05 +08:00
},
},
};
var RingGeometry = {
extends: Geometry,
props: {
innerRadius: { type: Number, default: 0.5 },
outerRadius: { type: Number, default: 1 },
thetaSegments: { type: Number, default: 8 },
phiSegments: { type: Number, default: 1 },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new RingGeometry$1(this.innerRadius, this.outerRadius, this.thetaSegments, this.phiSegments, this.thetaStart, this.thetaLength);
2020-10-04 06:49:05 +08:00
},
2020-09-17 05:54:14 +08:00
},
};
var SphereGeometry = {
extends: Geometry,
props: {
2020-10-04 06:49:05 +08:00
radius: { type: Number, default: 1 },
widthSegments: { type: Number, default: 12 },
heightSegments: { type: Number, default: 12 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new SphereGeometry$1(this.radius, this.widthSegments, this.heightSegments);
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
},
};
var TetrahedronGeometry = {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new TetrahedronGeometry$1(this.radius, this.detail);
2020-09-17 05:54:14 +08:00
},
},
2020-10-04 06:49:05 +08:00
};
var TorusGeometry = {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
tube: { type: Number, default: 0.4 },
radialSegments: { type: Number, default: 8 },
tubularSegments: { type: Number, default: 6 },
arc: { type: Number, default: Math.PI * 2 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new TorusGeometry$1(this.radius, this.tube, this.radialSegments, this.tubularSegments, this.arc);
2020-10-04 06:49:05 +08:00
},
},
};
var TorusKnotGeometry = {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
tube: { type: Number, default: 0.4 },
radialSegments: { type: Number, default: 64 },
tubularSegments: { type: Number, default: 8 },
p: { type: Number, default: 2 },
q: { type: Number, default: 3 },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new TorusKnotGeometry$1(this.radius, this.tube, this.radialSegments, this.tubularSegments, this.p, this.q);
2020-10-04 06:49:05 +08:00
},
},
};
var TubeGeometry = {
extends: Geometry,
props: {
path: Curve,
tubularSegments: { type: Number, default: 64 },
radius: { type: Number, default: 1 },
radiusSegments: { type: Number, default: 8 },
closed: { type: Boolean, default: false },
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
this.geometry = new TubeGeometry$1(this.path, this.tubularSegments, this.radius, this.radiusSegments, this.closed);
2020-10-04 06:49:05 +08:00
},
2020-09-17 05:54:14 +08:00
},
};
var Light = {
2021-03-08 04:17:46 +08:00
extends: Object3D,
name: 'Light',
2020-09-17 05:54:14 +08:00
props: {
2021-03-08 04:17:46 +08:00
color: { type: String, default: '#ffffff' },
intensity: { type: Number, default: 1 },
castShadow: { type: Boolean, default: false },
shadowMapSize: { type: Object, default: { x: 512, y: 512 } },
2020-09-17 05:54:14 +08:00
},
2021-02-26 05:55:44 +08:00
// can't use setup because it will not be used in sub components
// setup() {},
2021-03-08 04:17:46 +08:00
unmounted: function unmounted() {
if (this.light.target) { this.$parent.remove(this.light.target); }
2021-03-04 05:59:51 +08:00
},
2021-03-08 04:17:46 +08:00
methods: {
initLight: function initLight() {
var this$1 = this;
2020-10-04 06:49:05 +08:00
2021-03-08 04:17:46 +08:00
if (this.light.target) {
bindProp(this, 'target', this.light.target, 'position');
}
2020-09-17 05:54:14 +08:00
2021-03-08 04:17:46 +08:00
if (this.light.shadow) {
this.light.castShadow = this.castShadow;
setFromProp(this.light.shadow.mapSize, this.shadowMapSize);
}
2020-09-17 05:54:14 +08:00
2021-03-08 04:17:46 +08:00
['color', 'intensity', 'castShadow'].forEach(function (p) {
watch(function () { return this$1[p]; }, function () {
if (p === 'color') {
this$1.light.color = new Color(this$1.color);
} else {
this$1.light[p] = this$1[p];
}
});
2020-10-04 06:49:05 +08:00
});
2021-03-08 04:17:46 +08:00
this.initObject3D(this.light);
if (this.light.target) { this.$parent.add(this.light.target); }
},
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'Light',
2020-09-17 05:54:14 +08:00
};
var AmbientLight = {
extends: Light,
created: function created() {
this.light = new AmbientLight$1(this.color, this.intensity);
2021-03-08 04:17:46 +08:00
this.initLight();
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'AmbientLight',
};
var DirectionalLight = {
extends: Light,
props: {
target: Object,
},
created: function created() {
this.light = new DirectionalLight$1(this.color, this.intensity);
2021-03-08 04:17:46 +08:00
this.initLight();
2020-10-04 06:49:05 +08:00
},
__hmrId: 'DirectionalLight',
2020-09-17 05:54:14 +08:00
};
2021-03-08 04:17:46 +08:00
var HemisphereLight = {
extends: Light,
props: {
groundColor: { type: String, default: '#ffffff' },
},
created: function created() {
this.light = new HemisphereLight$1(this.color, this.groundColor, this.intensity);
bindProp(this, 'groundColor', this.light);
this.initLight();
},
__hmrId: 'HemisphereLight',
};
2020-09-17 05:54:14 +08:00
var PointLight = {
extends: Light,
props: {
distance: {
type: Number,
default: 0,
},
decay: {
type: Number,
default: 1,
},
},
created: function created() {
this.light = new PointLight$1(this.color, this.intensity, this.distance, this.decay);
2021-03-08 04:17:46 +08:00
this.initLight();
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'PointLight',
2020-09-17 05:54:14 +08:00
};
2021-03-08 04:17:46 +08:00
var RectAreaLight = {
extends: Light,
props: {
width: { type: Number, default: 10 },
height: { type: Number, default: 10 },
helper: Boolean,
},
created: function created() {
var this$1 = this;
RectAreaLightUniformsLib.init();
this.light = new RectAreaLight$1(this.color, this.intensity, this.width, this.height);
['width', 'height'].forEach(function (p) {
watch(function () { return this$1[p]; }, function () {
this$1.light[p] = this$1[p];
});
});
if (this.helper) {
this.lightHelper = new RectAreaLightHelper(this.light);
this.$parent.add(this.lightHelper);
}
this.initLight();
},
unmounted: function unmounted() {
if (this.lightHelper) { this.$parent.remove(this.lightHelper); }
},
__hmrId: 'RectAreaLight',
};
2020-09-17 05:54:14 +08:00
var SpotLight = {
extends: Light,
props: {
2021-03-08 04:17:46 +08:00
angle: { type: Number, default: Math.PI / 3 },
decay: { type: Number, default: 1 },
distance: { type: Number, default: 0 },
penumbra: { type: Number, default: 0 },
2020-10-04 06:49:05 +08:00
target: Object,
2020-09-17 05:54:14 +08:00
},
created: function created() {
2020-10-04 06:49:05 +08:00
var this$1 = this;
2020-09-17 05:54:14 +08:00
this.light = new SpotLight$1(this.color, this.intensity, this.distance, this.angle, this.penumbra, this.decay);
2020-10-04 06:49:05 +08:00
['angle', 'decay', 'distance', 'penumbra'].forEach(function (p) {
watch(function () { return this$1[p]; }, function () {
this$1.light[p] = this$1[p];
});
});
2021-03-08 04:17:46 +08:00
this.initLight();
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'SpotLight',
2020-09-17 05:54:14 +08:00
};
var Material = {
2020-10-04 06:49:05 +08:00
inject: ['three', 'mesh'],
2020-09-17 05:54:14 +08:00
props: {
2020-10-04 06:49:05 +08:00
color: { type: [String, Number], default: '#ffffff' },
depthTest: { type: Boolean, default: true },
depthWrite: { type: Boolean, default: true },
flatShading: Boolean,
fog: { type: Boolean, default: true },
opacity: { type: Number, default: 1 },
side: { type: Number, default: FrontSide },
transparent: Boolean,
vertexColors: Boolean,
},
provide: function provide() {
return {
material: this,
};
},
2021-03-08 04:17:46 +08:00
created: function created() {
2020-10-04 06:49:05 +08:00
this.createMaterial();
this.mesh.setMaterial(this.material);
2021-03-08 04:17:46 +08:00
2020-10-04 06:49:05 +08:00
this._addWatchers();
if (this.addWatchers) { this.addWatchers(); }
2020-09-17 05:54:14 +08:00
},
unmounted: function unmounted() {
this.material.dispose();
},
methods: {
2021-02-26 05:55:44 +08:00
setProp: function setProp(key, value, needsUpdate) {
if ( needsUpdate === void 0 ) needsUpdate = false;
this.material[key] = value;
this.material.needsUpdate = needsUpdate;
2020-10-04 06:49:05 +08:00
},
2021-02-26 05:55:44 +08:00
setTexture: function setTexture(texture, key) {
if ( key === void 0 ) key = 'map';
this.setProp(key, texture, true);
2020-10-04 06:49:05 +08:00
},
_addWatchers: function _addWatchers() {
var this$1 = this;
// don't work for flatShading
['color', 'depthTest', 'depthWrite', 'fog', 'opacity', 'side', 'transparent'].forEach(function (p) {
watch(function () { return this$1[p]; }, function () {
if (p === 'color') {
this$1.material.color.set(this$1.color);
} else {
this$1.material[p] = this$1[p];
}
});
});
2020-09-17 05:54:14 +08:00
},
},
render: function render() {
2021-03-08 04:17:46 +08:00
return this.$slots.default ? this.$slots.default() : [];
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'Material',
2020-09-17 05:54:14 +08:00
};
var BasicMaterial = {
extends: Material,
2020-10-04 06:49:05 +08:00
methods: {
createMaterial: function createMaterial() {
2021-03-08 04:17:46 +08:00
this.material = new MeshBasicMaterial(propsValues(this.$props));
2020-10-04 06:49:05 +08:00
},
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'BasicMaterial',
2020-09-17 05:54:14 +08:00
};
var LambertMaterial = {
extends: Material,
2020-10-04 06:49:05 +08:00
methods: {
createMaterial: function createMaterial() {
2021-03-08 04:17:46 +08:00
this.material = new MeshLambertMaterial(propsValues(this.$props));
2020-10-04 06:49:05 +08:00
},
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'LambertMaterial',
2020-09-17 05:54:14 +08:00
};
2021-02-26 05:55:44 +08:00
var MatcapMaterial = {
2020-09-17 05:54:14 +08:00
extends: Material,
2021-02-26 05:55:44 +08:00
props: {
src: String,
name: String,
},
2020-10-04 06:49:05 +08:00
methods: {
createMaterial: function createMaterial() {
2021-02-26 05:55:44 +08:00
var src = this.name ? getMatcapUrl(this.name) : this.src;
2021-03-08 04:17:46 +08:00
var opts = propsValues(this.$props, ['src', 'name']);
2021-02-26 05:55:44 +08:00
opts.matcap = new TextureLoader().load(src);
this.material = new MeshMatcapMaterial(opts);
2020-10-04 06:49:05 +08:00
},
2020-09-17 05:54:14 +08:00
},
2021-02-26 05:55:44 +08:00
__hmrId: 'MatcapMaterial',
2020-09-17 05:54:14 +08:00
};
2021-02-26 05:55:44 +08:00
var PhongMaterial = {
2020-09-17 05:54:14 +08:00
extends: Material,
props: {
2020-10-04 06:49:05 +08:00
emissive: { type: [Number, String], default: 0 },
emissiveIntensity: { type: Number, default: 1 },
2021-02-26 05:55:44 +08:00
reflectivity: { type: Number, default: 1 },
shininess: { type: Number, default: 30 },
specular: { type: [String, Number], default: 0x111111 },
},
methods: {
createMaterial: function createMaterial() {
2021-03-08 04:17:46 +08:00
this.material = new MeshPhongMaterial(propsValues(this.$props));
2021-02-26 05:55:44 +08:00
},
addWatchers: function addWatchers() {
var this$1 = this;
['emissive', 'emissiveIntensity', 'reflectivity', 'shininess', 'specular'].forEach(function (p) {
watch(function () { return this$1[p]; }, function (value) {
if (p === 'emissive' || p === 'specular') {
this$1.material[p].set(value);
} else {
this$1.material[p] = value;
}
});
});
},
2020-10-04 06:49:05 +08:00
},
2021-02-26 05:55:44 +08:00
__hmrId: 'PhongMaterial',
};
var props = {
aoMapIntensity: { type: Number, default: 1 },
bumpScale: { type: Number, default: 1 },
displacementBias: { type: Number, default: 0 },
displacementScale: { type: Number, default: 1 },
emissive: { type: [Number, String], default: 0 },
emissiveIntensity: { type: Number, default: 1 },
envMapIntensity: { type: Number, default: 1 },
lightMapIntensity: { type: Number, default: 1 },
metalness: { type: Number, default: 0 },
2021-03-08 04:17:46 +08:00
normalScale: { type: Object, default: { x: 1, y: 1 } },
2021-02-26 05:55:44 +08:00
roughness: { type: Number, default: 1 },
refractionRatio: { type: Number, default: 0.98 },
wireframe: Boolean,
};
var StandardMaterial = {
extends: Material,
props: props,
2020-10-04 06:49:05 +08:00
methods: {
createMaterial: function createMaterial() {
2021-03-08 04:17:46 +08:00
this.material = new MeshStandardMaterial(propsValues(this.$props, ['normalScale']));
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
addWatchers: function addWatchers() {
var this$1 = this;
2021-02-26 05:55:44 +08:00
// todo : use setProp ?
Object.keys(props).forEach(function (p) {
if (p === 'normalScale') { return; }
2020-10-04 06:49:05 +08:00
watch(function () { return this$1[p]; }, function (value) {
if (p === 'emissive') {
2021-02-26 05:55:44 +08:00
this$1.material[p].set(value);
2020-10-04 06:49:05 +08:00
} else {
this$1.material[p] = value;
}
});
});
2021-03-08 04:17:46 +08:00
bindProp(this, 'normalScale', this.material);
2020-09-17 05:54:14 +08:00
},
},
2020-10-04 06:49:05 +08:00
__hmrId: 'StandardMaterial',
};
var PhysicalMaterial = {
extends: StandardMaterial,
methods: {
createMaterial: function createMaterial() {
2021-03-08 04:17:46 +08:00
this.material = new MeshPhysicalMaterial(propsValues(this.$props));
2020-10-04 06:49:05 +08:00
},
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'PhysicalMaterial',
2020-09-17 05:54:14 +08:00
};
2020-10-04 06:49:05 +08:00
/**
* ------------------------------------------------------------------------------------------
* Subsurface Scattering shader
* Based on three/examples/jsm/shaders/SubsurfaceScatteringShader.js
* Based on GDC 2011 Approximating Translucency for a Fast, Cheap and Convincing Subsurface Scattering Look
* https://colinbarrebrisebois.com/2011/03/07/gdc-2011-approximating-translucency-for-a-fast-cheap-and-convincing-subsurface-scattering-look/
*------------------------------------------------------------------------------------------
*/
function replaceAll(string, find, replace) {
return string.split(find).join(replace);
}
var meshphongFragHead = ShaderChunk.meshphong_frag.slice(0, ShaderChunk.meshphong_frag.indexOf('void main() {'));
var meshphongFragBody = ShaderChunk.meshphong_frag.slice(ShaderChunk.meshphong_frag.indexOf('void main() {'));
var SubsurfaceScatteringShader = {
uniforms: UniformsUtils.merge([
ShaderLib.phong.uniforms,
{
thicknessColor: { value: new Color(0x668597) },
thicknessDistortion: { value: 0.1 },
thicknessAmbient: { value: 0.0 },
thicknessAttenuation: { value: 0.1 },
thicknessPower: { value: 2.0 },
thicknessScale: { value: 10.0 },
} ]),
vertexShader: ("\n #define USE_UV\n " + (ShaderChunk.meshphong_vert) + "\n "),
fragmentShader: "\n #define USE_UV\n #define SUBSURFACE\n\n " + meshphongFragHead + "\n\n uniform float thicknessPower;\n uniform float thicknessScale;\n uniform float thicknessDistortion;\n uniform float thicknessAmbient;\n uniform float thicknessAttenuation;\n uniform vec3 thicknessColor;\n\n void RE_Direct_Scattering(const in IncidentLight directLight, const in vec2 uv, const in GeometricContext geometry, inout ReflectedLight reflectedLight) {\n #ifdef USE_COLOR\n vec3 thickness = vColor * thicknessColor;\n #else\n vec3 thickness = thicknessColor;\n #endif\n vec3 scatteringHalf = normalize(directLight.direction + (geometry.normal * thicknessDistortion));\n float scatteringDot = pow(saturate(dot(geometry.viewDir, -scatteringHalf)), thicknessPower) * thicknessScale;\n vec3 scatteringIllu = (scatteringDot + thicknessAmbient) * thickness;\n reflectedLight.directDiffuse += scatteringIllu * thicknessAttenuation * directLight.color;\n }\n " + meshphongFragBody.replace(
'#include <lights_fragment_begin>',
replaceAll(
ShaderChunk.lights_fragment_begin,
'RE_Direct( directLight, geometry, material, reflectedLight );',
"\n RE_Direct( directLight, geometry, material, reflectedLight );\n #if defined( SUBSURFACE ) && defined( USE_UV )\n RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);\n #endif\n "
)
),
};
var ShaderMaterial = {
inject: ['three', 'mesh'],
2020-09-17 05:54:14 +08:00
props: {
2020-10-04 06:49:05 +08:00
uniforms: Object,
vertexShader: String,
fragmentShader: String,
},
2021-03-08 04:17:46 +08:00
created: function created() {
2020-10-04 06:49:05 +08:00
this.createMaterial();
this.mesh.setMaterial(this.material);
if (this.addWatchers) { this.addWatchers(); }
2020-09-17 05:54:14 +08:00
},
unmounted: function unmounted() {
2020-10-04 06:49:05 +08:00
this.material.dispose();
2020-09-17 05:54:14 +08:00
},
render: function render() {
return [];
},
2020-10-04 06:49:05 +08:00
__hmrId: 'ShaderMaterial',
2020-09-17 05:54:14 +08:00
};
2020-10-04 06:49:05 +08:00
var SubSurfaceMaterial = {
extends: ShaderMaterial,
2020-09-17 05:54:14 +08:00
props: {
2021-03-04 04:49:22 +08:00
color: { type: String, default: '#ffffff' },
2020-10-04 06:49:05 +08:00
thicknessColor: { type: String, default: '#ffffff' },
thicknessDistortion: { type: Number, default: 0.4 },
thicknessAmbient: { type: Number, default: 0.01 },
thicknessAttenuation: { type: Number, default: 0.7 },
thicknessPower: { type: Number, default: 2 },
thicknessScale: { type: Number, default: 4 },
transparent: { type: Boolean, default: false },
opacity: { type: Number, default: 1 },
vertexColors: { type: Boolean, default: false },
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
methods: {
createMaterial: function createMaterial() {
var params = SubsurfaceScatteringShader;
var uniforms = UniformsUtils.clone(params.uniforms);
2021-03-04 04:49:22 +08:00
2020-10-04 06:49:05 +08:00
Object.entries(this.$props).forEach(function (ref) {
var key = ref[0];
var value = ref[1];
2021-03-04 04:49:22 +08:00
var _key = key, _value = value;
if (['color', 'thicknessColor'].includes(key)) {
if (key === 'color') { _key = 'diffuse'; }
_value = new Color(value);
2020-10-04 06:49:05 +08:00
}
2021-03-08 04:17:46 +08:00
if (!['transparent', 'vertexColors'].includes(key)) {
2021-03-04 04:49:22 +08:00
uniforms[_key].value = _value;
2020-10-04 06:49:05 +08:00
}
});
this.material = new ShaderMaterial$1(Object.assign({}, params,
{uniforms: uniforms,
lights: true,
transparent: this.transparent,
vertexColors: this.vertexColors}));
},
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'SubSurfaceMaterial',
2020-09-17 05:54:14 +08:00
};
2020-10-04 06:49:05 +08:00
var ToonMaterial = {
extends: Material,
methods: {
createMaterial: function createMaterial() {
2021-03-08 04:17:46 +08:00
this.material = new MeshToonMaterial(propsValues(this.$props));
2020-09-17 05:54:14 +08:00
},
},
2020-10-04 06:49:05 +08:00
__hmrId: 'ToonMaterial',
2020-09-17 05:54:14 +08:00
};
2021-02-26 05:55:44 +08:00
var Texture = {
2020-10-04 06:49:05 +08:00
inject: ['material'],
2021-02-26 05:55:44 +08:00
emits: ['loaded'],
props: {
2021-03-08 04:17:46 +08:00
id: { type: String, default: 'map' },
2021-02-26 05:55:44 +08:00
src: String,
onLoad: Function,
onProgress: Function,
onError: Function,
2021-03-08 04:17:46 +08:00
mapping: { type: Number, default: UVMapping },
wrapS: { type: Number, default: ClampToEdgeWrapping },
wrapT: { type: Number, default: ClampToEdgeWrapping },
magFilter: { type: Number, default: LinearFilter },
minFilter: { type: Number, default: LinearMipmapLinearFilter },
repeat: { type: Object, default: { x: 1, y: 1 } },
rotation: { type: Number, default: 0 },
center: { type: Object, default: { x: 0, y: 0 } },
2021-02-26 05:55:44 +08:00
},
2020-10-04 06:49:05 +08:00
created: function created() {
2021-02-26 05:55:44 +08:00
var this$1 = this;
this.refreshTexture();
watch(function () { return this$1.src; }, this.refreshTexture);
2020-10-04 06:49:05 +08:00
},
unmounted: function unmounted() {
2021-02-26 05:55:44 +08:00
this.material.setTexture(null, this.id);
this.texture.dispose();
2020-10-04 06:49:05 +08:00
},
methods: {
2021-02-26 05:55:44 +08:00
createTexture: function createTexture() {
2021-03-08 04:17:46 +08:00
var this$1 = this;
2021-02-26 05:55:44 +08:00
this.texture = new TextureLoader().load(this.src, this.onLoaded, this.onProgress, this.onError);
2021-03-08 04:17:46 +08:00
var wathProps = ['mapping', 'wrapS', 'wrapT', 'magFilter', 'minFilter', 'repeat', 'rotation', 'rotation', 'center'];
wathProps.forEach(function (prop) {
bindProp(this$1, prop, this$1.texture);
});
2021-02-26 05:55:44 +08:00
},
2020-10-04 06:49:05 +08:00
refreshTexture: function refreshTexture() {
this.createTexture();
2021-02-26 05:55:44 +08:00
this.material.setTexture(this.texture, this.id);
2020-09-17 05:54:14 +08:00
},
2021-02-26 05:55:44 +08:00
onLoaded: function onLoaded() {
if (this.onLoad) { this.onLoad(); }
this.$emit('loaded');
},
},
2021-03-08 04:17:46 +08:00
render: function render() { return []; },
2020-10-04 06:49:05 +08:00
};
2021-02-26 05:55:44 +08:00
var CubeTexture = {
2020-10-04 06:49:05 +08:00
inject: ['material'],
2021-02-26 05:55:44 +08:00
emits: ['loaded'],
props: {
path: String,
urls: {
type: Array,
default: ['px.jpg', 'nx.jpg', 'py.jpg', 'ny.jpg', 'pz.jpg', 'nz.jpg'],
},
onLoad: Function,
onProgress: Function,
onError: Function,
id: { type: String, default: 'envMap' },
refraction: Boolean,
// todo: remove ?
refractionRatio: { type: Number, default: 0.98 },
},
2020-09-17 05:54:14 +08:00
created: function created() {
2021-02-26 05:55:44 +08:00
var this$1 = this;
this.refreshTexture();
watch(function () { return this$1.path; }, this.refreshTexture);
watch(function () { return this$1.urls; }, this.refreshTexture);
2020-10-04 06:49:05 +08:00
},
unmounted: function unmounted() {
2021-02-26 05:55:44 +08:00
this.material.setTexture(null, this.id);
this.texture.dispose();
2020-10-04 06:49:05 +08:00
},
methods: {
2021-02-26 05:55:44 +08:00
createTexture: function createTexture() {
this.texture = new CubeTextureLoader()
.setPath(this.path)
.load(this.urls, this.onLoaded, this.onProgress, this.onError);
},
2020-10-04 06:49:05 +08:00
refreshTexture: function refreshTexture() {
this.createTexture();
2021-02-26 05:55:44 +08:00
this.material.setTexture(this.texture, this.id);
if (this.refraction) {
this.texture.mapping = CubeRefractionMapping;
this.material.setProp('refractionRatio', this.refractionRatio);
}
2020-10-04 06:49:05 +08:00
},
2021-02-26 05:55:44 +08:00
onLoaded: function onLoaded() {
if (this.onLoad) { this.onLoad(); }
this.$emit('loaded');
},
},
render: function render() {
return [];
2020-09-17 05:54:14 +08:00
},
};
2020-10-04 06:49:05 +08:00
var Mesh = {
2021-03-08 04:17:46 +08:00
extends: Object3D,
name: 'Mesh',
2020-09-17 05:54:14 +08:00
props: {
2020-10-04 06:49:05 +08:00
castShadow: Boolean,
receiveShadow: Boolean,
2021-02-26 05:55:44 +08:00
onHover: Function,
onClick: Function,
},
// can't use setup because it will not be used in sub components
// setup() {},
2020-09-17 05:54:14 +08:00
provide: function provide() {
return {
2020-10-04 06:49:05 +08:00
mesh: this,
2020-09-17 05:54:14 +08:00
};
},
mounted: function mounted() {
2021-03-08 04:17:46 +08:00
if (!this.mesh && !this.loading) { this.initMesh(); }
2020-10-04 06:49:05 +08:00
},
methods: {
initMesh: function initMesh() {
2021-02-26 05:55:44 +08:00
var this$1 = this;
2020-10-04 06:49:05 +08:00
this.mesh = new Mesh$1(this.geometry, this.material);
2021-02-26 05:55:44 +08:00
2021-03-08 04:17:46 +08:00
['castShadow', 'receiveShadow'].forEach(function (p) {
this$1.mesh[p] = this$1[p];
watch(function () { return this$1[p]; }, function () { this$1.mesh[p] = this$1[p]; });
});
2021-02-26 05:55:44 +08:00
if (this.onHover) {
this.mesh.onHover = function (over) { this$1.onHover({ component: this$1, over: over }); };
this.three.addIntersectObject(this.mesh);
}
if (this.onClick) {
this.mesh.onClick = function (e) { this$1.onClick({ component: this$1, event: e }); };
this.three.addIntersectObject(this.mesh);
}
2021-03-08 04:17:46 +08:00
this.initObject3D(this.mesh);
2020-10-04 06:49:05 +08:00
},
setGeometry: function setGeometry(geometry) {
this.geometry = geometry;
if (this.mesh) { this.mesh.geometry = geometry; }
},
setMaterial: function setMaterial(material) {
this.material = material;
if (this.mesh) { this.mesh.material = material; }
},
refreshGeometry: function refreshGeometry() {
var oldGeo = this.geometry;
this.createGeometry();
this.mesh.geometry = this.geometry;
oldGeo.dispose();
},
2020-09-17 05:54:14 +08:00
},
2021-03-08 04:17:46 +08:00
unmounted: function unmounted() {
if (this.mesh) {
this.three.removeIntersectObject(this.mesh);
2020-10-04 06:49:05 +08:00
}
2021-03-08 04:17:46 +08:00
// for predefined mesh (geometry and material are not unmounted)
if (this.geometry) { this.geometry.dispose(); }
if (this.material) { this.material.dispose(); }
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'Mesh',
2020-09-17 05:54:14 +08:00
};
2020-10-04 06:49:05 +08:00
var Box = {
extends: Mesh,
props: {
size: Number,
width: { type: Number, default: 1 },
height: { type: Number, default: 1 },
depth: { type: Number, default: 1 },
widthSegments: { type: Number, default: 1 },
heightSegments: { type: Number, default: 1 },
depthSegments: { type: Number, default: 1 },
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
created: function created() {
2020-09-17 05:54:14 +08:00
var this$1 = this;
2020-10-04 06:49:05 +08:00
this.createGeometry();
['size', 'width', 'height', 'depth', 'widthSegments', 'heightSegments', 'depthSegments'].forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
2020-09-17 05:54:14 +08:00
});
});
},
2020-10-04 06:49:05 +08:00
methods: {
createGeometry: function createGeometry() {
if (this.size) {
this.geometry = new BoxBufferGeometry(this.size, this.size, this.size);
} else {
this.geometry = new BoxBufferGeometry(this.width, this.height, this.depth);
}
},
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
__hmrId: 'Box',
2020-09-17 05:54:14 +08:00
};
2020-10-04 06:49:05 +08:00
var Circle = {
extends: Mesh,
props: {
radius: { type: Number, default: 1 },
segments: { type: Number, default: 8 },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radius', 'segments', 'thetaStart', 'thetaLength'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
2020-09-17 05:54:14 +08:00
},
2020-10-04 06:49:05 +08:00
methods: {
createGeometry: function createGeometry() {
this.geometry = new CircleBufferGeometry(this.radius, this.segments, this.thetaStart, this.thetaLength);
},
},
__hmrId: 'Circle',
2020-09-17 05:54:14 +08:00
};
2020-10-04 06:49:05 +08:00
var Cone = {
extends: Mesh,
props: {
radius: { type: Number, default: 1 },
height: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
heightSegments: { type: Number, default: 1 },
openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radius', 'height', 'radialSegments', 'heightSegments', 'openEnded', 'thetaStart', 'thetaLength'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new ConeBufferGeometry(this.radius, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
},
},
__hmrId: 'Cone',
};
var Cylinder = {
extends: Mesh,
props: {
radiusTop: { type: Number, default: 1 },
radiusBottom: { type: Number, default: 1 },
height: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
heightSegments: { type: Number, default: 1 },
openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radiusTop', 'radiusBottom', 'height', 'radialSegments', 'heightSegments', 'openEnded', 'thetaStart', 'thetaLength'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new CylinderBufferGeometry(this.radiusTop, this.radiusBottom, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
},
},
__hmrId: 'Cylinder',
};
var Dodecahedron = {
extends: Mesh,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radius', 'detail'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new DodecahedronBufferGeometry(this.radius, this.detail);
},
},
__hmrId: 'Dodecahedron',
};
var Icosahedron = {
extends: Mesh,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radius', 'detail'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new IcosahedronBufferGeometry(this.radius, this.detail);
},
},
__hmrId: 'Icosahedron',
};
var Lathe = {
extends: Mesh,
props: {
points: Array,
segments: { type: Number, default: 12 },
phiStart: { type: Number, default: 0 },
phiLength: { type: Number, default: Math.PI * 2 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['points', 'segments', 'phiStart', 'phiLength'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new LatheBufferGeometry(this.points, this.segments, this.phiStart, this.phiLength);
},
},
__hmrId: 'Lathe',
};
var Octahedron = {
extends: Mesh,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radius', 'detail'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new OctahedronBufferGeometry(this.radius, this.detail);
},
},
__hmrId: 'Octahedron',
};
var Plane = {
extends: Mesh,
props: {
width: { type: Number, default: 1 },
height: { type: Number, default: 1 },
widthSegments: { type: Number, default: 1 },
heightSegments: { type: Number, default: 1 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['width', 'height', 'widthSegments', 'heightSegments'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new PlaneBufferGeometry(this.width, this.height, this.widthSegments, this.heightSegments);
},
},
__hmrId: 'Plane',
};
var Polyhedron = {
extends: Mesh,
props: {
vertices: Array,
indices: Array,
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['vertices', 'indices', 'radius', 'detail'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new PolyhedronBufferGeometry(this.vertices, this.indices, this.radius, this.detail);
},
},
__hmrId: 'Polyhedron',
};
var Ring = {
extends: Mesh,
props: {
innerRadius: { type: Number, default: 0.5 },
outerRadius: { type: Number, default: 1 },
thetaSegments: { type: Number, default: 8 },
phiSegments: { type: Number, default: 1 },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['innerRadius', 'outerRadius', 'thetaSegments', 'phiSegments', 'thetaStart', 'thetaLength'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new RingBufferGeometry(this.innerRadius, this.outerRadius, this.thetaSegments, this.phiSegments, this.thetaStart, this.thetaLength);
},
},
__hmrId: 'Ring',
};
var Sphere = {
extends: Mesh,
props: {
radius: Number,
widthSegments: { type: Number, default: 12 },
heightSegments: { type: Number, default: 12 },
},
watch: {
radius: function radius() { this.refreshGeometry(); },
widthSegments: function widthSegments() { this.refreshGeometry(); },
heightSegments: function heightSegments() { this.refreshGeometry(); },
},
created: function created() {
this.createGeometry();
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new SphereBufferGeometry(this.radius, this.widthSegments, this.heightSegments);
},
},
__hmrId: 'Sphere',
};
var Tetrahedron = {
extends: Mesh,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radius', 'detail'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new TetrahedronBufferGeometry(this.radius, this.detail);
},
},
__hmrId: 'Tetrahedron',
};
var TextProps = {
text: String,
fontSrc: String,
size: { type: Number, default: 80 },
height: { type: Number, default: 5 },
depth: { type: Number, default: 1 },
curveSegments: { type: Number, default: 12 },
bevelEnabled: { type: Boolean, default: false },
bevelThickness: { type: Number, default: 10 },
bevelSize: { type: Number, default: 8 },
bevelOffset: { type: Number, default: 0 },
bevelSegments: { type: Number, default: 5 },
align: { type: [Boolean, String], default: false },
};
var Text = {
extends: Mesh,
props: Object.assign({}, TextProps),
2021-03-08 04:17:46 +08:00
data: function data() {
return {
loading: true,
};
},
2020-10-04 06:49:05 +08:00
created: function created() {
var this$1 = this;
// add watchers
var watchProps = [
'text', 'size', 'height', 'curveSegments',
'bevelEnabled', 'bevelThickness', 'bevelSize', 'bevelOffset', 'bevelSegments',
'align' ];
watchProps.forEach(function (p) {
watch(function () { return this$1[p]; }, function () {
if (this$1.font) { this$1.refreshGeometry(); }
});
});
var loader = new FontLoader();
loader.load(this.fontSrc, function (font) {
2021-03-08 04:17:46 +08:00
this$1.loading = false;
2020-10-04 06:49:05 +08:00
this$1.font = font;
this$1.createGeometry();
this$1.initMesh();
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new TextBufferGeometry(this.text, {
font: this.font,
size: this.size,
height: this.height,
depth: this.depth,
curveSegments: this.curveSegments,
bevelEnabled: this.bevelEnabled,
bevelThickness: this.bevelThickness,
bevelSize: this.bevelSize,
bevelOffset: this.bevelOffset,
bevelSegments: this.bevelSegments,
});
if (this.align === 'center') {
this.geometry.center();
}
},
},
};
var Torus = {
extends: Mesh,
props: {
radius: { type: Number, default: 0.5 },
tube: { type: Number, default: 0.4 },
radialSegments: { type: Number, default: 8 },
tubularSegments: { type: Number, default: 6 },
arc: { type: Number, default: Math.PI * 2 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radius', 'tube', 'radialSegments', 'tubularSegments', 'arc'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new TorusBufferGeometry(this.radius, this.tube, this.radialSegments, this.tubularSegments, this.arc);
},
},
__hmrId: 'Torus',
};
var TorusKnot = {
extends: Mesh,
props: {
radius: { type: Number, default: 0.5 },
tube: { type: Number, default: 0.4 },
2021-03-04 04:49:22 +08:00
tubularSegments: { type: Number, default: 64 },
radialSegments: { type: Number, default: 8 },
2020-10-04 06:49:05 +08:00
p: { type: Number, default: 2 },
q: { type: Number, default: 3 },
},
created: function created() {
var this$1 = this;
this.createGeometry();
var watchProps = ['radius', 'tube', 'radialSegments', 'tubularSegments', 'p', 'q'];
watchProps.forEach(function (prop) {
watch(function () { return this$1[prop]; }, function () {
this$1.refreshGeometry();
});
});
},
methods: {
createGeometry: function createGeometry() {
2021-03-04 04:49:22 +08:00
this.geometry = new TorusKnotBufferGeometry(this.radius, this.tube, this.tubularSegments, this.radialSegments, this.p, this.q);
2020-10-04 06:49:05 +08:00
},
},
__hmrId: 'TorusKnot',
};
var Tube = {
extends: Mesh,
props: {
path: Curve,
2021-03-08 04:17:46 +08:00
points: Array,
2020-10-04 06:49:05 +08:00
tubularSegments: { type: Number, default: 64 },
radius: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
closed: { type: Boolean, default: false },
},
created: function created() {
var this$1 = this;
this.createGeometry();
2021-03-08 04:17:46 +08:00
var watchProps = ['tubularSegments', 'radius', 'radialSegments', 'closed'];
2020-10-04 06:49:05 +08:00
watchProps.forEach(function (prop) {
2021-03-08 04:17:46 +08:00
watch(function () { return this$1[prop]; }, function (v) {
2020-10-04 06:49:05 +08:00
this$1.refreshGeometry();
});
});
2021-03-10 01:25:02 +08:00
watch(function () { return this$1.points; }, function () {
updateTubeGeometryPoints(this$1.geometry, this$1.points);
});
2020-10-04 06:49:05 +08:00
},
methods: {
createGeometry: function createGeometry() {
2021-03-08 04:17:46 +08:00
var curve;
if (this.points) {
curve = new CatmullRomCurve3(this.points);
} else if (this.path) {
curve = this.path;
} else {
console.error('Missing path curve or points.');
}
this.geometry = new TubeGeometry$1(curve, this.tubularSegments, this.radius, this.radialSegments, this.closed);
},
2021-03-10 01:25:02 +08:00
// update curve points (without using prop, faster)
updateCurve: function updateCurve(points) {
updateTubeGeometryPoints(this.geometry, points);
2020-10-04 06:49:05 +08:00
},
},
__hmrId: 'Tube',
};
2021-03-08 04:17:46 +08:00
function updateTubeGeometryPoints(tube, points) {
var curve = new CatmullRomCurve3(points);
var ref = tube.parameters;
var radialSegments = ref.radialSegments;
var radius = ref.radius;
var tubularSegments = ref.tubularSegments;
var closed = ref.closed;
var frames = curve.computeFrenetFrames(tubularSegments, closed);
tube.tangents = frames.tangents;
tube.normals = frames.normals;
tube.binormals = frames.binormals;
tube.parameters.path = curve;
var pArray = tube.attributes.position.array;
var nArray = tube.attributes.normal.array;
var normal = new Vector3();
var P;
for (var i = 0; i < tubularSegments; i++) {
updateSegment(i);
}
updateSegment(tubularSegments);
tube.attributes.position.needsUpdate = true;
tube.attributes.normal.needsUpdate = true;
function updateSegment(i) {
P = curve.getPointAt(i / tubularSegments, P);
var N = frames.normals[i];
var B = frames.binormals[i];
for (var j = 0; j <= radialSegments; j++) {
var v = j / radialSegments * Math.PI * 2;
var sin = Math.sin(v);
var cos = -Math.cos(v);
normal.x = (cos * N.x + sin * B.x);
normal.y = (cos * N.y + sin * B.y);
normal.z = (cos * N.z + sin * B.z);
normal.normalize();
var index = (i * (radialSegments + 1) + j) * 3;
nArray[index] = normal.x;
nArray[index + 1] = normal.y;
nArray[index + 2] = normal.z;
pArray[index] = P.x + radius * normal.x;
pArray[index + 1] = P.y + radius * normal.y;
pArray[index + 2] = P.z + radius * normal.z;
}
}
}
2020-10-04 06:49:05 +08:00
var Gem = {
extends: Mesh,
props: {
2021-02-26 05:55:44 +08:00
cubeRTSize: { type: Number, default: 256 },
2020-10-04 06:49:05 +08:00
cubeCameraNear: { type: Number, default: 0.1 },
cubeCameraFar: { type: Number, default: 2000 },
autoUpdate: Boolean,
},
mounted: function mounted() {
this.initGem();
if (this.autoUpdate) { this.three.onBeforeRender(this.updateCubeRT); }
else { this.rendererComponent.onMounted(this.updateCubeRT); }
},
unmounted: function unmounted() {
this.three.offBeforeRender(this.updateCubeRT);
2021-03-08 04:17:46 +08:00
if (this.meshBack) { this.$parent.remove(this.meshBack); }
2020-10-04 06:49:05 +08:00
if (this.materialBack) { this.materialBack.dispose(); }
},
methods: {
initGem: function initGem() {
var cubeRT = new WebGLCubeRenderTarget(this.cubeRTSize, { format: RGBFormat, generateMipmaps: true, minFilter: LinearMipmapLinearFilter });
this.cubeCamera = new CubeCamera(this.cubeCameraNear, this.cubeCameraFar, cubeRT);
2021-03-08 04:17:46 +08:00
bindProp(this, 'position', this.cubeCamera);
this.$parent.add(this.cubeCamera);
2020-10-04 06:49:05 +08:00
this.material.side = FrontSide;
this.material.envMap = cubeRT.texture;
this.material.envMapIntensity = 10;
this.material.metalness = 0;
this.material.roughness = 0;
this.material.opacity = 0.75;
this.material.transparent = true;
this.material.premultipliedAlpha = true;
this.material.needsUpdate = true;
this.materialBack = this.material.clone();
this.materialBack.side = BackSide;
this.materialBack.envMapIntensity = 5;
this.materialBack.metalness = 1;
this.materialBack.roughness = 0;
this.materialBack.opacity = 0.5;
this.meshBack = new Mesh$1(this.geometry, this.materialBack);
2021-03-08 04:17:46 +08:00
bindProp(this, 'position', this.meshBack);
bindProp(this, 'rotation', this.meshBack);
bindProp(this, 'scale', this.meshBack);
this.$parent.add(this.meshBack);
2020-10-04 06:49:05 +08:00
},
updateCubeRT: function updateCubeRT() {
this.mesh.visible = false;
this.meshBack.visible = false;
this.cubeCamera.update(this.three.renderer, this.scene);
this.mesh.visible = true;
this.meshBack.visible = true;
},
},
__hmrId: 'Gem',
};
var Image = {
emits: ['loaded'],
extends: Mesh,
props: {
src: String,
width: Number,
height: Number,
keepSize: Boolean,
},
created: function created() {
var this$1 = this;
this.createGeometry();
this.createMaterial();
this.initMesh();
watch(function () { return this$1.src; }, this.refreshTexture);
['width', 'height'].forEach(function (p) {
watch(function () { return this$1[p]; }, this$1.resize);
});
if (this.keepSize) { this.three.onAfterResize(this.resize); }
},
methods: {
createGeometry: function createGeometry() {
this.geometry = new PlaneBufferGeometry(1, 1, 1, 1);
},
createMaterial: function createMaterial() {
this.material = new MeshBasicMaterial({ side: DoubleSide, map: this.loadTexture() });
},
loadTexture: function loadTexture() {
return new TextureLoader().load(this.src, this.onLoaded);
},
refreshTexture: function refreshTexture() {
if (this.texture) { this.texture.dispose(); }
this.material.map = this.loadTexture();
this.material.needsUpdate = true;
},
onLoaded: function onLoaded(texture) {
this.texture = texture;
this.resize();
this.$emit('loaded');
},
resize: function resize() {
if (!this.texture) { return; }
var screen = this.three.size;
var iW = this.texture.image.width;
var iH = this.texture.image.height;
var iRatio = iW / iH;
var w, h;
if (this.width && this.height) {
w = this.width * screen.wWidth / screen.width;
h = this.height * screen.wHeight / screen.height;
} else if (this.width) {
w = this.width * screen.wWidth / screen.width;
h = w / iRatio;
} else if (this.height) {
h = this.height * screen.wHeight / screen.height;
w = h * iRatio;
}
this.mesh.scale.x = w;
this.mesh.scale.y = h;
},
},
__hmrId: 'Image',
};
var InstancedMesh = {
2021-03-08 04:17:46 +08:00
extends: Object3D,
2020-10-04 06:49:05 +08:00
props: {
castShadow: Boolean,
receiveShadow: Boolean,
2021-03-08 04:17:46 +08:00
count: Number,
2020-10-04 06:49:05 +08:00
},
provide: function provide() {
return {
mesh: this,
};
},
beforeMount: function beforeMount() {
if (!this.$slots.default) {
console.error('Missing Geometry');
}
},
2021-03-08 04:17:46 +08:00
created: function created() {
2020-10-04 06:49:05 +08:00
this.initMesh();
},
methods: {
initMesh: function initMesh() {
var this$1 = this;
this.mesh = new InstancedMesh$1(this.geometry, this.material, this.count);
['castShadow', 'receiveShadow'].forEach(function (p) {
this$1.mesh[p] = this$1[p];
watch(function () { return this$1[p]; }, function () { this$1.mesh[p] = this$1[p]; });
});
2021-03-08 04:17:46 +08:00
this.initObject3D(this.mesh);
2020-10-04 06:49:05 +08:00
},
setGeometry: function setGeometry(geometry) {
this.geometry = geometry;
if (this.mesh) { this.mesh.geometry = geometry; }
},
setMaterial: function setMaterial(material) {
this.material = material;
if (this.mesh) { this.mesh.material = material; }
},
},
__hmrId: 'InstancedMesh',
};
var MirrorMesh = {
extends: Mesh,
props: {
2021-02-26 05:55:44 +08:00
cubeRTSize: { type: Number, default: 256 },
2020-10-04 06:49:05 +08:00
cubeCameraNear: { type: Number, default: 0.1 },
cubeCameraFar: { type: Number, default: 2000 },
autoUpdate: Boolean,
},
mounted: function mounted() {
this.initMirrorMesh();
if (this.autoUpdate) { this.three.onBeforeRender(this.updateCubeRT); }
else { this.rendererComponent.onMounted(this.updateCubeRT); }
},
unmounted: function unmounted() {
this.three.offBeforeRender(this.updateCubeRT);
2021-03-08 04:17:46 +08:00
if (this.cubeCamera) { this.$parent.remove(this.cubeCamera); }
2020-10-04 06:49:05 +08:00
},
methods: {
initMirrorMesh: function initMirrorMesh() {
var cubeRT = new WebGLCubeRenderTarget(this.cubeRTSize, { format: RGBFormat, generateMipmaps: true, minFilter: LinearMipmapLinearFilter });
this.cubeCamera = new CubeCamera(this.cubeCameraNear, this.cubeCameraFar, cubeRT);
2021-03-08 04:17:46 +08:00
this.$parent.add(this.cubeCamera);
2020-10-04 06:49:05 +08:00
this.material.envMap = cubeRT.texture;
this.material.needsUpdate = true;
},
updateCubeRT: function updateCubeRT() {
this.mesh.visible = false;
this.cubeCamera.update(this.three.renderer, this.scene);
this.mesh.visible = true;
},
},
__hmrId: 'MirrorMesh',
};
var RefractionMesh = {
extends: Mesh,
props: {
2021-02-26 05:55:44 +08:00
cubeRTSize: { type: Number, default: 256 },
2020-10-04 06:49:05 +08:00
cubeCameraNear: { type: Number, default: 0.1 },
cubeCameraFar: { type: Number, default: 2000 },
2021-02-26 05:55:44 +08:00
refractionRatio: { type: Number, default: 0.98 },
2020-10-04 06:49:05 +08:00
autoUpdate: Boolean,
},
mounted: function mounted() {
this.initMirrorMesh();
if (this.autoUpdate) { this.three.onBeforeRender(this.updateCubeRT); }
else { this.rendererComponent.onMounted(this.updateCubeRT); }
},
unmounted: function unmounted() {
this.three.offBeforeRender(this.updateCubeRT);
2021-03-08 04:17:46 +08:00
if (this.cubeCamera) { this.$parent.remove(this.cubeCamera); }
2020-10-04 06:49:05 +08:00
},
methods: {
initMirrorMesh: function initMirrorMesh() {
var cubeRT = new WebGLCubeRenderTarget(this.cubeRTSize, { mapping: CubeRefractionMapping, format: RGBFormat, generateMipmaps: true, minFilter: LinearMipmapLinearFilter });
this.cubeCamera = new CubeCamera(this.cubeCameraNear, this.cubeCameraFar, cubeRT);
2021-03-08 04:17:46 +08:00
bindProp(this, 'position', this.cubeCamera);
this.$parent.add(this.cubeCamera);
2020-10-04 06:49:05 +08:00
this.material.envMap = cubeRT.texture;
2021-02-26 05:55:44 +08:00
this.material.refractionRatio = this.refractionRatio;
2020-10-04 06:49:05 +08:00
this.material.needsUpdate = true;
},
updateCubeRT: function updateCubeRT() {
this.mesh.visible = false;
this.cubeCamera.update(this.three.renderer, this.scene);
this.mesh.visible = true;
},
},
__hmrId: 'RefractionMesh',
};
var Sprite = {
2021-03-08 04:17:46 +08:00
extends: Object3D,
emits: ['loaded'],
2020-10-04 06:49:05 +08:00
props: {
src: String,
},
2021-03-08 04:17:46 +08:00
data: function data() {
return {
loading: true,
};
2021-02-26 05:55:44 +08:00
},
2021-03-08 04:17:46 +08:00
created: function created() {
2020-10-04 06:49:05 +08:00
this.texture = new TextureLoader().load(this.src, this.onLoaded);
this.material = new SpriteMaterial({ map: this.texture });
this.sprite = new Sprite$1(this.material);
this.geometry = this.sprite.geometry;
2021-03-08 04:17:46 +08:00
this.initObject3D(this.sprite);
2020-10-04 06:49:05 +08:00
},
unmounted: function unmounted() {
this.texture.dispose();
this.material.dispose();
},
methods: {
onLoaded: function onLoaded() {
2021-03-08 04:17:46 +08:00
this.loading = false;
2020-10-04 06:49:05 +08:00
this.updateUV();
this.$emit('loaded');
},
updateUV: function updateUV() {
this.iWidth = this.texture.image.width;
this.iHeight = this.texture.image.height;
this.iRatio = this.iWidth / this.iHeight;
var x = 0.5, y = 0.5;
if (this.iRatio > 1) {
y = 0.5 / this.iRatio;
} else {
x = 0.5 / this.iRatio;
}
var positions = this.geometry.attributes.position.array;
positions[0] = -x; positions[1] = -y;
positions[5] = x; positions[6] = -y;
positions[10] = x; positions[11] = y;
positions[15] = -x; positions[16] = y;
this.geometry.attributes.position.needsUpdate = true;
},
},
__hmrId: 'Sprite',
};
var EffectComposer = {
setup: function setup() {
return {
passes: [],
};
},
inject: ['three'],
provide: function provide() {
return {
passes: this.passes,
};
},
mounted: function mounted() {
var this$1 = this;
this.three.onAfterInit(function () {
this$1.composer = new EffectComposer$1(this$1.three.renderer);
this$1.three.renderer.autoClear = false;
this$1.passes.forEach(function (pass) {
this$1.composer.addPass(pass);
});
this$1.three.composer = this$1.composer;
2021-02-26 05:55:44 +08:00
this$1.resize();
this$1.three.onAfterResize(this$1.resize);
2020-10-04 06:49:05 +08:00
});
},
2021-02-26 05:55:44 +08:00
unmounted: function unmounted() {
this.three.offAfterResize(this.resize);
},
methods: {
resize: function resize() {
this.composer.setSize(this.three.size.width, this.three.size.height);
},
},
2020-10-04 06:49:05 +08:00
render: function render() {
return this.$slots.default();
},
__hmrId: 'EffectComposer',
};
var EffectPass = {
inject: ['three', 'passes'],
beforeMount: function beforeMount() {
if (!this.passes) {
console.error('Missing parent EffectComposer');
}
},
unmounted: function unmounted() {
if (this.pass.dispose) { this.pass.dispose(); }
},
render: function render() {
return [];
},
__hmrId: 'EffectPass',
};
var RenderPass = {
extends: EffectPass,
mounted: function mounted() {
if (!this.three.scene) {
console.error('Missing Scene');
}
if (!this.three.camera) {
console.error('Missing Camera');
}
var pass = new RenderPass$1(this.three.scene, this.three.camera);
this.passes.push(pass);
this.pass = pass;
},
__hmrId: 'RenderPass',
};
var BokehPass = {
2020-09-17 05:54:14 +08:00
extends: EffectPass,
2020-10-04 06:49:05 +08:00
props: {
focus: {
type: Number,
default: 1,
},
aperture: {
type: Number,
default: 0.025,
},
maxblur: {
type: Number,
default: 0.01,
},
},
watch: {
focus: function focus() { this.pass.uniforms.focus.value = this.focus; },
aperture: function aperture() { this.pass.uniforms.aperture.value = this.aperture; },
maxblur: function maxblur() { this.pass.uniforms.maxblur.value = this.maxblur; },
},
mounted: function mounted() {
if (!this.three.scene) {
console.error('Missing Scene');
}
if (!this.three.camera) {
console.error('Missing Camera');
}
var params = {
focus: this.focus,
aperture: this.aperture,
maxblur: this.maxblur,
width: this.three.size.width,
height: this.three.size.height,
};
var pass = new BokehPass$1(this.three.scene, this.three.camera, params);
this.passes.push(pass);
this.pass = pass;
},
__hmrId: 'BokehPass',
};
var FilmPass = {
extends: EffectPass,
props: {
noiseIntensity: {
type: Number,
default: 0.5,
},
scanlinesIntensity: {
type: Number,
default: 0.05,
},
scanlinesCount: {
type: Number,
default: 4096,
},
grayscale: {
type: Number,
default: 0,
},
},
watch: {
noiseIntensity: function noiseIntensity() { this.pass.uniforms.nIntensity.value = this.noiseIntensity; },
scanlinesIntensity: function scanlinesIntensity() { this.pass.uniforms.sIntensity.value = this.scanlinesIntensity; },
scanlinesCount: function scanlinesCount() { this.pass.uniforms.sCount.value = this.scanlinesCount; },
grayscale: function grayscale() { this.pass.uniforms.grayscale.value = this.grayscale; },
},
mounted: function mounted() {
var pass = new FilmPass$1(this.noiseIntensity, this.scanlinesIntensity, this.scanlinesCount, this.grayscale);
this.passes.push(pass);
this.pass = pass;
},
__hmrId: 'FilmPass',
};
2021-02-26 05:55:44 +08:00
var FXAAPass = {
extends: EffectPass,
mounted: function mounted() {
var pass = new ShaderPass(FXAAShader);
this.passes.push(pass);
this.pass = pass;
// resize will be called in three init
this.three.onAfterResize(this.resize);
},
unmounted: function unmounted() {
this.three.offAfterResize(this.resize);
},
methods: {
resize: function resize() {
var ref = this.pass.material.uniforms;
var resolution = ref.resolution;
resolution.value.x = 1 / this.three.size.width;
resolution.value.y = 1 / this.three.size.height;
},
},
__hmrId: 'FXAAPass',
};
2020-10-04 06:49:05 +08:00
var HalftonePass = {
extends: EffectPass,
props: {
shape: { type: Number, default: 1 },
radius: { type: Number, default: 4 },
rotateR: { type: Number, default: Math.PI / 12 * 1 },
rotateG: { type: Number, default: Math.PI / 12 * 2 },
rotateB: { type: Number, default: Math.PI / 12 * 3 },
scatter: { type: Number, default: 0 },
},
2020-09-17 05:54:14 +08:00
mounted: function mounted() {
2020-10-04 06:49:05 +08:00
var this$1 = this;
var pass = new HalftonePass$1(this.three.size.width, this.three.size.height, {});
['shape', 'radius', 'rotateR', 'rotateG', 'rotateB', 'scatter'].forEach(function (p) {
pass.uniforms[p].value = this$1[p];
watch(function () { return this$1[p]; }, function () {
pass.uniforms[p].value = this$1[p];
});
});
2020-09-17 05:54:14 +08:00
this.passes.push(pass);
this.pass = pass;
},
2020-10-04 06:49:05 +08:00
__hmrId: 'HalftonePass',
2020-09-17 05:54:14 +08:00
};
2021-02-26 05:55:44 +08:00
var SMAAPass = {
extends: EffectPass,
mounted: function mounted() {
// three size is not set yet, but this pass will be resized by effect composer
var pass = new SMAAPass$1(this.three.size.width, this.three.size.height);
this.passes.push(pass);
this.pass = pass;
},
__hmrId: 'SMAAPass',
};
var DefaultShader = {
uniforms: {},
vertexShader: "\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",
fragmentShader: "\n varying vec2 vUv;\n void main() {\n gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n }\n ",
};
// From https://github.com/evanw/glfx.js
var TiltShift = {
uniforms: {
tDiffuse: { value: null },
blurRadius: { value: 0 },
gradientRadius: { value: 0 },
start: { value: new Vector2() },
end: { value: new Vector2() },
delta: { value: new Vector2() },
texSize: { value: new Vector2() },
},
vertexShader: DefaultShader.vertexShader,
fragmentShader: "\n uniform sampler2D tDiffuse;\n uniform float blurRadius;\n uniform float gradientRadius;\n uniform vec2 start;\n uniform vec2 end;\n uniform vec2 delta;\n uniform vec2 texSize;\n varying vec2 vUv;\n\n float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n }\n\n void main() {\n vec4 color = vec4(0.0);\n float total = 0.0;\n\n /* randomize the lookup values to hide the fixed number of samples */\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n\n vec2 normal = normalize(vec2(start.y - end.y, end.x - start.x));\n float radius = smoothstep(0.0, 1.0, abs(dot(vUv * texSize - start, normal)) / gradientRadius) * blurRadius;\n for (float t = -30.0; t <= 30.0; t++) {\n float percent = (t + offset - 0.5) / 30.0;\n float weight = 1.0 - abs(percent);\n vec4 texel = texture2D(tDiffuse, vUv + delta / texSize * percent * radius);\n // vec4 texel2 = texture2D(tDiffuse, vUv + vec2(-delta.y, delta.x) / texSize * percent * radius);\n\n /* switch to pre-multiplied alpha to correctly blur transparent images */\n texel.rgb *= texel.a;\n // texel2.rgb *= texel2.a;\n\n color += texel * weight;\n total += 2.0 * weight;\n }\n\n gl_FragColor = color / total;\n\n /* switch back from pre-multiplied alpha */\n gl_FragColor.rgb /= gl_FragColor.a + 0.00001;\n }\n ",
};
var TiltShiftPass = {
2020-09-17 05:54:14 +08:00
extends: EffectPass,
props: {
2021-02-26 05:55:44 +08:00
blurRadius: { type: Number, default: 10 },
gradientRadius: { type: Number, default: 100 },
start: { type: Object, default: { x: 0, y: 100 } },
end: { type: Object, default: { x: 10, y: 100 } },
2020-09-17 05:54:14 +08:00
},
mounted: function mounted() {
2021-02-26 05:55:44 +08:00
var this$1 = this;
2020-10-04 06:49:05 +08:00
2021-02-26 05:55:44 +08:00
this.pass = new ShaderPass(TiltShift);
this.passes.push(this.pass);
this.pass1 = new ShaderPass(TiltShift);
this.passes.push(this.pass1);
var uniforms = this.uniforms = this.pass.uniforms;
var uniforms1 = this.uniforms1 = this.pass1.uniforms;
uniforms1.blurRadius = uniforms.blurRadius;
uniforms1.gradientRadius = uniforms.gradientRadius;
uniforms1.start = uniforms.start;
uniforms1.end = uniforms.end;
uniforms1.texSize = uniforms.texSize;
2021-03-08 04:17:46 +08:00
bindProp(this, 'blurRadius', uniforms.blurRadius, 'value');
bindProp(this, 'gradientRadius', uniforms.gradientRadius, 'value');
2021-02-26 05:55:44 +08:00
this.updateFocusLine();
['start', 'end'].forEach(function (p) {
2021-03-05 16:17:16 +08:00
watch(function () { return this$1[p]; }, this$1.updateFocusLine, { deep: true });
2021-02-26 05:55:44 +08:00
});
this.pass.setSize = function (width, height) {
uniforms.texSize.value.set(width, height);
};
},
methods: {
updateFocusLine: function updateFocusLine() {
this.uniforms.start.value.copy(this.start);
this.uniforms.end.value.copy(this.end);
var dv = new Vector2().copy(this.end).sub(this.start).normalize();
this.uniforms.delta.value.copy(dv);
this.uniforms1.delta.value.set(-dv.y, dv.x);
},
2020-09-17 05:54:14 +08:00
},
2021-02-26 05:55:44 +08:00
__hmrId: 'TiltShiftPass',
2020-09-17 05:54:14 +08:00
};
var UnrealBloomPass = {
extends: EffectPass,
props: {
2020-10-04 06:49:05 +08:00
strength: { type: Number, default: 1.5 },
radius: { type: Number, default: 0 },
threshold: { type: Number, default: 0 },
},
watch: {
strength: function strength() { this.pass.strength = this.strength; },
radius: function radius() { this.pass.radius = this.radius; },
threshold: function threshold() { this.pass.threshold = this.threshold; },
2020-09-17 05:54:14 +08:00
},
mounted: function mounted() {
var size = new Vector2(this.three.size.width, this.three.size.height);
var pass = new UnrealBloomPass$1(size, this.strength, this.radius, this.threshold);
this.passes.push(pass);
this.pass = pass;
},
2020-10-04 06:49:05 +08:00
__hmrId: 'UnrealBloomPass',
};
2021-02-26 05:55:44 +08:00
// From https://github.com/evanw/glfx.js
var ZoomBlur = {
uniforms: {
tDiffuse: { value: null },
center: { value: new Vector2(0.5, 0.5) },
strength: { value: 0 },
},
vertexShader: DefaultShader.vertexShader,
fragmentShader: "\n uniform sampler2D tDiffuse;\n uniform vec2 center;\n uniform float strength;\n varying vec2 vUv;\n\n float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n }\n \n void main() {\n vec4 color = vec4(0.0);\n float total = 0.0;\n vec2 toCenter = center - vUv;\n \n /* randomize the lookup values to hide the fixed number of samples */\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n \n for (float t = 0.0; t <= 40.0; t++) {\n float percent = (t + offset) / 40.0;\n float weight = 4.0 * (percent - percent * percent);\n vec4 texel = texture2D(tDiffuse, vUv + toCenter * percent * strength);\n\n /* switch to pre-multiplied alpha to correctly blur transparent images */\n texel.rgb *= texel.a;\n\n color += texel * weight;\n total += weight;\n }\n\n gl_FragColor = color / total;\n\n /* switch back from pre-multiplied alpha */\n gl_FragColor.rgb /= gl_FragColor.a + 0.00001;\n }\n ",
};
var ZoomBlurPass = {
extends: EffectPass,
props: {
center: { type: Object, default: { x: 0.5, y: 0.5 } },
strength: { type: Number, default: 0.5 },
},
mounted: function mounted() {
this.pass = new ShaderPass(ZoomBlur);
this.passes.push(this.pass);
var uniforms = this.uniforms = this.pass.uniforms;
2021-03-08 04:17:46 +08:00
bindProp(this, 'center', uniforms.center, 'value');
bindProp(this, 'strength', uniforms.strength, 'value');
2021-02-26 05:55:44 +08:00
},
__hmrId: 'ZoomBlurPass',
};
2020-10-04 06:49:05 +08:00
var TROIS = /*#__PURE__*/Object.freeze({
__proto__: null,
Renderer: Renderer,
2021-02-26 05:55:44 +08:00
OrthographicCamera: OrthographicCamera,
2020-10-04 06:49:05 +08:00
PerspectiveCamera: PerspectiveCamera,
Camera: PerspectiveCamera,
2021-02-26 05:55:44 +08:00
Group: Group,
2020-10-04 06:49:05 +08:00
Scene: Scene,
BoxGeometry: BoxGeometry,
CircleGeometry: CircleGeometry,
ConeGeometry: ConeGeometry,
CylinderGeometry: CylinderGeometry,
DodecahedronGeometry: DodecahedronGeometry,
IcosahedronGeometry: IcosahedronGeometry,
LatheGeometry: LatheGeometry,
OctahedronGeometry: OctahedronGeometry,
PolyhedronGeometry: PolyhedronGeometry,
RingGeometry: RingGeometry,
SphereGeometry: SphereGeometry,
TetrahedronGeometry: TetrahedronGeometry,
TorusGeometry: TorusGeometry,
TorusKnotGeometry: TorusKnotGeometry,
TubeGeometry: TubeGeometry,
AmbientLight: AmbientLight,
DirectionalLight: DirectionalLight,
2021-03-08 04:17:46 +08:00
HemisphereLight: HemisphereLight,
2020-10-04 06:49:05 +08:00
PointLight: PointLight,
2021-03-08 04:17:46 +08:00
RectAreaLight: RectAreaLight,
2020-10-04 06:49:05 +08:00
SpotLight: SpotLight,
BasicMaterial: BasicMaterial,
LambertMaterial: LambertMaterial,
2021-02-26 05:55:44 +08:00
MatcapMaterial: MatcapMaterial,
2020-10-04 06:49:05 +08:00
PhongMaterial: PhongMaterial,
PhysicalMaterial: PhysicalMaterial,
StandardMaterial: StandardMaterial,
SubSurfaceMaterial: SubSurfaceMaterial,
ToonMaterial: ToonMaterial,
2021-02-26 05:55:44 +08:00
Texture: Texture,
CubeTexture: CubeTexture,
2020-10-04 06:49:05 +08:00
Mesh: Mesh,
Box: Box,
Circle: Circle,
Cone: Cone,
Cylinder: Cylinder,
Dodecahedron: Dodecahedron,
Icosahedron: Icosahedron,
Lathe: Lathe,
Octahedron: Octahedron,
Plane: Plane,
Polyhedron: Polyhedron,
Ring: Ring,
Sphere: Sphere,
Tetrahedron: Tetrahedron,
Text: Text,
Torus: Torus,
TorusKnot: TorusKnot,
Tube: Tube,
Gem: Gem,
Image: Image,
InstancedMesh: InstancedMesh,
MirrorMesh: MirrorMesh,
RefractionMesh: RefractionMesh,
Sprite: Sprite,
EffectComposer: EffectComposer,
RenderPass: RenderPass,
BokehPass: BokehPass,
FilmPass: FilmPass,
2021-02-26 05:55:44 +08:00
FXAAPass: FXAAPass,
2020-10-04 06:49:05 +08:00
HalftonePass: HalftonePass,
2021-02-26 05:55:44 +08:00
SMAAPass: SMAAPass,
TiltShiftPass: TiltShiftPass,
2020-10-04 06:49:05 +08:00
UnrealBloomPass: UnrealBloomPass,
2021-02-26 05:55:44 +08:00
ZoomBlurPass: ZoomBlurPass,
2020-10-04 06:49:05 +08:00
setFromProp: setFromProp,
2021-03-08 04:17:46 +08:00
bindProp: bindProp,
2020-10-04 06:49:05 +08:00
propsValues: propsValues,
lerp: lerp,
2021-02-26 05:55:44 +08:00
lerpv2: lerpv2,
2020-10-04 06:49:05 +08:00
lerpv3: lerpv3,
2021-02-26 05:55:44 +08:00
limit: limit,
getMatcapUrl: getMatcapUrl
2020-10-04 06:49:05 +08:00
});
var TroisJSVuePlugin = {
install: function (app) {
var comps = [
'Camera',
2021-02-26 05:55:44 +08:00
'OrthographicCamera',
2020-10-04 06:49:05 +08:00
'PerspectiveCamera',
'Renderer',
'Scene',
2021-02-26 05:55:44 +08:00
'Group',
2020-10-04 06:49:05 +08:00
'BoxGeometry',
'CircleGeometry',
'ConeGeometry',
'CylinderGeometry',
'DodecahedronGeometry',
'IcosahedronGeometry',
'LatheGeometry',
'OctahedronGeometry',
'PolyhedronGeometry',
'RingGeometry',
'SphereGeometry',
'TetrahedronGeometry',
'TorusGeometry',
'TorusKnotGeometry',
'TubeGeometry',
'AmbientLight',
'DirectionalLight',
2021-03-08 04:17:46 +08:00
'HemisphereLight',
2020-10-04 06:49:05 +08:00
'PointLight',
2021-03-08 04:17:46 +08:00
'RectAreaLight',
2020-10-04 06:49:05 +08:00
'SpotLight',
'BasicMaterial',
'LambertMaterial',
2021-02-26 05:55:44 +08:00
'MatcapMaterial',
2020-10-04 06:49:05 +08:00
'PhongMaterial',
'PhysicalMaterial',
'ShaderMaterial',
'StandardMaterial',
'SubSurfaceMaterial',
'ToonMaterial',
2021-02-26 05:55:44 +08:00
'Texture',
'CubeTexture',
2020-10-04 06:49:05 +08:00
'Box',
'Circle',
'Cone',
'Cylinder',
'Dodecahedron',
'Icosahedron',
'Mesh',
'Lathe',
'Octahedron',
'Plane',
'Polyhedron',
'Ring',
'Sphere',
'Tetrahedron',
'Text',
'Torus',
'TorusKnot',
'Tube',
'Gem',
'Image',
'InstancedMesh',
'MirrorMesh',
'RefractionMesh',
'Sprite',
'BokehPass',
'EffectComposer',
'FilmPass',
2021-02-26 05:55:44 +08:00
'FXAAPass',
2020-10-04 06:49:05 +08:00
'HalftonePass',
'RenderPass',
'SAOPass',
2021-02-26 05:55:44 +08:00
'SMAAPass',
'TiltShiftPass',
2020-10-04 06:49:05 +08:00
'UnrealBloomPass',
2021-02-26 05:55:44 +08:00
'ZoomBlurPass',
2020-10-04 06:49:05 +08:00
'GLTFViewer' ];
comps.forEach(function (comp) {
app.component(comp, TROIS[comp]);
});
},
2020-09-17 05:54:14 +08:00
};
2021-03-08 04:17:46 +08:00
function createApp(params) {
return createApp$1(params).use(TroisJSVuePlugin);
}
export { AmbientLight, BasicMaterial, BokehPass, Box, BoxGeometry, PerspectiveCamera as Camera, Circle, CircleGeometry, Cone, ConeGeometry, CubeTexture, Cylinder, CylinderGeometry, DirectionalLight, Dodecahedron, DodecahedronGeometry, EffectComposer, FXAAPass, FilmPass, Gem, Group, HalftonePass, HemisphereLight, Icosahedron, IcosahedronGeometry, Image, InstancedMesh, LambertMaterial, Lathe, LatheGeometry, MatcapMaterial, Mesh, MirrorMesh, Octahedron, OctahedronGeometry, OrthographicCamera, PerspectiveCamera, PhongMaterial, PhysicalMaterial, Plane, PointLight, Polyhedron, PolyhedronGeometry, RectAreaLight, RefractionMesh, RenderPass, Renderer, Ring, RingGeometry, SMAAPass, Scene, Sphere, SphereGeometry, SpotLight, Sprite, StandardMaterial, SubSurfaceMaterial, Tetrahedron, TetrahedronGeometry, Text, Texture, TiltShiftPass, ToonMaterial, Torus, TorusGeometry, TorusKnot, TorusKnotGeometry, TroisJSVuePlugin, Tube, TubeGeometry, UnrealBloomPass, ZoomBlurPass, bindProp, createApp, getMatcapUrl, lerp, lerpv2, lerpv3, limit, propsValues, setFromProp };
2020-09-17 05:54:14 +08:00
//# sourceMappingURL=trois.module.js.map