@realsee/vreo 0.2.0-alpha.13 → 0.2.0-alpha.14
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/docs/assets/search.js +1 -1
- package/docs/classes/Player.AudioLike.html +2 -2
- package/docs/classes/Player.Controller.html +3 -3
- package/docs/classes/Player.Player-1.html +3 -3
- package/docs/classes/Player.VideoAgentMesh.html +11 -11
- package/docs/classes/Player.VideoAgentScene.html +1 -1
- package/docs/demo/assets/{AppReact.388465e9.js → AppReact.5d77c4d8.js} +1 -1
- package/docs/demo/assets/default.3cf9974e.js +64 -0
- package/docs/demo/assets/{default.0350c336.css → default.70243c83.css} +1 -1
- package/docs/demo/assets/{dynamic.3f7479e4.js → dynamic.ee28990e.js} +1 -1
- package/docs/demo/assets/{examples.02abaf01.js → examples.294e0a10.js} +1 -1
- package/docs/demo/assets/{index.485f13f7.js → index.c55a0972.js} +1 -1
- package/docs/demo/assets/{main.0b6b41ab.js → main.8fadf245.js} +1 -1
- package/docs/demo/assets/{react.b14dadc7.js → react.ed4b53f9.js} +1 -1
- package/docs/demo/assets/{vendor.d3e0753c.js → vendor.5714cf27.js} +2 -2
- package/docs/demo/examples.html +4 -4
- package/docs/demo/index-react-dynamic.html +6 -6
- package/docs/demo/index-react.html +6 -6
- package/docs/demo/index.html +5 -5
- package/docs/enums/Player.InfoPanelStyleEnum.html +1 -1
- package/docs/enums/Player.InfoPanelTypeEnum.html +1 -1
- package/docs/enums/Player.PanoEffectEnum.html +1 -1
- package/docs/enums/Player.PanoTagEnum.html +1 -1
- package/docs/enums/Player.PanoTagStyleEnum.html +2 -2
- package/docs/enums/Player.VreoKeyframeEnum.html +12 -12
- package/docs/enums/fivePlugins.CameraMovementEffect.html +1 -1
- package/docs/enums/fivePlugins.Rotation.html +1 -1
- package/docs/interfaces/Player.CustomVreoKeyframeProps.html +1 -1
- package/docs/interfaces/Player.PlayerConfigs.html +2 -2
- package/docs/interfaces/Player.Vertex.html +1 -1
- package/docs/interfaces/Player.VideoAgentMeshOptions.html +1 -1
- package/docs/interfaces/Player.VreoKeyframe.html +1 -1
- package/docs/interfaces/Player.VreoUnit.html +1 -1
- package/docs/interfaces/Player.VreoVideo.html +1 -1
- package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +4 -0
- package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +1 -1
- package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +2 -2
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +1 -1
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +1 -1
- package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +1 -1
- package/docs/interfaces/fivePlugins.Vector3Position.html +3 -0
- package/docs/interfaces/react.VreoActionCallbacks.html +6 -6
- package/docs/interfaces/react.VreoProviderProps.html +1 -1
- package/docs/modules/Player.html +17 -15
- package/docs/modules/custom.html +1 -1
- package/docs/modules/fivePlugins.html +5 -2
- package/docs/modules/react.html +1 -1
- package/lib/Player/modules/keyframes/PanoTextLabel/index.d.ts +3 -0
- package/lib/Player/modules/keyframes/PanoTextLabel/index.js +96 -43
- package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.d.ts +2 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/centerPoint.js +12 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.d.ts +7 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/createResizeObserver.js +32 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.d.ts +3 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/evenNumber.js +11 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/index.d.ts +56 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/index.js +275 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.d.ts +7 -0
- package/lib/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.js +18 -0
- package/lib/typings/VreoUnit.d.ts +11 -0
- package/package.json +1 -1
- package/resources/Player/modules/keyframes/PanoTextLabel/index.tsx +87 -34
- package/resources/fivePlugins/CSS3DRenderPlugin/centerPoint.ts +5 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/createResizeObserver.ts +17 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/evenNumber.ts +4 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/index.ts +254 -0
- package/resources/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.ts +5 -0
- package/resources/typings/VreoUnit.ts +13 -1
- package/stylesheets/default.css +5 -1
- package/docs/demo/assets/default.f03f1cdd.js +0 -64
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { FivePlugin } from '@realsee/five';
|
|
2
|
+
import { Vector3 } from 'three';
|
|
3
|
+
import { CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer';
|
|
4
|
+
/**
|
|
5
|
+
* 三维向量
|
|
6
|
+
*/
|
|
7
|
+
export interface Vector3Position {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
z: number;
|
|
11
|
+
}
|
|
12
|
+
export declare type CSS3DRenderPluginParameterType = undefined;
|
|
13
|
+
export interface CSS3DRenderPluginExportType {
|
|
14
|
+
/**
|
|
15
|
+
* @description: 根据传入的四个点位创建一个3d dom容器,可以通过ReactDom.render()的方式将react组件放到容器中
|
|
16
|
+
* @param {Five} five
|
|
17
|
+
* @param {Vector3[] | Vector3Position[]} points: 矩形四个点坐标
|
|
18
|
+
* @param {number} config.ratio: 1px对应多少米,默认为 0.002,即1px对应2mm
|
|
19
|
+
* @param {number} config.dpr: dpr, 默认为1
|
|
20
|
+
* @param {HTMLElement} config.container: HTMLElement
|
|
21
|
+
* @param {number} config.autoRender: 默认为true,如果需要手动render则传false
|
|
22
|
+
* @param {'front' | 'behind'} config.mode: 两种模式
|
|
23
|
+
* @param {HTMLElement} config.behindFiveContainer: 如果config.mode为'behind',需要传入容器,并确保此容器位five下方,且中间没有其他dom元素遮挡
|
|
24
|
+
* @return {{ container: HTMLElement; dispose: () => void }}: container: dom容器, dispose: 清理函数
|
|
25
|
+
*/
|
|
26
|
+
create3DDomContainer: (points: Vector3[] | Vector3Position[], config?: {
|
|
27
|
+
ratio?: number;
|
|
28
|
+
dpr?: number;
|
|
29
|
+
autoRender?: boolean;
|
|
30
|
+
container?: HTMLElement;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
} & ({
|
|
33
|
+
mode?: 'front';
|
|
34
|
+
} | {
|
|
35
|
+
mode: 'behind';
|
|
36
|
+
behindFiveContainer: HTMLElement;
|
|
37
|
+
})) => {
|
|
38
|
+
container: HTMLElement;
|
|
39
|
+
dispose: () => void;
|
|
40
|
+
css3DObject: CSS3DObject;
|
|
41
|
+
render?: () => void;
|
|
42
|
+
} | void;
|
|
43
|
+
/**
|
|
44
|
+
* @description: 销毁所有的渲染内容
|
|
45
|
+
* @return {void}
|
|
46
|
+
*/
|
|
47
|
+
disposeAll: () => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* **CSS3DRenderPlugin** 提供矩形区域(三维空间四个坐标点),你可以在此矩形区域中渲染 DOM 内容。
|
|
51
|
+
* 实现原理参考[CSS3DRenderer](https://threejs.org/docs/index.html?q=CSS3D#examples/en/renderers/CSS3DRenderer)。
|
|
52
|
+
*
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
export declare const CSS3DRenderPlugin: FivePlugin<CSS3DRenderPluginParameterType, CSS3DRenderPluginExportType>;
|
|
56
|
+
export default CSS3DRenderPlugin;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = exports.CSS3DRenderPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var THREE = _interopRequireWildcard(require("three"));
|
|
11
|
+
|
|
12
|
+
var _CSS3DRenderer = require("three/examples/jsm/renderers/CSS3DRenderer");
|
|
13
|
+
|
|
14
|
+
var _evenNumber = _interopRequireDefault(require("./evenNumber"));
|
|
15
|
+
|
|
16
|
+
var _centerPoint = _interopRequireDefault(require("./centerPoint"));
|
|
17
|
+
|
|
18
|
+
var _transformPositionToVector = _interopRequireDefault(require("./transformPositionToVector3"));
|
|
19
|
+
|
|
20
|
+
var _createResizeObserver = _interopRequireDefault(require("./createResizeObserver"));
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
23
|
+
|
|
24
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
25
|
+
|
|
26
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* **CSS3DRenderPlugin** 提供矩形区域(三维空间四个坐标点),你可以在此矩形区域中渲染 DOM 内容。
|
|
30
|
+
* 实现原理参考[CSS3DRenderer](https://threejs.org/docs/index.html?q=CSS3D#examples/en/renderers/CSS3DRenderer)。
|
|
31
|
+
*
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
var CSS3DRenderPlugin = function CSS3DRenderPlugin(five) {
|
|
35
|
+
var state = {
|
|
36
|
+
disposeCallbacks: []
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var create3DDomContainer = function create3DDomContainer() {
|
|
40
|
+
var _five$model, _five$model2, _config$autoRender;
|
|
41
|
+
|
|
42
|
+
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
43
|
+
params[_key] = arguments[_key];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var points = params[0].map(function (point) {
|
|
47
|
+
return point instanceof THREE.Vector3 ? point : (0, _transformPositionToVector["default"])(point);
|
|
48
|
+
});
|
|
49
|
+
var config = params[1];
|
|
50
|
+
if ((points === null || points === void 0 ? void 0 : points.length) < 4) return console.error('points must be equal or greater than than 4');
|
|
51
|
+
if (!(five !== null && five !== void 0 && (_five$model = five.model) !== null && _five$model !== void 0 && _five$model.loaded)) return console.error('five.model.loaded is: ', five === null || five === void 0 ? void 0 : (_five$model2 = five.model) === null || _five$model2 === void 0 ? void 0 : _five$model2.loaded);
|
|
52
|
+
var fiveElement = five.getElement();
|
|
53
|
+
if (!fiveElement) return console.error('five.getElement() is ' + fiveElement);
|
|
54
|
+
var disposers = [];
|
|
55
|
+
var ratio = (config === null || config === void 0 ? void 0 : config.ratio) || 0.00216;
|
|
56
|
+
if (ratio <= 0.00215) console.warn('if you need click css3DElement on safari, ratio must be greater than 0.00215');
|
|
57
|
+
var dpr = (config === null || config === void 0 ? void 0 : config.dpr) || 1;
|
|
58
|
+
var mode = (config === null || config === void 0 ? void 0 : config.mode) || 'front';
|
|
59
|
+
var autoRender = (_config$autoRender = config === null || config === void 0 ? void 0 : config.autoRender) !== null && _config$autoRender !== void 0 ? _config$autoRender : true;
|
|
60
|
+
var behindFiveContainer = (config === null || config === void 0 ? void 0 : config.behindFiveContainer) || fiveElement.parentElement || document.body;
|
|
61
|
+
var container = (config === null || config === void 0 ? void 0 : config.container) || document.createElement('div');
|
|
62
|
+
container.classList.add('__Dnalogel-plugin--CSS3DRenderPlugin'); // 获取css3DObject, 如果mode为behind的话,一起获取mesh
|
|
63
|
+
|
|
64
|
+
var _createObject = createObject(points, {
|
|
65
|
+
ratio: ratio,
|
|
66
|
+
dpr: dpr,
|
|
67
|
+
container: container,
|
|
68
|
+
mode: mode
|
|
69
|
+
}),
|
|
70
|
+
css3DObject = _createObject.css3DObject,
|
|
71
|
+
mesh = _createObject.mesh; // ======= INIT START =======
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
var resizeObserver;
|
|
75
|
+
var frontModeUnInited = mode === 'front' && !state.frontMode;
|
|
76
|
+
var behindModeUnInited = mode === 'behind' && !state.behindMode;
|
|
77
|
+
var inited = !(frontModeUnInited || behindModeUnInited);
|
|
78
|
+
var stopRenderFlag = false;
|
|
79
|
+
var requestAnimationFrameId = null;
|
|
80
|
+
|
|
81
|
+
if (behindModeUnInited) {
|
|
82
|
+
state.behindMode = {
|
|
83
|
+
scene: new THREE.Scene(),
|
|
84
|
+
css3DRenderer: new _CSS3DRenderer.CSS3DRenderer()
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (frontModeUnInited) {
|
|
89
|
+
state.frontMode = {
|
|
90
|
+
scene: new THREE.Scene(),
|
|
91
|
+
css3DRenderer: new _CSS3DRenderer.CSS3DRenderer()
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var _ref = mode === 'behind' ? state.behindMode : state.frontMode,
|
|
96
|
+
scene = _ref.scene,
|
|
97
|
+
css3DRenderer = _ref.css3DRenderer;
|
|
98
|
+
|
|
99
|
+
var render = function () {
|
|
100
|
+
if (!inited) {
|
|
101
|
+
var css3DRendererSetSize = function css3DRendererSetSize() {
|
|
102
|
+
// 这里evenNumber策略是遇到奇数会加1,不知道为啥会触发滚动条显示,导致fiveElement变小,fiveElement变小又触发了这里的resize,宽高变小,滚动条消失,然后又触发resize。。。无限循环
|
|
103
|
+
// 为了规避上面这种情况,evenNumber设置了一个参数,遇到奇数可选择减一
|
|
104
|
+
var rendererWidth = (0, _evenNumber["default"])(fiveElement.clientWidth, {
|
|
105
|
+
smaller: true
|
|
106
|
+
});
|
|
107
|
+
var rendererHeight = (0, _evenNumber["default"])(fiveElement.clientHeight, {
|
|
108
|
+
smaller: true
|
|
109
|
+
});
|
|
110
|
+
css3DRenderer.setSize(rendererWidth, rendererHeight);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
css3DRendererSetSize();
|
|
114
|
+
resizeObserver = (0, _createResizeObserver["default"])(css3DRendererSetSize, fiveElement);
|
|
115
|
+
css3DRenderer.domElement.style.position = 'absolute';
|
|
116
|
+
css3DRenderer.domElement.style.top = '0';
|
|
117
|
+
css3DRenderer.domElement.style.userSelect = 'none';
|
|
118
|
+
css3DRenderer.domElement.style.pointerEvents = 'none';
|
|
119
|
+
|
|
120
|
+
var renderEveryFrame = function renderEveryFrame() {
|
|
121
|
+
if (stopRenderFlag) return;
|
|
122
|
+
requestAnimationFrameId = requestAnimationFrame(renderEveryFrame);
|
|
123
|
+
css3DRenderer.render(scene, five.camera);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return function () {
|
|
127
|
+
var _resizeObserver, _resizeObserver$obser;
|
|
128
|
+
|
|
129
|
+
scene.add(css3DObject);
|
|
130
|
+
(_resizeObserver = resizeObserver) === null || _resizeObserver === void 0 ? void 0 : (_resizeObserver$obser = _resizeObserver.observe) === null || _resizeObserver$obser === void 0 ? void 0 : _resizeObserver$obser.call(_resizeObserver);
|
|
131
|
+
renderEveryFrame();
|
|
132
|
+
|
|
133
|
+
if (mode === 'behind' && mesh) {
|
|
134
|
+
five.scene.add(mesh);
|
|
135
|
+
disposers.push(function () {
|
|
136
|
+
return mesh && five.scene.remove(mesh);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
} else {
|
|
141
|
+
return function () {
|
|
142
|
+
scene.add(css3DObject);
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}();
|
|
146
|
+
|
|
147
|
+
if (frontModeUnInited) {
|
|
148
|
+
var wrapper = fiveElement.parentElement || document.body;
|
|
149
|
+
wrapper.appendChild(css3DRenderer.domElement);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (behindModeUnInited) {
|
|
153
|
+
var _wrapper = behindFiveContainer;
|
|
154
|
+
|
|
155
|
+
_wrapper.appendChild(css3DRenderer.domElement);
|
|
156
|
+
} // ======= INIT END =======
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
var dispose = function dispose() {
|
|
160
|
+
stopRenderFlag = true;
|
|
161
|
+
disposers.forEach(function (d) {
|
|
162
|
+
return d === null || d === void 0 ? void 0 : d();
|
|
163
|
+
});
|
|
164
|
+
scene.remove(css3DObject);
|
|
165
|
+
if (typeof requestAnimationFrameId === 'number') cancelAnimationFrame(requestAnimationFrameId);
|
|
166
|
+
|
|
167
|
+
if (scene.children.length === 0) {
|
|
168
|
+
css3DRenderer.domElement.remove();
|
|
169
|
+
if (mode === 'front') state.frontMode = undefined;
|
|
170
|
+
if (mode === 'behind') state.behindMode = undefined;
|
|
171
|
+
|
|
172
|
+
if (!state.behindMode && !state.frontMode) {
|
|
173
|
+
var _resizeObserver2, _resizeObserver2$unob;
|
|
174
|
+
|
|
175
|
+
(_resizeObserver2 = resizeObserver) === null || _resizeObserver2 === void 0 ? void 0 : (_resizeObserver2$unob = _resizeObserver2.unobserve) === null || _resizeObserver2$unob === void 0 ? void 0 : _resizeObserver2$unob.call(_resizeObserver2);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return true;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
var idx = state.disposeCallbacks.findIndex(function (item) {
|
|
183
|
+
return item === dispose;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
if (idx !== -1) {
|
|
187
|
+
state.disposeCallbacks.splice(idx, 1);
|
|
188
|
+
} else {
|
|
189
|
+
state.disposeCallbacks.push(dispose);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (autoRender) render();
|
|
193
|
+
return {
|
|
194
|
+
container: container,
|
|
195
|
+
dispose: dispose,
|
|
196
|
+
css3DObject: css3DObject,
|
|
197
|
+
render: autoRender ? undefined : render
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
var createObject = function createObject(points, config) {
|
|
202
|
+
var ratio = config.ratio,
|
|
203
|
+
dpr = config.dpr,
|
|
204
|
+
element = config.container,
|
|
205
|
+
mode = config.mode;
|
|
206
|
+
var planeWidth = points[0].distanceTo(points[1]);
|
|
207
|
+
var planeHeight = points[1].distanceTo(points[2]);
|
|
208
|
+
var domWidthPx = (0, _evenNumber["default"])(planeWidth / ratio * dpr);
|
|
209
|
+
var domHeightPx = (0, _evenNumber["default"])(planeHeight / ratio * dpr);
|
|
210
|
+
var css3DObject = new _CSS3DRenderer.CSS3DObject(element);
|
|
211
|
+
css3DObject.scale.set(ratio, ratio, ratio);
|
|
212
|
+
element.style.width = domWidthPx + 'px';
|
|
213
|
+
element.style.height = domHeightPx + 'px';
|
|
214
|
+
element.style.pointerEvents = 'none';
|
|
215
|
+
var centerPosition = (0, _centerPoint["default"])(points[0], points[2]);
|
|
216
|
+
var vector01 = points[1].clone().sub(points[0]); // 点0 -> 点1 的向量
|
|
217
|
+
|
|
218
|
+
var vector12 = points[2].clone().sub(points[1]); // 点1 -> 点2 的向量
|
|
219
|
+
// 旋转
|
|
220
|
+
|
|
221
|
+
var rotateXAngle = new THREE.Vector3(0, 1, 0).angleTo(new THREE.Vector3(0, vector12.y, vector12.z));
|
|
222
|
+
var rotateYAngle = new THREE.Vector3(1, 0, 0).angleTo(new THREE.Vector3(vector01.x, 0, vector01.z));
|
|
223
|
+
var rotateZAngle = vector01.angleTo(new THREE.Vector3(vector01.x, 0, vector01.z));
|
|
224
|
+
/**
|
|
225
|
+
* [0,1,0] => [0,0,1] 为rolate Worldx正方向
|
|
226
|
+
* [0,0,1] => [0,1,0] 为rolate Worldy正方向
|
|
227
|
+
* [0,1,1] => [-1,0,0] 为rolate Worldz正方向
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
var rotateX = (vector12.z > 0 ? -1 : 1) * rotateXAngle;
|
|
231
|
+
var rotateY = (vector01.z < 0 ? 1 : -1) * rotateYAngle;
|
|
232
|
+
var rotateZ = (vector01.x > 0 && vector01.y < 0 || vector01.x < 0 && vector01.y > 0 ? -1 : 1) * rotateZAngle;
|
|
233
|
+
css3DObject.rotateOnWorldAxis(new THREE.Vector3(1, 0, 0), rotateX); // x
|
|
234
|
+
|
|
235
|
+
css3DObject.rotateOnWorldAxis(new THREE.Vector3(0, 1, 0), rotateY); // y
|
|
236
|
+
|
|
237
|
+
css3DObject.rotateOnWorldAxis(new THREE.Vector3(0, 0, 1), rotateZ); // z
|
|
238
|
+
|
|
239
|
+
css3DObject.position.set(centerPosition.x, centerPosition.y, centerPosition.z);
|
|
240
|
+
var mesh;
|
|
241
|
+
|
|
242
|
+
if (mode === 'behind') {
|
|
243
|
+
var material = new THREE.MeshBasicMaterial({
|
|
244
|
+
opacity: 0,
|
|
245
|
+
transparent: false,
|
|
246
|
+
side: THREE.DoubleSide
|
|
247
|
+
});
|
|
248
|
+
var geometry = new THREE.PlaneGeometry(domWidthPx, domHeightPx);
|
|
249
|
+
mesh = new THREE.Mesh(geometry, material);
|
|
250
|
+
mesh.name = 'CSS3DRenderPlugin-mesh';
|
|
251
|
+
mesh.position.copy(css3DObject.position);
|
|
252
|
+
mesh.rotation.copy(css3DObject.rotation);
|
|
253
|
+
mesh.scale.copy(css3DObject.scale);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
css3DObject: css3DObject,
|
|
258
|
+
mesh: mesh
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
create3DDomContainer: create3DDomContainer,
|
|
264
|
+
disposeAll: function disposeAll() {
|
|
265
|
+
state.disposeCallbacks.forEach(function (d) {
|
|
266
|
+
return d === null || d === void 0 ? void 0 : d();
|
|
267
|
+
});
|
|
268
|
+
state.disposeCallbacks = [];
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
exports.CSS3DRenderPlugin = CSS3DRenderPlugin;
|
|
274
|
+
var _default = CSS3DRenderPlugin;
|
|
275
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _three = require("three");
|
|
9
|
+
|
|
10
|
+
var transformPositionToVector3 = function transformPositionToVector3(_ref) {
|
|
11
|
+
var x = _ref.x,
|
|
12
|
+
y = _ref.y,
|
|
13
|
+
z = _ref.z;
|
|
14
|
+
return new _three.Vector3(x, y, z);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var _default = transformPositionToVector3;
|
|
18
|
+
exports["default"] = _default;
|
|
@@ -172,12 +172,23 @@ export declare type ModelVideoData = {
|
|
|
172
172
|
vertexs: QuadrangleVertexs | Vertexs;
|
|
173
173
|
matrixWorld?: number[];
|
|
174
174
|
};
|
|
175
|
+
/**
|
|
176
|
+
* 四元数
|
|
177
|
+
*/
|
|
178
|
+
export declare type Quaternion = {
|
|
179
|
+
x: number;
|
|
180
|
+
y: number;
|
|
181
|
+
z: number;
|
|
182
|
+
w: number;
|
|
183
|
+
};
|
|
175
184
|
/**
|
|
176
185
|
* 全景文本标签
|
|
177
186
|
*/
|
|
178
187
|
export declare type PanoTextLabelData = {
|
|
179
188
|
text: string;
|
|
180
189
|
vertex: Vertex;
|
|
190
|
+
normal?: Vertex;
|
|
191
|
+
quaternion?: Quaternion;
|
|
181
192
|
fontSize?: number;
|
|
182
193
|
};
|
|
183
194
|
/**
|
package/package.json
CHANGED
|
@@ -1,21 +1,66 @@
|
|
|
1
|
-
import classNames from 'classnames'
|
|
2
1
|
import * as React from 'react'
|
|
3
|
-
import
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import ReactDOM from 'react-dom'
|
|
4
|
+
import { Vector3, Quaternion } from 'three'
|
|
5
|
+
|
|
6
|
+
import { useController, useFiveInstance } from '../../../hooks'
|
|
7
|
+
import { CSS3DRenderPlugin } from '../../../../fivePlugins/CSS3DRenderPlugin'
|
|
4
8
|
import { PanoTextLabelData, VreoKeyframe, VreoKeyframeEnum } from '../../../../typings/VreoUnit'
|
|
5
|
-
import { useController, useFiveProject2d } from '../../../hooks'
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 通过传入中心点确定矩形框架容器的四个点:
|
|
12
|
+
* 1. 已知矩形长宽和中心点
|
|
13
|
+
* 2. 借助planeGeometry生成垂直相机视角的平面上的四个点
|
|
14
|
+
* 3. 通过向量相加,平行四边形法则获取到移动position后的面上四个点
|
|
15
|
+
*/
|
|
16
|
+
const calcPoints = (
|
|
17
|
+
centerPoint: Vector3,
|
|
18
|
+
normal: THREE.Vector3 | undefined,
|
|
19
|
+
wrapperLength: number,
|
|
20
|
+
wrapperWidth: number
|
|
21
|
+
) => {
|
|
22
|
+
// 375px 对应 1m
|
|
23
|
+
const length = wrapperLength / 375
|
|
24
|
+
const width = wrapperWidth / 375
|
|
25
|
+
|
|
26
|
+
const geometry = new THREE.PlaneGeometry(length, width)
|
|
27
|
+
if (normal) {
|
|
28
|
+
const lookPoint = new THREE.Vector3(normal.x + centerPoint.x, normal.y + centerPoint.y, normal.z + centerPoint.z)
|
|
29
|
+
geometry.lookAt(lookPoint)
|
|
30
|
+
}
|
|
31
|
+
// const pointgeometry = new THREE.Geometry()
|
|
32
|
+
// pointgeometry.vertices.push(cameraPosition)
|
|
33
|
+
// const pointmaterial = new THREE.PointsMaterial({
|
|
34
|
+
// color: 0xffffff,
|
|
35
|
+
// size: 0.4,
|
|
36
|
+
// })
|
|
37
|
+
// _point = new THREE.Points(pointgeometry, pointmaterial)
|
|
38
|
+
// console.log(cameraPosition)
|
|
39
|
+
|
|
40
|
+
const material = new THREE.MeshBasicMaterial({ color: 0xffff00, side: THREE.DoubleSide })
|
|
41
|
+
const plane = new THREE.Mesh(geometry, material)
|
|
42
|
+
const v0 = centerPoint.clone()
|
|
43
|
+
plane.position.copy(v0)
|
|
44
|
+
|
|
45
|
+
// 计算传入的四个点的坐标
|
|
46
|
+
const [v1, v2, v3, v4] = plane.geometry.vertices
|
|
47
|
+
const downLeft = v0.clone().add(v4)
|
|
48
|
+
const downRight = v0.clone().add(v3)
|
|
49
|
+
const upLeft = v0.clone().add(v2)
|
|
50
|
+
const upRight = v0.clone().add(v1)
|
|
51
|
+
|
|
52
|
+
// 插件使用要求:矩形四个点位数据,顺序为**必须**为左下、右下、右上、左上
|
|
53
|
+
return [downLeft, downRight, upRight, upLeft]
|
|
12
54
|
}
|
|
13
55
|
|
|
56
|
+
/**
|
|
57
|
+
* 空间文本标签。
|
|
58
|
+
*/
|
|
14
59
|
export function PanoTextLabel() {
|
|
15
|
-
const [state, setState] = React.useState<PanoTextLabelState | null>(null)
|
|
16
60
|
const timeoutRef = React.useRef<NodeJS.Timeout | null>()
|
|
17
61
|
const controller = useController()
|
|
18
|
-
const
|
|
62
|
+
const five = useFiveInstance()
|
|
63
|
+
const ref = React.useRef<ReturnType<typeof CSS3DRenderPlugin>>()
|
|
19
64
|
|
|
20
65
|
React.useEffect(() => {
|
|
21
66
|
if (controller.configs?.keyframeMap.PanoTextLabel === false) {
|
|
@@ -24,19 +69,43 @@ export function PanoTextLabel() {
|
|
|
24
69
|
const callback = (keyframe: VreoKeyframe) => {
|
|
25
70
|
const { start, end, data } = keyframe
|
|
26
71
|
const panoTextLabelData = data as PanoTextLabelData
|
|
72
|
+
// 增加无文本情况的判断
|
|
73
|
+
if (data.text === '') return
|
|
74
|
+
|
|
27
75
|
const { x, y, z } = panoTextLabelData.vertex
|
|
76
|
+
const centerPoint = new Vector3(x, y, z)
|
|
77
|
+
const normal = new Vector3(panoTextLabelData.normal?.x, panoTextLabelData.normal?.y, panoTextLabelData.normal?.z)
|
|
78
|
+
// 生成传入的四个点,将文本框最大宽度定在200px,最高高度在30px
|
|
79
|
+
const wrapperLength = 200
|
|
80
|
+
const wrapperWidth = 30
|
|
81
|
+
const points = calcPoints(centerPoint, panoTextLabelData.normal && normal, wrapperLength, wrapperWidth)
|
|
28
82
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
83
|
+
if (!ref.current) ref.current = CSS3DRenderPlugin(five)
|
|
84
|
+
const container = ref.current.create3DDomContainer(points)
|
|
85
|
+
const css3DObject = container?.css3DObject
|
|
86
|
+
// 将获取的mesh进行旋转操作,根据欧拉角去进行mesh的变换
|
|
87
|
+
if (data.quaternion) {
|
|
88
|
+
const quaternion = new Quaternion(data.quaternion.x, data.quaternion.y, data.quaternion.z, data.quaternion.w)
|
|
89
|
+
css3DObject?.quaternion.copy(quaternion)
|
|
90
|
+
}
|
|
91
|
+
if (container?.container)
|
|
92
|
+
ReactDOM.render(
|
|
93
|
+
<div className="PanoTextLabel PanoTextLabel--notHidden">
|
|
94
|
+
<div className="PanoTextLabel-wrapper">
|
|
95
|
+
<div style={{ fontSize: `${data.fontSize || 16}px` }} className="PanoText-innerText">
|
|
96
|
+
{data.text || ''}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
</div>,
|
|
100
|
+
container?.container
|
|
101
|
+
)
|
|
32
102
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
103
|
+
timeoutRef.current = setTimeout(() => {
|
|
104
|
+
ref.current?.disposeAll()
|
|
105
|
+
}, end - start)
|
|
36
106
|
}
|
|
37
107
|
controller.on(VreoKeyframeEnum.PanoTextLabel, callback)
|
|
38
108
|
|
|
39
|
-
// Object.assign(window, { $panoTextLabel: { setState } })
|
|
40
109
|
return () => {
|
|
41
110
|
controller.off(VreoKeyframeEnum.PanoTextLabel, callback)
|
|
42
111
|
if (timeoutRef.current) {
|
|
@@ -45,21 +114,5 @@ export function PanoTextLabel() {
|
|
|
45
114
|
}
|
|
46
115
|
}, [controller])
|
|
47
116
|
|
|
48
|
-
return
|
|
49
|
-
<div
|
|
50
|
-
className={classNames('PanoTextLabel', {
|
|
51
|
-
'PanoTextLabel--notHidden': state,
|
|
52
|
-
})}
|
|
53
|
-
style={{
|
|
54
|
-
left: (state?.left || 0) + 'px',
|
|
55
|
-
top: (state?.top || 0) + 'px',
|
|
56
|
-
}}
|
|
57
|
-
>
|
|
58
|
-
<div className="PanoTextLabel-wrapper">
|
|
59
|
-
<div style={{ fontSize: `${state?.fontSize || 16}px` }} className="PanoText-innerText">
|
|
60
|
-
{state?.text || ''}
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
)
|
|
117
|
+
return <></>
|
|
65
118
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description: 简陋的 ResizeObserver polyfill
|
|
3
|
+
*/
|
|
4
|
+
export default function createResizeObserver(func: () => any, element?: HTMLElement) {
|
|
5
|
+
if (!element || typeof ResizeObserver === 'undefined') {
|
|
6
|
+
return {
|
|
7
|
+
observe: () => window.addEventListener('resize', func),
|
|
8
|
+
unobserve: () => window.removeEventListener('resize', func),
|
|
9
|
+
}
|
|
10
|
+
} else {
|
|
11
|
+
const observer = new ResizeObserver(func)
|
|
12
|
+
return {
|
|
13
|
+
observe: () => observer.observe(element),
|
|
14
|
+
unobserve: () => observer.unobserve(element),
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|