@anov/3d-ability 0.0.4-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/city/flyinglead.d.ts +0 -0
- package/dist/city/flyinglead.js +0 -0
- package/dist/city/radar.d.ts +0 -0
- package/dist/city/radar.js +0 -0
- package/dist/city/scanning.d.ts +0 -0
- package/dist/city/scanning.js +0 -0
- package/dist/city/surroundLine.d.ts +0 -0
- package/dist/city/surroundLine.js +0 -0
- package/dist/core/mouseDrawe.d.ts +2 -0
- package/dist/core/mouseDrawe.js +1 -0
- package/dist/environment/cloud/cloud.d.ts +1 -0
- package/dist/environment/cloud/cloud.js +1 -0
- package/dist/environment/cloud/index.d.ts +7 -0
- package/dist/environment/cloud/index.js +60 -0
- package/dist/environment/rain.d.ts +20 -0
- package/dist/environment/rain.js +44 -0
- package/dist/environment/rainShder/index.d.ts +8 -0
- package/dist/environment/rainShder/index.js +70 -0
- package/dist/environment/rainShder/shader.d.ts +26 -0
- package/dist/environment/rainShder/shader.js +28 -0
- package/dist/environment/shaderCloud/cloudMaterial.d.ts +10 -0
- package/dist/environment/shaderCloud/cloudMaterial.js +39 -0
- package/dist/environment/shaderCloud/index.d.ts +2 -0
- package/dist/environment/shaderCloud/index.js +45 -0
- package/dist/environment/shaderCloud/shader.d.ts +5 -0
- package/dist/environment/shaderCloud/shader.js +6 -0
- package/dist/environment/showShder/index.d.ts +8 -0
- package/dist/environment/showShder/index.js +73 -0
- package/dist/environment/showShder/shader.d.ts +28 -0
- package/dist/environment/showShder/shader.js +32 -0
- package/dist/environment/sky/index.d.ts +12 -0
- package/dist/environment/sky/index.js +116 -0
- package/dist/environment/snow.d.ts +16 -0
- package/dist/environment/snow.js +45 -0
- package/dist/environment/sun/index.d.ts +13 -0
- package/dist/environment/sun/index.js +76 -0
- package/dist/environment/utils/points.d.ts +26 -0
- package/dist/environment/utils/points.js +55 -0
- package/dist/environment/volumetricCloud/cloudMaterial.d.ts +3 -0
- package/dist/environment/volumetricCloud/cloudMaterial.js +60 -0
- package/dist/environment/volumetricCloud/inex.d.ts +8 -0
- package/dist/environment/volumetricCloud/inex.js +42 -0
- package/dist/helper/view/index.d.ts +40 -0
- package/dist/helper/view/index.js +385 -0
- package/dist/helper/view/utils.d.ts +6 -0
- package/dist/helper/view/utils.js +91 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +20 -0
- package/dist/material/pristineGridMaterial/index.d.ts +20 -0
- package/dist/material/pristineGridMaterial/index.js +102 -0
- package/dist/material/pristineGridMaterial/shader/fragment.d.ts +2 -0
- package/dist/material/pristineGridMaterial/shader/fragment.js +1 -0
- package/dist/material/pristineGridMaterial/shader/vertex.d.ts +2 -0
- package/dist/material/pristineGridMaterial/shader/vertex.js +1 -0
- package/dist/postEffects/bloomPass.d.ts +5 -0
- package/dist/postEffects/bloomPass.js +30 -0
- package/dist/postEffects/index.d.ts +11 -0
- package/dist/postEffects/index.js +32 -0
- package/dist/postEffects/outlinePass.d.ts +16 -0
- package/dist/postEffects/outlinePass.js +51 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +3 -0
- package/package.json +29 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
10
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
13
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
14
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
15
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
16
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
18
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
19
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
20
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
22
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
23
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
24
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
|
+
import { BackSide, Clock, Euler, Mesh, MeshBasicMaterial, Object3D, OrthographicCamera, Quaternion, Raycaster, SphereGeometry, Vector2, Vector3, Vector4 } from '@anov/3d-core';
|
|
26
|
+
import { getAxesLines, getAxesSpritePoints, getDomContainer } from "./utils";
|
|
27
|
+
var _Array$fill$map = Array(6).fill(0).map(function (_, i) {
|
|
28
|
+
return i;
|
|
29
|
+
}),
|
|
30
|
+
_Array$fill$map2 = _slicedToArray(_Array$fill$map, 6),
|
|
31
|
+
POS_X = _Array$fill$map2[0],
|
|
32
|
+
POS_Y = _Array$fill$map2[1],
|
|
33
|
+
POS_Z = _Array$fill$map2[2],
|
|
34
|
+
NEG_X = _Array$fill$map2[3],
|
|
35
|
+
NEG_Y = _Array$fill$map2[4],
|
|
36
|
+
NEG_Z = _Array$fill$map2[5];
|
|
37
|
+
var clock = new Clock();
|
|
38
|
+
var targetPosition = new Vector3();
|
|
39
|
+
var targetQuaternion = new Quaternion();
|
|
40
|
+
var euler = new Euler();
|
|
41
|
+
var q1 = new Quaternion();
|
|
42
|
+
var q2 = new Quaternion();
|
|
43
|
+
var point = new Vector3();
|
|
44
|
+
var dim = 128;
|
|
45
|
+
var turnRate = 2 * Math.PI;
|
|
46
|
+
var raycaster = new Raycaster();
|
|
47
|
+
var mouse = new Vector2();
|
|
48
|
+
var mouseStart = new Vector2();
|
|
49
|
+
var mouseAngle = new Vector2();
|
|
50
|
+
var dummy = new Object3D();
|
|
51
|
+
var radius = 0;
|
|
52
|
+
var ViewHelper = /*#__PURE__*/function (_Object3D) {
|
|
53
|
+
_inherits(ViewHelper, _Object3D);
|
|
54
|
+
var _super = _createSuper(ViewHelper);
|
|
55
|
+
function ViewHelper(camera, renderer) {
|
|
56
|
+
var _this2;
|
|
57
|
+
var _this;
|
|
58
|
+
var placement = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bottom-right';
|
|
59
|
+
var size = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 128;
|
|
60
|
+
_classCallCheck(this, ViewHelper);
|
|
61
|
+
_this = _super.call(this);
|
|
62
|
+
_defineProperty(_assertThisInitialized(_this), "camera", void 0);
|
|
63
|
+
_defineProperty(_assertThisInitialized(_this), "orthoCamera", new OrthographicCamera(-1.8, 1.8, 1.8, -1.8, 0, 4));
|
|
64
|
+
_defineProperty(_assertThisInitialized(_this), "isViewHelper", true);
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "animating", false);
|
|
66
|
+
_defineProperty(_assertThisInitialized(_this), "target", new Vector3());
|
|
67
|
+
_defineProperty(_assertThisInitialized(_this), "backgroundSphere", void 0);
|
|
68
|
+
_defineProperty(_assertThisInitialized(_this), "axesLines", void 0);
|
|
69
|
+
_defineProperty(_assertThisInitialized(_this), "spritePoints", void 0);
|
|
70
|
+
_defineProperty(_assertThisInitialized(_this), "domElement", void 0);
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "domContainer", void 0);
|
|
72
|
+
_defineProperty(_assertThisInitialized(_this), "domRect", void 0);
|
|
73
|
+
_defineProperty(_assertThisInitialized(_this), "dragging", false);
|
|
74
|
+
_defineProperty(_assertThisInitialized(_this), "renderer", void 0);
|
|
75
|
+
_defineProperty(_assertThisInitialized(_this), "controls", void 0);
|
|
76
|
+
_defineProperty(_assertThisInitialized(_this), "controlsChangeEvent", void 0);
|
|
77
|
+
_defineProperty(_assertThisInitialized(_this), "viewport", new Vector4());
|
|
78
|
+
_defineProperty(_assertThisInitialized(_this), "offsetHeight", 0);
|
|
79
|
+
_this.renderer = renderer;
|
|
80
|
+
_this.camera = camera;
|
|
81
|
+
_this.domElement = renderer.domElement;
|
|
82
|
+
_this.orthoCamera.position.set(0, 0, 2);
|
|
83
|
+
_this.backgroundSphere = getBackgroundSphere();
|
|
84
|
+
_this.axesLines = getAxesLines();
|
|
85
|
+
_this.spritePoints = getAxesSpritePoints();
|
|
86
|
+
_this.domContainer = getDomContainer(placement, size);
|
|
87
|
+
|
|
88
|
+
// This may cause confusion if the parent isn't the body and doesn't have a `position:relative`
|
|
89
|
+
_this.domElement.parentElement.appendChild(_this.domContainer);
|
|
90
|
+
_this.domRect = _this.domContainer.getBoundingClientRect();
|
|
91
|
+
_this.startListening();
|
|
92
|
+
_this.controlsChangeEvent = {
|
|
93
|
+
listener: function listener() {
|
|
94
|
+
return _this.updateOrientation();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
_this.update();
|
|
98
|
+
_this.updateOrientation();
|
|
99
|
+
(_this2 = _this).add.apply(_this2, [_this.backgroundSphere, _this.axesLines].concat(_toConsumableArray(_this.spritePoints)));
|
|
100
|
+
return _this;
|
|
101
|
+
}
|
|
102
|
+
_createClass(ViewHelper, [{
|
|
103
|
+
key: "startListening",
|
|
104
|
+
value: function startListening() {
|
|
105
|
+
var _this3 = this;
|
|
106
|
+
this.domContainer.onpointerdown = function (e) {
|
|
107
|
+
return _this3.onPointerDown(e);
|
|
108
|
+
};
|
|
109
|
+
this.domContainer.onpointermove = function (e) {
|
|
110
|
+
return _this3.onPointerMove(e);
|
|
111
|
+
};
|
|
112
|
+
this.domContainer.onpointerleave = function () {
|
|
113
|
+
return _this3.onPointerLeave();
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "onPointerDown",
|
|
118
|
+
value: function onPointerDown(e) {
|
|
119
|
+
var _this4 = this;
|
|
120
|
+
var drag = function drag(e) {
|
|
121
|
+
if (!_this4.dragging && isClick(e, mouseStart)) return;
|
|
122
|
+
if (!_this4.dragging) {
|
|
123
|
+
resetSprites(_this4.spritePoints);
|
|
124
|
+
_this4.dragging = true;
|
|
125
|
+
}
|
|
126
|
+
mouseAngle.set(e.clientX, e.clientY).sub(mouseStart).multiplyScalar(1 / _this4.domRect.width * Math.PI);
|
|
127
|
+
_this4.rotation.x = clamp(
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
129
|
+
rotationStart.x + mouseAngle.y, Math.PI / -2 + 0.001, Math.PI / 2 - 0.001);
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
131
|
+
_this4.rotation.y = rotationStart.y + mouseAngle.x;
|
|
132
|
+
_this4.updateMatrixWorld();
|
|
133
|
+
q1.copy(_this4.quaternion).invert();
|
|
134
|
+
_this4.camera.position.set(0, 0, 1).applyQuaternion(q1).multiplyScalar(radius).add(_this4.target);
|
|
135
|
+
_this4.camera.rotation.setFromQuaternion(q1);
|
|
136
|
+
_this4.updateOrientation(false);
|
|
137
|
+
};
|
|
138
|
+
var endDrag = function endDrag() {
|
|
139
|
+
document.removeEventListener('pointermove', drag, false);
|
|
140
|
+
document.removeEventListener('pointerup', endDrag, false);
|
|
141
|
+
if (!_this4.dragging) {
|
|
142
|
+
_this4.handleClick(e);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
_this4.dragging = false;
|
|
146
|
+
};
|
|
147
|
+
if (this.animating === true) return;
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
mouseStart.set(e.clientX, e.clientY);
|
|
150
|
+
var rotationStart = euler.copy(this.rotation);
|
|
151
|
+
setRadius(this.camera, this.target);
|
|
152
|
+
document.addEventListener('pointermove', drag, false);
|
|
153
|
+
document.addEventListener('pointerup', endDrag, false);
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: "onPointerMove",
|
|
157
|
+
value: function onPointerMove(e) {
|
|
158
|
+
if (this.dragging) return;
|
|
159
|
+
this.backgroundSphere.material.opacity = 0.2;
|
|
160
|
+
this.handleHover(e);
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "onPointerLeave",
|
|
164
|
+
value: function onPointerLeave() {
|
|
165
|
+
if (this.dragging) return;
|
|
166
|
+
this.backgroundSphere.material.opacity = 0;
|
|
167
|
+
resetSprites(this.spritePoints);
|
|
168
|
+
this.domContainer.style.cursor = '';
|
|
169
|
+
}
|
|
170
|
+
}, {
|
|
171
|
+
key: "handleClick",
|
|
172
|
+
value: function handleClick(e) {
|
|
173
|
+
var object = getIntersectionObject(e, this.domRect, this.orthoCamera, this.spritePoints);
|
|
174
|
+
if (!object) return;
|
|
175
|
+
this.setOrientation(object.userData.type);
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
key: "handleHover",
|
|
179
|
+
value: function handleHover(e) {
|
|
180
|
+
var object = getIntersectionObject(e, this.domRect, this.orthoCamera, this.spritePoints);
|
|
181
|
+
resetSprites(this.spritePoints);
|
|
182
|
+
if (!object) {
|
|
183
|
+
this.domContainer.style.cursor = '';
|
|
184
|
+
} else {
|
|
185
|
+
object.material.map.offset.x = 0.5;
|
|
186
|
+
object.scale.multiplyScalar(1.2);
|
|
187
|
+
this.domContainer.style.cursor = 'pointer';
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}, {
|
|
191
|
+
key: "setControls",
|
|
192
|
+
value: function setControls(controls) {
|
|
193
|
+
if (this.controls) {
|
|
194
|
+
this.controls.removeEventListener('change', this.controlsChangeEvent.listener);
|
|
195
|
+
this.target = new Vector3();
|
|
196
|
+
}
|
|
197
|
+
if (!controls) return;
|
|
198
|
+
this.controls = controls;
|
|
199
|
+
controls.addEventListener('change', this.controlsChangeEvent.listener);
|
|
200
|
+
this.target = controls.target;
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
key: "render",
|
|
204
|
+
value: function render() {
|
|
205
|
+
var delta = clock.getDelta();
|
|
206
|
+
if (this.animating) this.animate(delta);
|
|
207
|
+
var _this$domElement$getB = this.domElement.getBoundingClientRect(),
|
|
208
|
+
width = _this$domElement$getB.width,
|
|
209
|
+
height = _this$domElement$getB.height;
|
|
210
|
+
var autoClear = this.renderer.autoClear;
|
|
211
|
+
this.renderer.autoClear = false;
|
|
212
|
+
this.renderer.setViewport(width - dim, height - dim, dim, dim);
|
|
213
|
+
this.renderer.render(this, this.orthoCamera);
|
|
214
|
+
this.renderer.setViewport(this.viewport);
|
|
215
|
+
this.renderer.autoClear = autoClear;
|
|
216
|
+
}
|
|
217
|
+
}, {
|
|
218
|
+
key: "updateOrientation",
|
|
219
|
+
value: function updateOrientation() {
|
|
220
|
+
var fromCamera = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
221
|
+
if (fromCamera) {
|
|
222
|
+
this.quaternion.copy(this.camera.quaternion).invert();
|
|
223
|
+
this.updateMatrixWorld();
|
|
224
|
+
}
|
|
225
|
+
updateSpritesOpacity(this.spritePoints, this.camera);
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
key: "update",
|
|
229
|
+
value: function update() {
|
|
230
|
+
this.domRect = this.domContainer.getBoundingClientRect();
|
|
231
|
+
this.offsetHeight = this.domElement.offsetHeight;
|
|
232
|
+
setRadius(this.camera, this.target);
|
|
233
|
+
this.renderer.getViewport(this.viewport);
|
|
234
|
+
this.updateOrientation();
|
|
235
|
+
}
|
|
236
|
+
}, {
|
|
237
|
+
key: "animate",
|
|
238
|
+
value: function animate(delta) {
|
|
239
|
+
var step = delta * turnRate;
|
|
240
|
+
|
|
241
|
+
// animate position by doing a slerp and then scaling the position on the unit sphere
|
|
242
|
+
|
|
243
|
+
q1.rotateTowards(q2, step);
|
|
244
|
+
this.camera.position.set(0, 0, 1).applyQuaternion(q1).multiplyScalar(radius).add(this.target);
|
|
245
|
+
|
|
246
|
+
// animate orientation
|
|
247
|
+
|
|
248
|
+
this.camera.quaternion.rotateTowards(targetQuaternion, step);
|
|
249
|
+
this.updateOrientation();
|
|
250
|
+
if (q1.angleTo(q2) === 0) this.animating = false;
|
|
251
|
+
}
|
|
252
|
+
}, {
|
|
253
|
+
key: "setOrientation",
|
|
254
|
+
value: function setOrientation(orientation) {
|
|
255
|
+
prepareAnimationData(this.camera, this.target, orientation);
|
|
256
|
+
this.animating = true;
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "dispose",
|
|
260
|
+
value: function dispose() {
|
|
261
|
+
this.axesLines.geometry.dispose();
|
|
262
|
+
this.axesLines.material.dispose();
|
|
263
|
+
this.backgroundSphere.geometry.dispose();
|
|
264
|
+
this.backgroundSphere.material.dispose();
|
|
265
|
+
this.spritePoints.forEach(function (sprite) {
|
|
266
|
+
sprite.material.map.dispose();
|
|
267
|
+
sprite.material.dispose();
|
|
268
|
+
});
|
|
269
|
+
this.domContainer.remove();
|
|
270
|
+
if (this.controls) {
|
|
271
|
+
this.controls.removeEventListener('change', this.controlsChangeEvent.listener);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}]);
|
|
275
|
+
return ViewHelper;
|
|
276
|
+
}(Object3D);
|
|
277
|
+
function getBackgroundSphere() {
|
|
278
|
+
var geometry = new SphereGeometry(1.6);
|
|
279
|
+
var sphere = new Mesh(geometry, new MeshBasicMaterial({
|
|
280
|
+
color: 0xFFFFFF,
|
|
281
|
+
side: BackSide,
|
|
282
|
+
transparent: true,
|
|
283
|
+
opacity: 0,
|
|
284
|
+
depthTest: false
|
|
285
|
+
}));
|
|
286
|
+
return sphere;
|
|
287
|
+
}
|
|
288
|
+
function prepareAnimationData(camera, focusPoint, axis) {
|
|
289
|
+
switch (axis) {
|
|
290
|
+
case '+x':
|
|
291
|
+
targetPosition.set(1, 0, 0);
|
|
292
|
+
targetQuaternion.setFromEuler(new Euler(0, Math.PI * 0.5, 0));
|
|
293
|
+
break;
|
|
294
|
+
case '+y':
|
|
295
|
+
targetPosition.set(0, 1, 0);
|
|
296
|
+
targetQuaternion.setFromEuler(new Euler(-Math.PI * 0.5, 0, 0));
|
|
297
|
+
break;
|
|
298
|
+
case '+z':
|
|
299
|
+
targetPosition.set(0, 0, 1);
|
|
300
|
+
targetQuaternion.setFromEuler(new Euler());
|
|
301
|
+
break;
|
|
302
|
+
case '-x':
|
|
303
|
+
targetPosition.set(-1, 0, 0);
|
|
304
|
+
targetQuaternion.setFromEuler(new Euler(0, -Math.PI * 0.5, 0));
|
|
305
|
+
break;
|
|
306
|
+
case '-y':
|
|
307
|
+
targetPosition.set(0, -1, 0);
|
|
308
|
+
targetQuaternion.setFromEuler(new Euler(Math.PI * 0.5, 0, 0));
|
|
309
|
+
break;
|
|
310
|
+
case '-z':
|
|
311
|
+
targetPosition.set(0, 0, -1);
|
|
312
|
+
targetQuaternion.setFromEuler(new Euler(0, Math.PI, 0));
|
|
313
|
+
break;
|
|
314
|
+
default:
|
|
315
|
+
console.error('ViewHelper: Invalid axis.');
|
|
316
|
+
}
|
|
317
|
+
setRadius(camera, focusPoint);
|
|
318
|
+
prepareQuaternions(camera, focusPoint);
|
|
319
|
+
}
|
|
320
|
+
function setRadius(camera, focusPoint) {
|
|
321
|
+
radius = camera.position.distanceTo(focusPoint);
|
|
322
|
+
}
|
|
323
|
+
function prepareQuaternions(camera, focusPoint) {
|
|
324
|
+
targetPosition.multiplyScalar(radius).add(focusPoint);
|
|
325
|
+
dummy.position.copy(focusPoint);
|
|
326
|
+
dummy.lookAt(camera.position);
|
|
327
|
+
q1.copy(dummy.quaternion);
|
|
328
|
+
dummy.lookAt(targetPosition);
|
|
329
|
+
q2.copy(dummy.quaternion);
|
|
330
|
+
}
|
|
331
|
+
function updatePointer(e, domRect, orthoCamera) {
|
|
332
|
+
mouse.x = (e.clientX - domRect.left) / domRect.width * 2 - 1;
|
|
333
|
+
mouse.y = -((e.clientY - domRect.top) / domRect.height) * 2 + 1;
|
|
334
|
+
raycaster.setFromCamera(mouse, orthoCamera);
|
|
335
|
+
}
|
|
336
|
+
function isClick(e, startCoords) {
|
|
337
|
+
var threshold = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
338
|
+
return Math.abs(e.clientX - startCoords.x) < threshold && Math.abs(e.clientY - startCoords.y) < threshold;
|
|
339
|
+
}
|
|
340
|
+
function getIntersectionObject(event, domRect, orthoCamera, intersectionObjects) {
|
|
341
|
+
updatePointer(event, domRect, orthoCamera);
|
|
342
|
+
var intersects = raycaster.intersectObjects(intersectionObjects);
|
|
343
|
+
if (!intersects.length) return null;
|
|
344
|
+
var intersection = intersects[0];
|
|
345
|
+
return intersection.object;
|
|
346
|
+
}
|
|
347
|
+
function resetSprites(sprites) {
|
|
348
|
+
var i = sprites.length;
|
|
349
|
+
while (i--) {
|
|
350
|
+
var scale = i < 3 ? 0.6 : 0.4;
|
|
351
|
+
sprites[i].scale.set(scale, scale, scale);
|
|
352
|
+
sprites[i].material.map.offset.x = 1;
|
|
353
|
+
}
|
|
354
|
+
// sprites.forEach((sprite) => (sprite.material.map!.offset.x = 1));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function updateSpritesOpacity(sprites, camera) {
|
|
358
|
+
point.set(0, 0, 1);
|
|
359
|
+
point.applyQuaternion(camera.quaternion);
|
|
360
|
+
if (point.x >= 0) {
|
|
361
|
+
sprites[POS_X].material.opacity = 1;
|
|
362
|
+
sprites[NEG_X].material.opacity = 0.5;
|
|
363
|
+
} else {
|
|
364
|
+
sprites[POS_X].material.opacity = 0.5;
|
|
365
|
+
sprites[NEG_X].material.opacity = 1;
|
|
366
|
+
}
|
|
367
|
+
if (point.y >= 0) {
|
|
368
|
+
sprites[POS_Y].material.opacity = 1;
|
|
369
|
+
sprites[NEG_Y].material.opacity = 0.5;
|
|
370
|
+
} else {
|
|
371
|
+
sprites[POS_Y].material.opacity = 0.5;
|
|
372
|
+
sprites[NEG_Y].material.opacity = 1;
|
|
373
|
+
}
|
|
374
|
+
if (point.z >= 0) {
|
|
375
|
+
sprites[POS_Z].material.opacity = 1;
|
|
376
|
+
sprites[NEG_Z].material.opacity = 0.5;
|
|
377
|
+
} else {
|
|
378
|
+
sprites[POS_Z].material.opacity = 0.5;
|
|
379
|
+
sprites[NEG_Z].material.opacity = 1;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function clamp(num, min, max) {
|
|
383
|
+
return Math.min(Math.max(num, min), max);
|
|
384
|
+
}
|
|
385
|
+
export default ViewHelper;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BufferGeometry, Color, LineBasicMaterial, LineSegments, Sprite, SpriteMaterial } from '@anov/3d-core';
|
|
2
|
+
import type { DomPlacement } from './index';
|
|
3
|
+
export declare const getDomContainer: (placement: DomPlacement, size: number) => HTMLDivElement;
|
|
4
|
+
export declare const getAxesLines: () => LineSegments<BufferGeometry<import("@anov/3d-core").NormalBufferAttributes>, LineBasicMaterial>;
|
|
5
|
+
export declare const getSpriteMaterial: (color: Color, text?: 'x' | 'y' | 'z' | null) => SpriteMaterial;
|
|
6
|
+
export declare const getAxesSpritePoints: () => Sprite[];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { BufferAttribute, BufferGeometry, CanvasTexture, Color, LineBasicMaterial, LineSegments, RepeatWrapping, Sprite, SpriteMaterial } from '@anov/3d-core';
|
|
8
|
+
var axesColors = [new Color(0xFF3653), new Color(0x8ADB00), new Color(0x2C8FFF)];
|
|
9
|
+
export var getDomContainer = function getDomContainer(placement, size) {
|
|
10
|
+
var div = document.createElement('div');
|
|
11
|
+
var style = div.style;
|
|
12
|
+
style.height = "".concat(size, "px");
|
|
13
|
+
style.width = "".concat(size, "px");
|
|
14
|
+
style.borderRadius = '100%';
|
|
15
|
+
style.position = 'absolute';
|
|
16
|
+
var _placement$split = placement.split('-'),
|
|
17
|
+
_placement$split2 = _slicedToArray(_placement$split, 2),
|
|
18
|
+
y = _placement$split2[0],
|
|
19
|
+
x = _placement$split2[1];
|
|
20
|
+
style.transform = '';
|
|
21
|
+
style.left = x === 'left' ? '0' : x === 'center' ? '50%' : '';
|
|
22
|
+
style.right = x === 'right' ? '0' : '';
|
|
23
|
+
style.transform += x === 'center' ? 'translateX(-50%)' : '';
|
|
24
|
+
style.top = y === 'top' ? '0' : y === 'bottom' ? '' : '50%';
|
|
25
|
+
style.bottom = y === 'bottom' ? '0' : '';
|
|
26
|
+
style.transform += y === 'center' ? 'translateY(-50%)' : '';
|
|
27
|
+
return div;
|
|
28
|
+
};
|
|
29
|
+
export var getAxesLines = function getAxesLines() {
|
|
30
|
+
var distance = 0.9;
|
|
31
|
+
var position = Array(3).fill(0).map(function (_, i) {
|
|
32
|
+
return [!i ? distance : 0, i === 1 ? distance : 0, i === 2 ? distance : 0, 0, 0, 0];
|
|
33
|
+
}).flat();
|
|
34
|
+
var color = Array(6).fill(0).map(function (_, i) {
|
|
35
|
+
return i < 2 ? axesColors[0].toArray() : i < 4 ? axesColors[1].toArray() : axesColors[2].toArray();
|
|
36
|
+
}).flat();
|
|
37
|
+
var geometry = new BufferGeometry();
|
|
38
|
+
geometry.setAttribute('position', new BufferAttribute(new Float32Array(position), 3));
|
|
39
|
+
geometry.setAttribute('color', new BufferAttribute(new Float32Array(color), 3));
|
|
40
|
+
return new LineSegments(geometry, new LineBasicMaterial({
|
|
41
|
+
linewidth: 3,
|
|
42
|
+
vertexColors: true
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
export var getSpriteMaterial = function getSpriteMaterial(color) {
|
|
46
|
+
var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
47
|
+
var canvas = document.createElement('canvas');
|
|
48
|
+
canvas.width = 128;
|
|
49
|
+
canvas.height = 64;
|
|
50
|
+
var context = canvas.getContext('2d');
|
|
51
|
+
context.beginPath();
|
|
52
|
+
context.arc(32, 32, 32, 0, 2 * Math.PI);
|
|
53
|
+
context.closePath();
|
|
54
|
+
context.fillStyle = color.getStyle();
|
|
55
|
+
context.fill();
|
|
56
|
+
context.beginPath();
|
|
57
|
+
context.arc(96, 32, 32, 0, 2 * Math.PI);
|
|
58
|
+
context.closePath();
|
|
59
|
+
context.fillStyle = '#FFF';
|
|
60
|
+
context.fill();
|
|
61
|
+
if (text !== null) {
|
|
62
|
+
context.font = 'bold 48px Arial';
|
|
63
|
+
context.textAlign = 'center';
|
|
64
|
+
context.fillStyle = '#000';
|
|
65
|
+
context.fillText(text.toUpperCase(), 32, 48);
|
|
66
|
+
context.fillText(text.toUpperCase(), 96, 48);
|
|
67
|
+
}
|
|
68
|
+
var texture = new CanvasTexture(canvas);
|
|
69
|
+
texture.wrapS = texture.wrapT = RepeatWrapping;
|
|
70
|
+
texture.repeat.x = 0.5;
|
|
71
|
+
return new SpriteMaterial({
|
|
72
|
+
map: texture,
|
|
73
|
+
toneMapped: false,
|
|
74
|
+
transparent: true
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export var getAxesSpritePoints = function getAxesSpritePoints() {
|
|
78
|
+
var axes = ['x', 'y', 'z'];
|
|
79
|
+
return Array(6).fill(0).map(function (_, i) {
|
|
80
|
+
var isPositive = i < 3;
|
|
81
|
+
var sign = isPositive ? '+' : '-';
|
|
82
|
+
var axis = axes[i % 3];
|
|
83
|
+
var color = axesColors[i % 3];
|
|
84
|
+
var sprite = new Sprite(getSpriteMaterial(color, isPositive ? axis : null));
|
|
85
|
+
sprite.userData.type = "".concat(sign).concat(axis);
|
|
86
|
+
sprite.scale.setScalar(isPositive ? 0.6 : 0.4);
|
|
87
|
+
sprite.position[axis] = isPositive ? 1.2 : -1.2;
|
|
88
|
+
sprite.renderOrder = 1;
|
|
89
|
+
return sprite;
|
|
90
|
+
});
|
|
91
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SceneControl } from '@anov/3d-core';
|
|
2
|
+
import { mouseDraweLine } from './core/mouseDrawe';
|
|
3
|
+
import { createSnow } from './environment/snow';
|
|
4
|
+
import { createRain } from './environment/rain';
|
|
5
|
+
import createCloud from './environment/cloud';
|
|
6
|
+
import { initPostEffects } from './postEffects';
|
|
7
|
+
import createHighSelectedTool from './postEffects/outlinePass';
|
|
8
|
+
import { createSun } from './environment/sun';
|
|
9
|
+
import GridMaterial from './material/pristineGridMaterial';
|
|
10
|
+
import ViewHelper from './helper/view';
|
|
11
|
+
import createSkySystem from './environment/sky';
|
|
12
|
+
import createVolumetricCloud from './environment/volumetricCloud/inex';
|
|
13
|
+
import createSkyCloud from './environment/shaderCloud/index';
|
|
14
|
+
import Snow from './environment/showShder';
|
|
15
|
+
import Rain from './environment/rainShder';
|
|
16
|
+
export { SceneControl, // todo remove
|
|
17
|
+
mouseDraweLine, createRain, createSnow, createCloud, createSun, createSkySystem, createVolumetricCloud, createSkyCloud, Snow, Rain, initPostEffects, // effect
|
|
18
|
+
createHighSelectedTool, GridMaterial, ViewHelper, };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SceneControl } from '@anov/3d-core';
|
|
2
|
+
import { mouseDraweLine } from "./core/mouseDrawe";
|
|
3
|
+
import { createSnow } from "./environment/snow";
|
|
4
|
+
import { createRain } from "./environment/rain";
|
|
5
|
+
import createCloud from "./environment/cloud";
|
|
6
|
+
import { initPostEffects } from "./postEffects";
|
|
7
|
+
import createHighSelectedTool from "./postEffects/outlinePass";
|
|
8
|
+
import { createSun } from "./environment/sun";
|
|
9
|
+
import GridMaterial from "./material/pristineGridMaterial";
|
|
10
|
+
import ViewHelper from "./helper/view";
|
|
11
|
+
import createSkySystem from "./environment/sky";
|
|
12
|
+
import createVolumetricCloud from "./environment/volumetricCloud/inex";
|
|
13
|
+
import createSkyCloud from "./environment/shaderCloud/index";
|
|
14
|
+
import Snow from "./environment/showShder";
|
|
15
|
+
import Rain from "./environment/rainShder";
|
|
16
|
+
export { SceneControl,
|
|
17
|
+
// todo remove
|
|
18
|
+
mouseDraweLine, createRain, createSnow, createCloud, createSun, createSkySystem, createVolumetricCloud, createSkyCloud, Snow, Rain, initPostEffects,
|
|
19
|
+
// effect
|
|
20
|
+
createHighSelectedTool, GridMaterial, ViewHelper };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as THREE from '@anov/3d-core';
|
|
2
|
+
declare type GridMaterialParameters = {
|
|
3
|
+
name?: string;
|
|
4
|
+
side?: THREE.Side;
|
|
5
|
+
transparent?: boolean;
|
|
6
|
+
theme?: THREE.Color;
|
|
7
|
+
majorLineWidth?: number;
|
|
8
|
+
minorLineWidth?: number;
|
|
9
|
+
axisLineWidth?: number;
|
|
10
|
+
majorGridDiv?: number;
|
|
11
|
+
gridDiv?: number;
|
|
12
|
+
majorLineColor?: THREE.Color;
|
|
13
|
+
minorLineColor?: THREE.Color;
|
|
14
|
+
xAxisColor?: THREE.Color;
|
|
15
|
+
zAxisColor?: THREE.Color;
|
|
16
|
+
};
|
|
17
|
+
declare class GridMaterial extends THREE.Material {
|
|
18
|
+
constructor(options?: GridMaterialParameters);
|
|
19
|
+
}
|
|
20
|
+
export default GridMaterial;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
3
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
5
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
8
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
9
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
11
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
12
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
13
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
14
|
+
import * as THREE from '@anov/3d-core';
|
|
15
|
+
import vertexShader from "./shader/vertex";
|
|
16
|
+
import fragmentShader from "./shader/fragment";
|
|
17
|
+
var GridMaterial = /*#__PURE__*/function (_THREE$Material) {
|
|
18
|
+
_inherits(GridMaterial, _THREE$Material);
|
|
19
|
+
var _super = _createSuper(GridMaterial);
|
|
20
|
+
function GridMaterial(options) {
|
|
21
|
+
var _this;
|
|
22
|
+
_classCallCheck(this, GridMaterial);
|
|
23
|
+
_this = _super.call(this);
|
|
24
|
+
var _ref = options || {},
|
|
25
|
+
side = _ref.side,
|
|
26
|
+
transparent = _ref.transparent,
|
|
27
|
+
theme = _ref.theme,
|
|
28
|
+
majorLineWidth = _ref.majorLineWidth,
|
|
29
|
+
minorLineWidth = _ref.minorLineWidth,
|
|
30
|
+
axisLineWidth = _ref.axisLineWidth,
|
|
31
|
+
name = _ref.name,
|
|
32
|
+
majorGridDiv = _ref.majorGridDiv,
|
|
33
|
+
gridDiv = _ref.gridDiv,
|
|
34
|
+
majorLineColor = _ref.majorLineColor,
|
|
35
|
+
minorLineColor = _ref.minorLineColor,
|
|
36
|
+
xAxisColor = _ref.xAxisColor,
|
|
37
|
+
zAxisColor = _ref.zAxisColor;
|
|
38
|
+
var _majorLineWidth = majorLineWidth !== null && majorLineWidth !== void 0 ? majorLineWidth : 0.04;
|
|
39
|
+
var _minorLineWidth = minorLineWidth !== null && minorLineWidth !== void 0 ? minorLineWidth : 0.01;
|
|
40
|
+
var _axisLineWidth = axisLineWidth !== null && axisLineWidth !== void 0 ? axisLineWidth : 0.15;
|
|
41
|
+
var _majorGridDiv = majorGridDiv !== null && majorGridDiv !== void 0 ? majorGridDiv : 10.0;
|
|
42
|
+
var _gridDiv = gridDiv !== null && gridDiv !== void 0 ? gridDiv : 4.0;
|
|
43
|
+
var _majorLineColor = majorLineColor !== null && majorLineColor !== void 0 ? majorLineColor : new THREE.Color();
|
|
44
|
+
var _minorLineColor = minorLineColor !== null && minorLineColor !== void 0 ? minorLineColor : new THREE.Color();
|
|
45
|
+
var _xAxisColor = xAxisColor !== null && xAxisColor !== void 0 ? xAxisColor : new THREE.Color(1, 0.3, 0.3);
|
|
46
|
+
var _zAxisColor = zAxisColor !== null && zAxisColor !== void 0 ? zAxisColor : new THREE.Color(0.3, 0.3, 1);
|
|
47
|
+
return _possibleConstructorReturn(_this, new THREE.ShaderMaterial({
|
|
48
|
+
side: side !== null && side !== void 0 ? side : THREE.DoubleSide,
|
|
49
|
+
glslVersion: THREE.GLSL3,
|
|
50
|
+
transparent: transparent !== null && transparent !== void 0 ? transparent : true,
|
|
51
|
+
name: name !== null && name !== void 0 ? name : 'GridMaterial',
|
|
52
|
+
vertexShader: vertexShader,
|
|
53
|
+
fragmentShader: fragmentShader,
|
|
54
|
+
uniforms: {
|
|
55
|
+
u_baseAlpha: {
|
|
56
|
+
value: 0.5
|
|
57
|
+
},
|
|
58
|
+
u_majorLineWidth: {
|
|
59
|
+
value: _majorLineWidth
|
|
60
|
+
},
|
|
61
|
+
// Example default value , 大网格线宽
|
|
62
|
+
u_minorLineWidth: {
|
|
63
|
+
value: _minorLineWidth
|
|
64
|
+
},
|
|
65
|
+
// Example default value ,小网格线宽
|
|
66
|
+
u_axisLineWidth: {
|
|
67
|
+
value: _axisLineWidth
|
|
68
|
+
},
|
|
69
|
+
// Example default value ,坐标轴线宽
|
|
70
|
+
u_majorGridDiv: {
|
|
71
|
+
value: _majorGridDiv
|
|
72
|
+
},
|
|
73
|
+
// Example default value, 大网格间隔
|
|
74
|
+
u_gridDiv: {
|
|
75
|
+
value: _gridDiv
|
|
76
|
+
},
|
|
77
|
+
// Example default value, 小网格间隔
|
|
78
|
+
u_majorLineColor: {
|
|
79
|
+
value: _majorLineColor
|
|
80
|
+
},
|
|
81
|
+
// White color
|
|
82
|
+
u_minorLineColor: {
|
|
83
|
+
value: _minorLineColor
|
|
84
|
+
},
|
|
85
|
+
// White color
|
|
86
|
+
u_baseColor: {
|
|
87
|
+
value: theme !== null && theme !== void 0 ? theme : new THREE.Color('#707070')
|
|
88
|
+
},
|
|
89
|
+
// Black color
|
|
90
|
+
u_xAxisColor: {
|
|
91
|
+
value: _xAxisColor
|
|
92
|
+
},
|
|
93
|
+
// Red color
|
|
94
|
+
u_zAxisColor: {
|
|
95
|
+
value: _zAxisColor
|
|
96
|
+
} // Blue color
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
return _createClass(GridMaterial);
|
|
101
|
+
}(THREE.Material);
|
|
102
|
+
export default GridMaterial;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: "\nprecision highp float;\n\n// Varyings from the vertex shader\nin vec2 v_uv;\nin vec2 v_worldPos;\n\n// Uniforms\nuniform float u_majorLineWidth, u_minorLineWidth, u_axisLineWidth;\nuniform vec3 u_majorLineColor, u_minorLineColor, u_baseColor;\nuniform vec3 u_xAxisColor, u_zAxisColor;\nuniform float u_majorGridDiv, u_baseAlpha;\nuniform vec2 u_resolution;\n\n// Output color\nout vec4 gColor;\n\nfloat saturate(float value) {\nreturn clamp(value, 0.0, 1.0);\n}\n\nvoid main() {\n // Calculate derivatives for anti-aliasing\nvec4 uvDDXY = vec4(dFdx(v_uv), dFdy(v_uv));\nvec2 uvDeriv = vec2(length(uvDDXY.xz), length(uvDDXY.yw));\n\nvec4 worldPosDDXY = vec4(dFdx(v_worldPos), dFdy(v_worldPos));\nvec2 worldPosDeriv = vec2(length(worldPosDDXY.xz), length(worldPosDDXY.yw));\n\n // Axis lines calculation\nfloat axisLineWidth = max(u_majorLineWidth, u_axisLineWidth);\n\nvec2 axisDrawWidth = vec2(axisLineWidth) + worldPosDeriv * 0.5; // Adjust for AA\nvec2 axisLineAA = worldPosDeriv * 1.5;\nvec2 axisLines2 = smoothstep(axisDrawWidth + axisLineAA, axisDrawWidth - axisLineAA, abs(v_worldPos.xy * 2.0));\naxisLines2 *= (axisLineWidth / axisDrawWidth);\n\n // Major grid lines\nfloat div = max(2.0, round(u_majorGridDiv));\nvec2 majorUVDeriv = worldPosDeriv / div;\nfloat majorLineWidth = u_majorLineWidth / div;\nvec2 majorDrawWidth = clamp(vec2(majorLineWidth), majorUVDeriv, vec2(0.5));\nvec2 majorLineAA = majorUVDeriv * 1.5;\nvec2 majorGridUV = 1.0 - abs(fract(v_worldPos.xy / div) * 2.0 - 1.0);\nvec2 majorGrid2 = smoothstep(majorDrawWidth + majorLineAA, majorDrawWidth - majorLineAA, majorGridUV);\nmajorGrid2 *= (majorLineWidth / majorDrawWidth);\n\n // Minor grid lines\nfloat minorLineWidth = u_minorLineWidth;\nbool minorInvertLine = minorLineWidth > 0.5;\nfloat minorTargetWidth = minorInvertLine ? 1.0 - minorLineWidth : minorLineWidth;\nvec2 minorDrawWidth = clamp(vec2(minorTargetWidth), uvDeriv, vec2(0.5));\nvec2 minorLineAA = uvDeriv * 1.5;\nvec2 minorGridUV = abs(fract(v_uv) * 2.0 - 1.0);\nminorGridUV = minorInvertLine ? minorGridUV : 1.0 - minorGridUV;\nvec2 minorGrid2 = smoothstep(minorDrawWidth + minorLineAA, minorDrawWidth - minorLineAA, minorGridUV);\nminorGrid2 *= (minorTargetWidth / minorDrawWidth);\n\nif(max(axisLines2.x, axisLines2.y) > 0.) {\n // If we're drawing axis lines, don't draw grid lines on axis\nmajorGrid2 = vec2(0.);\nminorGrid2 = vec2(0.);\n}\n\n // Combine minor and major grid lines\nfloat minorGrid = mix(minorGrid2.x, 1.0, minorGrid2.y);\nfloat majorGrid = mix(majorGrid2.x, 1.0, majorGrid2.y);\n\n // Final color calculations for grid\nvec3 gridColor = mix(u_baseColor, u_minorLineColor, minorGrid);\ngridColor = mix(gridColor, u_majorLineColor, majorGrid);\nfloat gridAlpha = u_baseAlpha;\n\n // Apply base alpha to the grid lines\nif(minorGrid > 0.0) {\ngridAlpha = saturate(mix(gridAlpha, 1.0, minorGrid));\n}\nif(majorGrid > 0.0) {\ngridAlpha = saturate(mix(gridAlpha, 1.0, majorGrid));\n}\n\n // Apply axis color to the axis lines\nvec3 axisColor = mix(vec3(1.), u_xAxisColor, step(0.5, abs(v_worldPos.x)));\naxisColor = mix(axisColor, u_zAxisColor, step(0.5, abs(v_worldPos.y)));\n\nvec3 finalColor = mix(gridColor, axisColor, max(axisLines2.x, axisLines2.y));\n\nif(max(axisLines2.x, axisLines2.y) > 0.) {\ngridAlpha = saturate(mix(gridAlpha, 1.0, max(axisLines2.x, axisLines2.y)));\n}\n\n // Set the final fragment color\ngColor = vec4(finalColor, gridAlpha);\n}\n";
|
|
2
|
+
export default _default;
|