spoint 0.1.0 → 0.1.11
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 +134 -209
- package/SKILL.md +95 -0
- package/apps/environment/index.js +200 -1
- package/apps/environment/models/decorative/.gitkeep +0 -0
- package/apps/environment/models/hazards/.gitkeep +0 -0
- package/apps/environment/models/interactive/.gitkeep +0 -0
- package/apps/environment/models/structures/.gitkeep +0 -0
- package/apps/environment/smartObjects.js +114 -0
- package/apps/interactable/index.js +155 -0
- package/apps/physics-crate/index.js +15 -9
- package/apps/power-crate/index.js +18 -12
- package/apps/tps-game/$GDUPI.vrm +0 -0
- package/apps/tps-game/Cleetus.vrm +0 -0
- package/apps/tps-game/index.js +185 -27
- package/apps/world/index.js +68 -22
- package/bin/create-app.js +337 -0
- package/client/ARControls.js +301 -0
- package/client/LoadingManager.js +117 -0
- package/client/MobileControls.js +1122 -0
- package/client/anim-lib.glb +0 -0
- package/client/animation.js +306 -0
- package/client/app.js +1341 -65
- package/client/camera.js +191 -33
- package/client/createLoadingScreen.js +69 -0
- package/client/editor/bridge.js +113 -0
- package/client/editor/css/main.css +794 -0
- package/client/editor/images/rotate.svg +4 -0
- package/client/editor/images/scale.svg +4 -0
- package/client/editor/images/translate.svg +4 -0
- package/client/editor/index.html +103 -0
- package/client/editor/js/Command.js +41 -0
- package/client/editor/js/Config.js +81 -0
- package/client/editor/js/Editor.js +785 -0
- package/client/editor/js/EditorControls.js +438 -0
- package/client/editor/js/History.js +321 -0
- package/client/editor/js/Loader.js +987 -0
- package/client/editor/js/LoaderUtils.js +90 -0
- package/client/editor/js/Menubar.Add.js +510 -0
- package/client/editor/js/Menubar.Edit.js +145 -0
- package/client/editor/js/Menubar.File.js +466 -0
- package/client/editor/js/Menubar.Help.js +73 -0
- package/client/editor/js/Menubar.Status.js +51 -0
- package/client/editor/js/Menubar.View.js +183 -0
- package/client/editor/js/Menubar.js +27 -0
- package/client/editor/js/Player.js +53 -0
- package/client/editor/js/Resizer.js +58 -0
- package/client/editor/js/Script.js +503 -0
- package/client/editor/js/Selector.js +102 -0
- package/client/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.BufferGeometry.js +115 -0
- package/client/editor/js/Sidebar.Geometry.CapsuleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
- package/client/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
- package/client/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
- package/client/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
- package/client/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
- package/client/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
- package/client/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
- package/client/editor/js/Sidebar.Geometry.js +332 -0
- package/client/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.ColorProperty.js +87 -0
- package/client/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
- package/client/editor/js/Sidebar.Material.MapProperty.js +249 -0
- package/client/editor/js/Sidebar.Material.NumberProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.Program.js +73 -0
- package/client/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
- package/client/editor/js/Sidebar.Material.js +751 -0
- package/client/editor/js/Sidebar.Object.Animation.js +102 -0
- package/client/editor/js/Sidebar.Object.js +898 -0
- package/client/editor/js/Sidebar.Project.App.js +165 -0
- package/client/editor/js/Sidebar.Project.Image.js +225 -0
- package/client/editor/js/Sidebar.Project.Materials.js +82 -0
- package/client/editor/js/Sidebar.Project.Renderer.js +144 -0
- package/client/editor/js/Sidebar.Project.Video.js +242 -0
- package/client/editor/js/Sidebar.Project.js +31 -0
- package/client/editor/js/Sidebar.Properties.js +73 -0
- package/client/editor/js/Sidebar.Scene.js +585 -0
- package/client/editor/js/Sidebar.Script.js +129 -0
- package/client/editor/js/Sidebar.Settings.History.js +146 -0
- package/client/editor/js/Sidebar.Settings.Shortcuts.js +175 -0
- package/client/editor/js/Sidebar.Settings.js +60 -0
- package/client/editor/js/Sidebar.js +41 -0
- package/client/editor/js/Storage.js +98 -0
- package/client/editor/js/Strings.js +2028 -0
- package/client/editor/js/Toolbar.js +84 -0
- package/client/editor/js/Viewport.Controls.js +92 -0
- package/client/editor/js/Viewport.Info.js +136 -0
- package/client/editor/js/Viewport.Pathtracer.js +91 -0
- package/client/editor/js/Viewport.ViewHelper.js +39 -0
- package/client/editor/js/Viewport.XR.js +222 -0
- package/client/editor/js/Viewport.js +900 -0
- package/client/editor/js/commands/AddObjectCommand.js +68 -0
- package/client/editor/js/commands/AddScriptCommand.js +75 -0
- package/client/editor/js/commands/Commands.js +23 -0
- package/client/editor/js/commands/MoveObjectCommand.js +111 -0
- package/client/editor/js/commands/MultiCmdsCommand.js +85 -0
- package/client/editor/js/commands/RemoveObjectCommand.js +88 -0
- package/client/editor/js/commands/RemoveScriptCommand.js +81 -0
- package/client/editor/js/commands/SetColorCommand.js +73 -0
- package/client/editor/js/commands/SetGeometryCommand.js +87 -0
- package/client/editor/js/commands/SetGeometryValueCommand.js +70 -0
- package/client/editor/js/commands/SetMaterialColorCommand.js +86 -0
- package/client/editor/js/commands/SetMaterialCommand.js +79 -0
- package/client/editor/js/commands/SetMaterialMapCommand.js +143 -0
- package/client/editor/js/commands/SetMaterialRangeCommand.js +91 -0
- package/client/editor/js/commands/SetMaterialValueCommand.js +90 -0
- package/client/editor/js/commands/SetMaterialVectorCommand.js +79 -0
- package/client/editor/js/commands/SetPositionCommand.js +84 -0
- package/client/editor/js/commands/SetRotationCommand.js +84 -0
- package/client/editor/js/commands/SetScaleCommand.js +84 -0
- package/client/editor/js/commands/SetSceneCommand.js +103 -0
- package/client/editor/js/commands/SetScriptValueCommand.js +80 -0
- package/client/editor/js/commands/SetShadowValueCommand.js +73 -0
- package/client/editor/js/commands/SetUuidCommand.js +70 -0
- package/client/editor/js/commands/SetValueCommand.js +75 -0
- package/client/editor/js/libs/acorn/acorn.js +3236 -0
- package/client/editor/js/libs/acorn/acorn_loose.js +1299 -0
- package/client/editor/js/libs/acorn/walk.js +344 -0
- package/client/editor/js/libs/app/index.html +57 -0
- package/client/editor/js/libs/app.js +251 -0
- package/client/editor/js/libs/codemirror/addon/dialog.css +32 -0
- package/client/editor/js/libs/codemirror/addon/dialog.js +163 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.css +36 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.js +529 -0
- package/client/editor/js/libs/codemirror/addon/tern.css +87 -0
- package/client/editor/js/libs/codemirror/addon/tern.js +750 -0
- package/client/editor/js/libs/codemirror/codemirror.css +344 -0
- package/client/editor/js/libs/codemirror/codemirror.js +9849 -0
- package/client/editor/js/libs/codemirror/mode/glsl.js +233 -0
- package/client/editor/js/libs/codemirror/mode/javascript.js +959 -0
- package/client/editor/js/libs/codemirror/theme/monokai.css +41 -0
- package/client/editor/js/libs/esprima.js +6401 -0
- package/client/editor/js/libs/jsonlint.js +453 -0
- package/client/editor/js/libs/signals.min.js +14 -0
- package/client/editor/js/libs/tern-threejs/threejs.js +5031 -0
- package/client/editor/js/libs/ternjs/comment.js +87 -0
- package/client/editor/js/libs/ternjs/def.js +588 -0
- package/client/editor/js/libs/ternjs/doc_comment.js +401 -0
- package/client/editor/js/libs/ternjs/infer.js +1635 -0
- package/client/editor/js/libs/ternjs/polyfill.js +80 -0
- package/client/editor/js/libs/ternjs/signal.js +26 -0
- package/client/editor/js/libs/ternjs/tern.js +993 -0
- package/client/editor/js/libs/ui.js +1346 -0
- package/client/editor/js/libs/ui.three.js +855 -0
- package/client/facial-animation.js +455 -0
- package/client/index.html +7 -4
- package/client/loading.css +147 -0
- package/client/loading.html +25 -0
- package/client/style.css +251 -0
- package/package.json +7 -3
- package/server.js +9 -1
- package/src/apps/AppContext.js +1 -1
- package/src/apps/AppLoader.js +50 -37
- package/src/apps/AppRuntime.js +32 -8
- package/src/client/InputHandler.js +233 -0
- package/src/client/JitterBuffer.js +207 -0
- package/src/client/KalmanFilter.js +125 -0
- package/src/client/MessageHandler.js +101 -0
- package/src/client/PhysicsNetworkClient.js +141 -68
- package/src/client/ReconnectManager.js +62 -0
- package/src/client/SmoothInterpolation.js +127 -0
- package/src/client/SnapshotProcessor.js +144 -0
- package/src/connection/ConnectionManager.js +21 -3
- package/src/connection/SessionStore.js +13 -3
- package/src/index.client.js +4 -6
- package/src/netcode/EventLog.js +29 -15
- package/src/netcode/LagCompensator.js +25 -26
- package/src/netcode/NetworkState.js +4 -1
- package/src/netcode/PhysicsIntegration.js +20 -6
- package/src/netcode/PlayerManager.js +10 -2
- package/src/netcode/SnapshotEncoder.js +66 -19
- package/src/netcode/TickSystem.js +13 -4
- package/src/physics/World.js +66 -13
- package/src/protocol/msgpack.js +90 -63
- package/src/sdk/ReloadHandlers.js +12 -2
- package/src/sdk/ReloadManager.js +5 -0
- package/src/sdk/ServerHandlers.js +50 -11
- package/src/sdk/StaticHandler.js +22 -6
- package/src/sdk/TickHandler.js +101 -34
- package/src/sdk/scaffold.js +31 -0
- package/src/sdk/server.js +59 -33
- package/src/shared/movement.js +2 -1
- package/src/spatial/Octree.js +5 -0
- package/apps/interactive-door/index.js +0 -33
- package/apps/patrol-npc/index.js +0 -37
- package/src/connection/QualityMonitor.js +0 -46
- package/src/debug/StateInspector.js +0 -42
- package/src/index.js +0 -1
- package/src/index.server.js +0 -27
- package/src/protocol/Codec.js +0 -60
- package/src/protocol/SequenceTracker.js +0 -71
- package/src/sdk/ClientMessageHandler.js +0 -80
- package/src/sdk/client.js +0 -122
- package/world/kaira.glb +0 -0
- package/world/schwust.glb +0 -0
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
import { Config } from './Config.js';
|
|
4
|
+
import { Loader } from './Loader.js';
|
|
5
|
+
import { History as _History } from './History.js';
|
|
6
|
+
import { Strings } from './Strings.js';
|
|
7
|
+
import { Storage as _Storage } from './Storage.js';
|
|
8
|
+
import { Selector } from './Selector.js';
|
|
9
|
+
|
|
10
|
+
var _DEFAULT_CAMERA = new THREE.PerspectiveCamera( 50, 1, 0.01, 1000 );
|
|
11
|
+
_DEFAULT_CAMERA.name = 'Camera';
|
|
12
|
+
_DEFAULT_CAMERA.position.set( 0, 5, 10 );
|
|
13
|
+
_DEFAULT_CAMERA.lookAt( new THREE.Vector3() );
|
|
14
|
+
|
|
15
|
+
function Editor() {
|
|
16
|
+
|
|
17
|
+
const Signal = signals.Signal; // eslint-disable-line no-undef
|
|
18
|
+
|
|
19
|
+
this.signals = {
|
|
20
|
+
|
|
21
|
+
// script
|
|
22
|
+
|
|
23
|
+
editScript: new Signal(),
|
|
24
|
+
|
|
25
|
+
// player
|
|
26
|
+
|
|
27
|
+
startPlayer: new Signal(),
|
|
28
|
+
stopPlayer: new Signal(),
|
|
29
|
+
|
|
30
|
+
// xr
|
|
31
|
+
|
|
32
|
+
enterXR: new Signal(),
|
|
33
|
+
offerXR: new Signal(),
|
|
34
|
+
leaveXR: new Signal(),
|
|
35
|
+
|
|
36
|
+
// notifications
|
|
37
|
+
|
|
38
|
+
editorCleared: new Signal(),
|
|
39
|
+
|
|
40
|
+
savingStarted: new Signal(),
|
|
41
|
+
savingFinished: new Signal(),
|
|
42
|
+
|
|
43
|
+
transformModeChanged: new Signal(),
|
|
44
|
+
snapChanged: new Signal(),
|
|
45
|
+
spaceChanged: new Signal(),
|
|
46
|
+
rendererCreated: new Signal(),
|
|
47
|
+
rendererUpdated: new Signal(),
|
|
48
|
+
rendererDetectKTX2Support: new Signal(),
|
|
49
|
+
|
|
50
|
+
sceneBackgroundChanged: new Signal(),
|
|
51
|
+
sceneEnvironmentChanged: new Signal(),
|
|
52
|
+
sceneFogChanged: new Signal(),
|
|
53
|
+
sceneFogSettingsChanged: new Signal(),
|
|
54
|
+
sceneGraphChanged: new Signal(),
|
|
55
|
+
sceneRendered: new Signal(),
|
|
56
|
+
|
|
57
|
+
cameraChanged: new Signal(),
|
|
58
|
+
cameraResetted: new Signal(),
|
|
59
|
+
|
|
60
|
+
geometryChanged: new Signal(),
|
|
61
|
+
|
|
62
|
+
objectSelected: new Signal(),
|
|
63
|
+
objectFocused: new Signal(),
|
|
64
|
+
|
|
65
|
+
objectAdded: new Signal(),
|
|
66
|
+
objectChanged: new Signal(),
|
|
67
|
+
objectRemoved: new Signal(),
|
|
68
|
+
|
|
69
|
+
cameraAdded: new Signal(),
|
|
70
|
+
cameraRemoved: new Signal(),
|
|
71
|
+
|
|
72
|
+
helperAdded: new Signal(),
|
|
73
|
+
helperRemoved: new Signal(),
|
|
74
|
+
|
|
75
|
+
materialAdded: new Signal(),
|
|
76
|
+
materialChanged: new Signal(),
|
|
77
|
+
materialRemoved: new Signal(),
|
|
78
|
+
|
|
79
|
+
scriptAdded: new Signal(),
|
|
80
|
+
scriptChanged: new Signal(),
|
|
81
|
+
scriptRemoved: new Signal(),
|
|
82
|
+
|
|
83
|
+
windowResize: new Signal(),
|
|
84
|
+
|
|
85
|
+
showHelpersChanged: new Signal(),
|
|
86
|
+
refreshSidebarObject3D: new Signal(),
|
|
87
|
+
refreshSidebarEnvironment: new Signal(),
|
|
88
|
+
historyChanged: new Signal(),
|
|
89
|
+
|
|
90
|
+
viewportCameraChanged: new Signal(),
|
|
91
|
+
viewportShadingChanged: new Signal(),
|
|
92
|
+
|
|
93
|
+
intersectionsDetected: new Signal(),
|
|
94
|
+
|
|
95
|
+
pathTracerUpdated: new Signal(),
|
|
96
|
+
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
this.config = new Config();
|
|
100
|
+
this.history = new _History( this );
|
|
101
|
+
this.selector = new Selector( this );
|
|
102
|
+
this.storage = new _Storage();
|
|
103
|
+
this.strings = new Strings( this.config );
|
|
104
|
+
|
|
105
|
+
this.loader = new Loader( this );
|
|
106
|
+
|
|
107
|
+
this.camera = _DEFAULT_CAMERA.clone();
|
|
108
|
+
|
|
109
|
+
this.scene = new THREE.Scene();
|
|
110
|
+
this.scene.name = 'Scene';
|
|
111
|
+
|
|
112
|
+
this.sceneHelpers = new THREE.Scene();
|
|
113
|
+
this.sceneHelpers.add( new THREE.HemisphereLight( 0xffffff, 0x888888, 2 ) );
|
|
114
|
+
|
|
115
|
+
this.object = {};
|
|
116
|
+
this.geometries = {};
|
|
117
|
+
this.materials = {};
|
|
118
|
+
this.textures = {};
|
|
119
|
+
this.scripts = {};
|
|
120
|
+
|
|
121
|
+
this.materialsRefCounter = new Map(); // tracks how often is a material used by a 3D object
|
|
122
|
+
|
|
123
|
+
this.mixer = new THREE.AnimationMixer( this.scene );
|
|
124
|
+
|
|
125
|
+
this.selected = null;
|
|
126
|
+
this.helpers = {};
|
|
127
|
+
|
|
128
|
+
this.cameras = {};
|
|
129
|
+
|
|
130
|
+
this.viewportCamera = this.camera;
|
|
131
|
+
this.viewportShading = 'default';
|
|
132
|
+
|
|
133
|
+
this.addCamera( this.camera );
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
Editor.prototype = {
|
|
138
|
+
|
|
139
|
+
setScene: function ( scene ) {
|
|
140
|
+
|
|
141
|
+
this.scene.uuid = scene.uuid;
|
|
142
|
+
this.scene.name = scene.name;
|
|
143
|
+
|
|
144
|
+
this.scene.background = scene.background;
|
|
145
|
+
this.scene.environment = scene.environment;
|
|
146
|
+
this.scene.fog = scene.fog;
|
|
147
|
+
this.scene.backgroundBlurriness = scene.backgroundBlurriness;
|
|
148
|
+
this.scene.backgroundIntensity = scene.backgroundIntensity;
|
|
149
|
+
|
|
150
|
+
this.scene.userData = JSON.parse( JSON.stringify( scene.userData ) );
|
|
151
|
+
|
|
152
|
+
// avoid render per object
|
|
153
|
+
|
|
154
|
+
this.signals.sceneGraphChanged.active = false;
|
|
155
|
+
|
|
156
|
+
while ( scene.children.length > 0 ) {
|
|
157
|
+
|
|
158
|
+
this.addObject( scene.children[ 0 ] );
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.signals.sceneGraphChanged.active = true;
|
|
163
|
+
this.signals.sceneGraphChanged.dispatch();
|
|
164
|
+
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
//
|
|
168
|
+
|
|
169
|
+
addObject: function ( object, parent, index ) {
|
|
170
|
+
|
|
171
|
+
var scope = this;
|
|
172
|
+
|
|
173
|
+
object.traverse( function ( child ) {
|
|
174
|
+
|
|
175
|
+
if ( child.geometry !== undefined ) scope.addGeometry( child.geometry );
|
|
176
|
+
if ( child.material !== undefined ) scope.addMaterial( child.material );
|
|
177
|
+
|
|
178
|
+
scope.addCamera( child );
|
|
179
|
+
scope.addHelper( child );
|
|
180
|
+
|
|
181
|
+
} );
|
|
182
|
+
|
|
183
|
+
if ( parent === undefined ) {
|
|
184
|
+
|
|
185
|
+
this.scene.add( object );
|
|
186
|
+
|
|
187
|
+
} else {
|
|
188
|
+
|
|
189
|
+
parent.children.splice( index, 0, object );
|
|
190
|
+
object.parent = parent;
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.signals.objectAdded.dispatch( object );
|
|
195
|
+
this.signals.sceneGraphChanged.dispatch();
|
|
196
|
+
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
nameObject: function ( object, name ) {
|
|
200
|
+
|
|
201
|
+
object.name = name;
|
|
202
|
+
this.signals.sceneGraphChanged.dispatch();
|
|
203
|
+
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
removeObject: function ( object ) {
|
|
207
|
+
|
|
208
|
+
if ( object.parent === null ) return; // avoid deleting the camera or scene
|
|
209
|
+
|
|
210
|
+
var scope = this;
|
|
211
|
+
|
|
212
|
+
object.traverse( function ( child ) {
|
|
213
|
+
|
|
214
|
+
scope.removeCamera( child );
|
|
215
|
+
scope.removeHelper( child );
|
|
216
|
+
|
|
217
|
+
if ( child.material !== undefined ) scope.removeMaterial( child.material );
|
|
218
|
+
|
|
219
|
+
} );
|
|
220
|
+
|
|
221
|
+
object.parent.remove( object );
|
|
222
|
+
|
|
223
|
+
this.signals.objectRemoved.dispatch( object );
|
|
224
|
+
this.signals.sceneGraphChanged.dispatch();
|
|
225
|
+
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
addGeometry: function ( geometry ) {
|
|
229
|
+
|
|
230
|
+
this.geometries[ geometry.uuid ] = geometry;
|
|
231
|
+
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
setGeometryName: function ( geometry, name ) {
|
|
235
|
+
|
|
236
|
+
geometry.name = name;
|
|
237
|
+
this.signals.sceneGraphChanged.dispatch();
|
|
238
|
+
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
addMaterial: function ( material ) {
|
|
242
|
+
|
|
243
|
+
if ( Array.isArray( material ) ) {
|
|
244
|
+
|
|
245
|
+
for ( var i = 0, l = material.length; i < l; i ++ ) {
|
|
246
|
+
|
|
247
|
+
this.addMaterialToRefCounter( material[ i ] );
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
} else {
|
|
252
|
+
|
|
253
|
+
this.addMaterialToRefCounter( material );
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
this.signals.materialAdded.dispatch();
|
|
258
|
+
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
addMaterialToRefCounter: function ( material ) {
|
|
262
|
+
|
|
263
|
+
var materialsRefCounter = this.materialsRefCounter;
|
|
264
|
+
|
|
265
|
+
var count = materialsRefCounter.get( material );
|
|
266
|
+
|
|
267
|
+
if ( count === undefined ) {
|
|
268
|
+
|
|
269
|
+
materialsRefCounter.set( material, 1 );
|
|
270
|
+
this.materials[ material.uuid ] = material;
|
|
271
|
+
|
|
272
|
+
} else {
|
|
273
|
+
|
|
274
|
+
count ++;
|
|
275
|
+
materialsRefCounter.set( material, count );
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
removeMaterial: function ( material ) {
|
|
282
|
+
|
|
283
|
+
if ( Array.isArray( material ) ) {
|
|
284
|
+
|
|
285
|
+
for ( var i = 0, l = material.length; i < l; i ++ ) {
|
|
286
|
+
|
|
287
|
+
this.removeMaterialFromRefCounter( material[ i ] );
|
|
288
|
+
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
} else {
|
|
292
|
+
|
|
293
|
+
this.removeMaterialFromRefCounter( material );
|
|
294
|
+
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
this.signals.materialRemoved.dispatch();
|
|
298
|
+
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
removeMaterialFromRefCounter: function ( material ) {
|
|
302
|
+
|
|
303
|
+
var materialsRefCounter = this.materialsRefCounter;
|
|
304
|
+
|
|
305
|
+
var count = materialsRefCounter.get( material );
|
|
306
|
+
count --;
|
|
307
|
+
|
|
308
|
+
if ( count === 0 ) {
|
|
309
|
+
|
|
310
|
+
materialsRefCounter.delete( material );
|
|
311
|
+
delete this.materials[ material.uuid ];
|
|
312
|
+
|
|
313
|
+
} else {
|
|
314
|
+
|
|
315
|
+
materialsRefCounter.set( material, count );
|
|
316
|
+
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
getMaterialById: function ( id ) {
|
|
322
|
+
|
|
323
|
+
var material;
|
|
324
|
+
var materials = Object.values( this.materials );
|
|
325
|
+
|
|
326
|
+
for ( var i = 0; i < materials.length; i ++ ) {
|
|
327
|
+
|
|
328
|
+
if ( materials[ i ].id === id ) {
|
|
329
|
+
|
|
330
|
+
material = materials[ i ];
|
|
331
|
+
break;
|
|
332
|
+
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return material;
|
|
338
|
+
|
|
339
|
+
},
|
|
340
|
+
|
|
341
|
+
setMaterialName: function ( material, name ) {
|
|
342
|
+
|
|
343
|
+
material.name = name;
|
|
344
|
+
this.signals.sceneGraphChanged.dispatch();
|
|
345
|
+
|
|
346
|
+
},
|
|
347
|
+
|
|
348
|
+
addTexture: function ( texture ) {
|
|
349
|
+
|
|
350
|
+
this.textures[ texture.uuid ] = texture;
|
|
351
|
+
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
//
|
|
355
|
+
|
|
356
|
+
addCamera: function ( camera ) {
|
|
357
|
+
|
|
358
|
+
if ( camera.isCamera ) {
|
|
359
|
+
|
|
360
|
+
this.cameras[ camera.uuid ] = camera;
|
|
361
|
+
|
|
362
|
+
this.signals.cameraAdded.dispatch( camera );
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
},
|
|
367
|
+
|
|
368
|
+
removeCamera: function ( camera ) {
|
|
369
|
+
|
|
370
|
+
if ( this.cameras[ camera.uuid ] !== undefined ) {
|
|
371
|
+
|
|
372
|
+
delete this.cameras[ camera.uuid ];
|
|
373
|
+
|
|
374
|
+
this.signals.cameraRemoved.dispatch( camera );
|
|
375
|
+
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
//
|
|
381
|
+
|
|
382
|
+
addHelper: function () {
|
|
383
|
+
|
|
384
|
+
var geometry = new THREE.SphereGeometry( 2, 4, 2 );
|
|
385
|
+
var material = new THREE.MeshBasicMaterial( { color: 0xff0000, visible: false } );
|
|
386
|
+
|
|
387
|
+
return function ( object, helper ) {
|
|
388
|
+
|
|
389
|
+
if ( helper === undefined ) {
|
|
390
|
+
|
|
391
|
+
if ( object.isCamera ) {
|
|
392
|
+
|
|
393
|
+
helper = new THREE.CameraHelper( object );
|
|
394
|
+
|
|
395
|
+
} else if ( object.isPointLight ) {
|
|
396
|
+
|
|
397
|
+
helper = new THREE.PointLightHelper( object, 1 );
|
|
398
|
+
|
|
399
|
+
} else if ( object.isDirectionalLight ) {
|
|
400
|
+
|
|
401
|
+
helper = new THREE.DirectionalLightHelper( object, 1 );
|
|
402
|
+
|
|
403
|
+
} else if ( object.isSpotLight ) {
|
|
404
|
+
|
|
405
|
+
helper = new THREE.SpotLightHelper( object );
|
|
406
|
+
|
|
407
|
+
} else if ( object.isHemisphereLight ) {
|
|
408
|
+
|
|
409
|
+
helper = new THREE.HemisphereLightHelper( object, 1 );
|
|
410
|
+
|
|
411
|
+
} else if ( object.isSkinnedMesh ) {
|
|
412
|
+
|
|
413
|
+
helper = new THREE.SkeletonHelper( object.skeleton.bones[ 0 ] );
|
|
414
|
+
|
|
415
|
+
} else if ( object.isBone === true && object.parent && object.parent.isBone !== true ) {
|
|
416
|
+
|
|
417
|
+
helper = new THREE.SkeletonHelper( object );
|
|
418
|
+
|
|
419
|
+
} else {
|
|
420
|
+
|
|
421
|
+
// no helper for this object type
|
|
422
|
+
return;
|
|
423
|
+
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const picker = new THREE.Mesh( geometry, material );
|
|
427
|
+
picker.name = 'picker';
|
|
428
|
+
picker.userData.object = object;
|
|
429
|
+
helper.add( picker );
|
|
430
|
+
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
this.sceneHelpers.add( helper );
|
|
434
|
+
this.helpers[ object.id ] = helper;
|
|
435
|
+
|
|
436
|
+
this.signals.helperAdded.dispatch( helper );
|
|
437
|
+
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
}(),
|
|
441
|
+
|
|
442
|
+
removeHelper: function ( object ) {
|
|
443
|
+
|
|
444
|
+
if ( this.helpers[ object.id ] !== undefined ) {
|
|
445
|
+
|
|
446
|
+
var helper = this.helpers[ object.id ];
|
|
447
|
+
helper.parent.remove( helper );
|
|
448
|
+
helper.dispose();
|
|
449
|
+
|
|
450
|
+
delete this.helpers[ object.id ];
|
|
451
|
+
|
|
452
|
+
this.signals.helperRemoved.dispatch( helper );
|
|
453
|
+
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
},
|
|
457
|
+
|
|
458
|
+
//
|
|
459
|
+
|
|
460
|
+
addScript: function ( object, script ) {
|
|
461
|
+
|
|
462
|
+
if ( this.scripts[ object.uuid ] === undefined ) {
|
|
463
|
+
|
|
464
|
+
this.scripts[ object.uuid ] = [];
|
|
465
|
+
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
this.scripts[ object.uuid ].push( script );
|
|
469
|
+
|
|
470
|
+
this.signals.scriptAdded.dispatch( script );
|
|
471
|
+
|
|
472
|
+
},
|
|
473
|
+
|
|
474
|
+
removeScript: function ( object, script ) {
|
|
475
|
+
|
|
476
|
+
if ( this.scripts[ object.uuid ] === undefined ) return;
|
|
477
|
+
|
|
478
|
+
var index = this.scripts[ object.uuid ].indexOf( script );
|
|
479
|
+
|
|
480
|
+
if ( index !== - 1 ) {
|
|
481
|
+
|
|
482
|
+
this.scripts[ object.uuid ].splice( index, 1 );
|
|
483
|
+
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
this.signals.scriptRemoved.dispatch( script );
|
|
487
|
+
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
getObjectMaterial: function ( object, slot ) {
|
|
491
|
+
|
|
492
|
+
var material = object.material;
|
|
493
|
+
|
|
494
|
+
if ( Array.isArray( material ) && slot !== undefined ) {
|
|
495
|
+
|
|
496
|
+
material = material[ slot ];
|
|
497
|
+
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return material;
|
|
501
|
+
|
|
502
|
+
},
|
|
503
|
+
|
|
504
|
+
setObjectMaterial: function ( object, slot, newMaterial ) {
|
|
505
|
+
|
|
506
|
+
if ( Array.isArray( object.material ) && slot !== undefined ) {
|
|
507
|
+
|
|
508
|
+
object.material[ slot ] = newMaterial;
|
|
509
|
+
|
|
510
|
+
} else {
|
|
511
|
+
|
|
512
|
+
object.material = newMaterial;
|
|
513
|
+
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
},
|
|
517
|
+
|
|
518
|
+
setViewportCamera: function ( uuid ) {
|
|
519
|
+
|
|
520
|
+
this.viewportCamera = this.cameras[ uuid ];
|
|
521
|
+
this.signals.viewportCameraChanged.dispatch();
|
|
522
|
+
|
|
523
|
+
},
|
|
524
|
+
|
|
525
|
+
setViewportShading: function ( value ) {
|
|
526
|
+
|
|
527
|
+
this.viewportShading = value;
|
|
528
|
+
this.signals.viewportShadingChanged.dispatch();
|
|
529
|
+
|
|
530
|
+
},
|
|
531
|
+
|
|
532
|
+
//
|
|
533
|
+
|
|
534
|
+
select: function ( object ) {
|
|
535
|
+
|
|
536
|
+
this.selector.select( object );
|
|
537
|
+
|
|
538
|
+
},
|
|
539
|
+
|
|
540
|
+
selectById: function ( id ) {
|
|
541
|
+
|
|
542
|
+
if ( id === this.camera.id ) {
|
|
543
|
+
|
|
544
|
+
this.select( this.camera );
|
|
545
|
+
return;
|
|
546
|
+
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
this.select( this.scene.getObjectById( id ) );
|
|
550
|
+
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
selectByUuid: function ( uuid ) {
|
|
554
|
+
|
|
555
|
+
var scope = this;
|
|
556
|
+
|
|
557
|
+
this.scene.traverse( function ( child ) {
|
|
558
|
+
|
|
559
|
+
if ( child.uuid === uuid ) {
|
|
560
|
+
|
|
561
|
+
scope.select( child );
|
|
562
|
+
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
} );
|
|
566
|
+
|
|
567
|
+
},
|
|
568
|
+
|
|
569
|
+
deselect: function () {
|
|
570
|
+
|
|
571
|
+
this.selector.deselect();
|
|
572
|
+
|
|
573
|
+
},
|
|
574
|
+
|
|
575
|
+
focus: function ( object ) {
|
|
576
|
+
|
|
577
|
+
if ( object !== undefined ) {
|
|
578
|
+
|
|
579
|
+
this.signals.objectFocused.dispatch( object );
|
|
580
|
+
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
},
|
|
584
|
+
|
|
585
|
+
focusById: function ( id ) {
|
|
586
|
+
|
|
587
|
+
this.focus( this.scene.getObjectById( id ) );
|
|
588
|
+
|
|
589
|
+
},
|
|
590
|
+
|
|
591
|
+
clear: function () {
|
|
592
|
+
|
|
593
|
+
this.history.clear();
|
|
594
|
+
this.storage.clear();
|
|
595
|
+
|
|
596
|
+
this.camera.copy( _DEFAULT_CAMERA );
|
|
597
|
+
this.signals.cameraResetted.dispatch();
|
|
598
|
+
|
|
599
|
+
this.scene.name = 'Scene';
|
|
600
|
+
this.scene.userData = {};
|
|
601
|
+
this.scene.background = null;
|
|
602
|
+
this.scene.environment = null;
|
|
603
|
+
this.scene.fog = null;
|
|
604
|
+
|
|
605
|
+
var objects = this.scene.children;
|
|
606
|
+
|
|
607
|
+
this.signals.sceneGraphChanged.active = false;
|
|
608
|
+
|
|
609
|
+
while ( objects.length > 0 ) {
|
|
610
|
+
|
|
611
|
+
this.removeObject( objects[ 0 ] );
|
|
612
|
+
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
this.signals.sceneGraphChanged.active = true;
|
|
616
|
+
|
|
617
|
+
this.geometries = {};
|
|
618
|
+
this.materials = {};
|
|
619
|
+
this.textures = {};
|
|
620
|
+
this.scripts = {};
|
|
621
|
+
|
|
622
|
+
this.materialsRefCounter.clear();
|
|
623
|
+
|
|
624
|
+
this.animations = {};
|
|
625
|
+
this.mixer.stopAllAction();
|
|
626
|
+
|
|
627
|
+
this.deselect();
|
|
628
|
+
|
|
629
|
+
this.signals.editorCleared.dispatch();
|
|
630
|
+
|
|
631
|
+
},
|
|
632
|
+
|
|
633
|
+
//
|
|
634
|
+
|
|
635
|
+
fromJSON: async function ( json ) {
|
|
636
|
+
|
|
637
|
+
var loader = new THREE.ObjectLoader();
|
|
638
|
+
var camera = await loader.parseAsync( json.camera );
|
|
639
|
+
|
|
640
|
+
const existingUuid = this.camera.uuid;
|
|
641
|
+
const incomingUuid = camera.uuid;
|
|
642
|
+
|
|
643
|
+
// copy all properties, including uuid
|
|
644
|
+
this.camera.copy( camera );
|
|
645
|
+
this.camera.uuid = incomingUuid;
|
|
646
|
+
|
|
647
|
+
delete this.cameras[ existingUuid ]; // remove old entry [existingUuid, this.camera]
|
|
648
|
+
this.cameras[ incomingUuid ] = this.camera; // add new entry [incomingUuid, this.camera]
|
|
649
|
+
|
|
650
|
+
this.signals.cameraResetted.dispatch();
|
|
651
|
+
|
|
652
|
+
this.history.fromJSON( json.history );
|
|
653
|
+
this.scripts = json.scripts;
|
|
654
|
+
|
|
655
|
+
this.setScene( await loader.parseAsync( json.scene ) );
|
|
656
|
+
|
|
657
|
+
if ( json.environment === 'ModelViewer' ) {
|
|
658
|
+
|
|
659
|
+
this.signals.sceneEnvironmentChanged.dispatch( json.environment );
|
|
660
|
+
this.signals.refreshSidebarEnvironment.dispatch();
|
|
661
|
+
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
},
|
|
665
|
+
|
|
666
|
+
toJSON: function () {
|
|
667
|
+
|
|
668
|
+
// scripts clean up
|
|
669
|
+
|
|
670
|
+
var scene = this.scene;
|
|
671
|
+
var scripts = this.scripts;
|
|
672
|
+
|
|
673
|
+
for ( var key in scripts ) {
|
|
674
|
+
|
|
675
|
+
var script = scripts[ key ];
|
|
676
|
+
|
|
677
|
+
if ( script.length === 0 || scene.getObjectByProperty( 'uuid', key ) === undefined ) {
|
|
678
|
+
|
|
679
|
+
delete scripts[ key ];
|
|
680
|
+
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// honor modelviewer environment
|
|
686
|
+
|
|
687
|
+
let environment = null;
|
|
688
|
+
|
|
689
|
+
if ( this.scene.environment !== null && this.scene.environment.isRenderTargetTexture === true ) {
|
|
690
|
+
|
|
691
|
+
environment = 'ModelViewer';
|
|
692
|
+
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
//
|
|
696
|
+
|
|
697
|
+
return {
|
|
698
|
+
|
|
699
|
+
metadata: {},
|
|
700
|
+
project: {
|
|
701
|
+
shadows: this.config.getKey( 'project/renderer/shadows' ),
|
|
702
|
+
shadowType: this.config.getKey( 'project/renderer/shadowType' ),
|
|
703
|
+
toneMapping: this.config.getKey( 'project/renderer/toneMapping' ),
|
|
704
|
+
toneMappingExposure: this.config.getKey( 'project/renderer/toneMappingExposure' )
|
|
705
|
+
},
|
|
706
|
+
camera: this.viewportCamera.toJSON(),
|
|
707
|
+
scene: this.scene.toJSON(),
|
|
708
|
+
scripts: this.scripts,
|
|
709
|
+
history: this.history.toJSON(),
|
|
710
|
+
environment: environment
|
|
711
|
+
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
},
|
|
715
|
+
|
|
716
|
+
objectByUuid: function ( uuid ) {
|
|
717
|
+
|
|
718
|
+
return this.scene.getObjectByProperty( 'uuid', uuid, true );
|
|
719
|
+
|
|
720
|
+
},
|
|
721
|
+
|
|
722
|
+
execute: function ( cmd, optionalName ) {
|
|
723
|
+
|
|
724
|
+
this.history.execute( cmd, optionalName );
|
|
725
|
+
|
|
726
|
+
},
|
|
727
|
+
|
|
728
|
+
undo: function () {
|
|
729
|
+
|
|
730
|
+
this.history.undo();
|
|
731
|
+
|
|
732
|
+
},
|
|
733
|
+
|
|
734
|
+
redo: function () {
|
|
735
|
+
|
|
736
|
+
this.history.redo();
|
|
737
|
+
|
|
738
|
+
},
|
|
739
|
+
|
|
740
|
+
utils: {
|
|
741
|
+
|
|
742
|
+
save: save,
|
|
743
|
+
saveArrayBuffer: saveArrayBuffer,
|
|
744
|
+
saveString: saveString,
|
|
745
|
+
formatNumber: formatNumber
|
|
746
|
+
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
const link = document.createElement( 'a' );
|
|
752
|
+
|
|
753
|
+
function save( blob, filename ) {
|
|
754
|
+
|
|
755
|
+
if ( link.href ) {
|
|
756
|
+
|
|
757
|
+
URL.revokeObjectURL( link.href );
|
|
758
|
+
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
link.href = URL.createObjectURL( blob );
|
|
762
|
+
link.download = filename || 'data.json';
|
|
763
|
+
link.dispatchEvent( new MouseEvent( 'click' ) );
|
|
764
|
+
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function saveArrayBuffer( buffer, filename ) {
|
|
768
|
+
|
|
769
|
+
save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename );
|
|
770
|
+
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function saveString( text, filename ) {
|
|
774
|
+
|
|
775
|
+
save( new Blob( [ text ], { type: 'text/plain' } ), filename );
|
|
776
|
+
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
function formatNumber( number ) {
|
|
780
|
+
|
|
781
|
+
return new Intl.NumberFormat( 'en-us', { useGrouping: true } ).format( number );
|
|
782
|
+
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
export { Editor };
|