spoint 0.1.0 → 0.1.10
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 +28 -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,165 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
import { zipSync, strToU8 } from 'three/addons/libs/fflate.module.js';
|
|
4
|
+
|
|
5
|
+
import { UIButton, UICheckbox, UIPanel, UIInput, UIRow, UIText } from './libs/ui.js';
|
|
6
|
+
|
|
7
|
+
function SidebarProjectApp( editor ) {
|
|
8
|
+
|
|
9
|
+
const config = editor.config;
|
|
10
|
+
const signals = editor.signals;
|
|
11
|
+
const strings = editor.strings;
|
|
12
|
+
|
|
13
|
+
const save = editor.utils.save;
|
|
14
|
+
|
|
15
|
+
const container = new UIPanel();
|
|
16
|
+
container.setId( 'app' );
|
|
17
|
+
|
|
18
|
+
const headerRow = new UIRow();
|
|
19
|
+
headerRow.add( new UIText( strings.getKey( 'sidebar/project/app' ).toUpperCase() ) );
|
|
20
|
+
container.add( headerRow );
|
|
21
|
+
|
|
22
|
+
// Title
|
|
23
|
+
|
|
24
|
+
const titleRow = new UIRow();
|
|
25
|
+
const title = new UIInput( config.getKey( 'project/title' ) ).setLeft( '100px' ).setWidth( '150px' ).onChange( function () {
|
|
26
|
+
|
|
27
|
+
config.setKey( 'project/title', this.getValue() );
|
|
28
|
+
|
|
29
|
+
} );
|
|
30
|
+
|
|
31
|
+
titleRow.add( new UIText( strings.getKey( 'sidebar/project/app/title' ) ).setClass( 'Label' ) );
|
|
32
|
+
titleRow.add( title );
|
|
33
|
+
|
|
34
|
+
container.add( titleRow );
|
|
35
|
+
|
|
36
|
+
// Editable
|
|
37
|
+
|
|
38
|
+
const editableRow = new UIRow();
|
|
39
|
+
const editable = new UICheckbox( config.getKey( 'project/editable' ) ).setLeft( '100px' ).onChange( function () {
|
|
40
|
+
|
|
41
|
+
config.setKey( 'project/editable', this.getValue() );
|
|
42
|
+
|
|
43
|
+
} );
|
|
44
|
+
|
|
45
|
+
editableRow.add( new UIText( strings.getKey( 'sidebar/project/app/editable' ) ).setClass( 'Label' ) );
|
|
46
|
+
editableRow.add( editable );
|
|
47
|
+
|
|
48
|
+
container.add( editableRow );
|
|
49
|
+
|
|
50
|
+
// Play/Stop
|
|
51
|
+
|
|
52
|
+
let isPlaying = false;
|
|
53
|
+
|
|
54
|
+
const playButton = new UIButton( strings.getKey( 'sidebar/project/app/play' ) );
|
|
55
|
+
playButton.setWidth( '170px' );
|
|
56
|
+
playButton.setMarginLeft( '120px' );
|
|
57
|
+
playButton.setMarginBottom( '10px' );
|
|
58
|
+
playButton.onClick( function () {
|
|
59
|
+
|
|
60
|
+
if ( isPlaying === false ) {
|
|
61
|
+
|
|
62
|
+
isPlaying = true;
|
|
63
|
+
playButton.setTextContent( strings.getKey( 'sidebar/project/app/stop' ) );
|
|
64
|
+
signals.startPlayer.dispatch();
|
|
65
|
+
|
|
66
|
+
} else {
|
|
67
|
+
|
|
68
|
+
isPlaying = false;
|
|
69
|
+
playButton.setTextContent( strings.getKey( 'sidebar/project/app/play' ) );
|
|
70
|
+
signals.stopPlayer.dispatch();
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
} );
|
|
75
|
+
|
|
76
|
+
container.add( playButton );
|
|
77
|
+
|
|
78
|
+
// Publish
|
|
79
|
+
|
|
80
|
+
const publishButton = new UIButton( strings.getKey( 'sidebar/project/app/publish' ) );
|
|
81
|
+
publishButton.setWidth( '170px' );
|
|
82
|
+
publishButton.setMarginLeft( '120px' );
|
|
83
|
+
publishButton.setMarginBottom( '10px' );
|
|
84
|
+
publishButton.onClick( function () {
|
|
85
|
+
|
|
86
|
+
const toZip = {};
|
|
87
|
+
|
|
88
|
+
//
|
|
89
|
+
|
|
90
|
+
let output = editor.toJSON();
|
|
91
|
+
output.metadata.type = 'App';
|
|
92
|
+
delete output.history;
|
|
93
|
+
|
|
94
|
+
output = JSON.stringify( output, null, '\t' );
|
|
95
|
+
output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
|
|
96
|
+
|
|
97
|
+
toZip[ 'app.json' ] = strToU8( output );
|
|
98
|
+
|
|
99
|
+
//
|
|
100
|
+
|
|
101
|
+
const title = config.getKey( 'project/title' );
|
|
102
|
+
|
|
103
|
+
const manager = new THREE.LoadingManager( function () {
|
|
104
|
+
|
|
105
|
+
const zipped = zipSync( toZip, { level: 9 } );
|
|
106
|
+
|
|
107
|
+
const blob = new Blob( [ zipped.buffer ], { type: 'application/zip' } );
|
|
108
|
+
|
|
109
|
+
save( blob, ( title !== '' ? title : 'untitled' ) + '.zip' );
|
|
110
|
+
|
|
111
|
+
} );
|
|
112
|
+
|
|
113
|
+
const loader = new THREE.FileLoader( manager );
|
|
114
|
+
loader.load( 'js/libs/app/index.html', function ( content ) {
|
|
115
|
+
|
|
116
|
+
content = content.replace( '<!-- title -->', title );
|
|
117
|
+
|
|
118
|
+
let editButton = '';
|
|
119
|
+
|
|
120
|
+
if ( config.getKey( 'project/editable' ) ) {
|
|
121
|
+
|
|
122
|
+
editButton = [
|
|
123
|
+
' let button = document.createElement( \'a\' );',
|
|
124
|
+
' button.href = \'https://threejs.org/editor/#file=\' + location.href.split( \'/\' ).slice( 0, - 1 ).join( \'/\' ) + \'/app.json\';',
|
|
125
|
+
' button.style.cssText = \'position: absolute; bottom: 20px; right: 20px; padding: 10px 16px; color: #fff; border: 1px solid #fff; border-radius: 20px; text-decoration: none;\';',
|
|
126
|
+
' button.target = \'_blank\';',
|
|
127
|
+
' button.textContent = \'EDIT\';',
|
|
128
|
+
' document.body.appendChild( button );',
|
|
129
|
+
].join( '\n' );
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
content = content.replace( '\t\t\t/* edit button */', editButton );
|
|
134
|
+
|
|
135
|
+
toZip[ 'index.html' ] = strToU8( content );
|
|
136
|
+
|
|
137
|
+
} );
|
|
138
|
+
loader.load( 'js/libs/app.js', function ( content ) {
|
|
139
|
+
|
|
140
|
+
toZip[ 'js/app.js' ] = strToU8( content );
|
|
141
|
+
|
|
142
|
+
} );
|
|
143
|
+
loader.load( '../build/three.module.js', function ( content ) {
|
|
144
|
+
|
|
145
|
+
toZip[ 'js/three.module.js' ] = strToU8( content );
|
|
146
|
+
|
|
147
|
+
} );
|
|
148
|
+
|
|
149
|
+
} );
|
|
150
|
+
container.add( publishButton );
|
|
151
|
+
|
|
152
|
+
// Signals
|
|
153
|
+
|
|
154
|
+
signals.editorCleared.add( function () {
|
|
155
|
+
|
|
156
|
+
title.setValue( '' );
|
|
157
|
+
config.setKey( 'project/title', '' );
|
|
158
|
+
|
|
159
|
+
} );
|
|
160
|
+
|
|
161
|
+
return container;
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { SidebarProjectApp };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
import { UIBreak, UIButton, UIInteger, UIPanel, UIRow, UISelect, UIText } from './libs/ui.js';
|
|
4
|
+
|
|
5
|
+
import { ViewportPathtracer } from './Viewport.Pathtracer.js';
|
|
6
|
+
|
|
7
|
+
function SidebarProjectImage( editor ) {
|
|
8
|
+
|
|
9
|
+
const strings = editor.strings;
|
|
10
|
+
|
|
11
|
+
const container = new UIPanel();
|
|
12
|
+
container.setId( 'render' );
|
|
13
|
+
|
|
14
|
+
// Image
|
|
15
|
+
|
|
16
|
+
container.add( new UIText( strings.getKey( 'sidebar/project/image' ) ).setTextTransform( 'uppercase' ) );
|
|
17
|
+
container.add( new UIBreak(), new UIBreak() );
|
|
18
|
+
|
|
19
|
+
// Shading
|
|
20
|
+
|
|
21
|
+
const shadingRow = new UIRow();
|
|
22
|
+
container.add( shadingRow );
|
|
23
|
+
|
|
24
|
+
shadingRow.add( new UIText( strings.getKey( 'sidebar/project/shading' ) ).setClass( 'Label' ) );
|
|
25
|
+
|
|
26
|
+
const shadingTypeSelect = new UISelect().setOptions( {
|
|
27
|
+
'solid': 'SOLID',
|
|
28
|
+
'realistic': 'REALISTIC'
|
|
29
|
+
} ).setWidth( '170px' ).onChange( refreshShadingRow ).setValue( 'solid' );
|
|
30
|
+
shadingRow.add( shadingTypeSelect );
|
|
31
|
+
|
|
32
|
+
const pathTracerMinSamples = 3;
|
|
33
|
+
const pathTracerMaxSamples = 65536;
|
|
34
|
+
const samplesNumber = new UIInteger( 16 ).setRange( pathTracerMinSamples, pathTracerMaxSamples );
|
|
35
|
+
|
|
36
|
+
const samplesRow = new UIRow();
|
|
37
|
+
samplesRow.add( new UIText( strings.getKey( 'sidebar/project/image/samples' ) ).setClass( 'Label' ) );
|
|
38
|
+
samplesRow.add( samplesNumber );
|
|
39
|
+
|
|
40
|
+
container.add( samplesRow );
|
|
41
|
+
|
|
42
|
+
function refreshShadingRow() {
|
|
43
|
+
|
|
44
|
+
samplesRow.setHidden( shadingTypeSelect.getValue() !== 'realistic' );
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
refreshShadingRow();
|
|
49
|
+
|
|
50
|
+
// Resolution
|
|
51
|
+
|
|
52
|
+
const resolutionRow = new UIRow();
|
|
53
|
+
container.add( resolutionRow );
|
|
54
|
+
|
|
55
|
+
resolutionRow.add( new UIText( strings.getKey( 'sidebar/project/resolution' ) ).setClass( 'Label' ) );
|
|
56
|
+
|
|
57
|
+
const imageWidth = new UIInteger( 1024 ).setTextAlign( 'center' ).setWidth( '28px' );
|
|
58
|
+
resolutionRow.add( imageWidth );
|
|
59
|
+
|
|
60
|
+
resolutionRow.add( new UIText( '×' ).setTextAlign( 'center' ).setFontSize( '12px' ).setWidth( '12px' ) );
|
|
61
|
+
|
|
62
|
+
const imageHeight = new UIInteger( 1024 ).setTextAlign( 'center' ).setWidth( '28px' );
|
|
63
|
+
resolutionRow.add( imageHeight );
|
|
64
|
+
|
|
65
|
+
// Render
|
|
66
|
+
|
|
67
|
+
const renderButton = new UIButton( strings.getKey( 'sidebar/project/render' ) );
|
|
68
|
+
renderButton.setWidth( '170px' );
|
|
69
|
+
renderButton.setMarginLeft( '120px' );
|
|
70
|
+
renderButton.onClick( async () => {
|
|
71
|
+
|
|
72
|
+
if ( shadingTypeSelect.getValue() === 'realistic' ) {
|
|
73
|
+
|
|
74
|
+
let isMaterialsValid = true;
|
|
75
|
+
|
|
76
|
+
editor.scene.traverseVisible( ( object ) => {
|
|
77
|
+
|
|
78
|
+
if ( object.isMesh ) {
|
|
79
|
+
|
|
80
|
+
const materials = Array.isArray( object.material ) ? object.material : [ object.material ];
|
|
81
|
+
|
|
82
|
+
for ( let i = 0; i < materials.length; i ++ ) {
|
|
83
|
+
|
|
84
|
+
const material = materials[ i ];
|
|
85
|
+
|
|
86
|
+
if ( ! material.isMeshStandardMaterial ) {
|
|
87
|
+
|
|
88
|
+
isMaterialsValid = false;
|
|
89
|
+
return;
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
} );
|
|
98
|
+
|
|
99
|
+
if ( isMaterialsValid === false ) {
|
|
100
|
+
|
|
101
|
+
alert( strings.getKey( 'prompt/rendering/realistic/unsupportedMaterial' ) );
|
|
102
|
+
return;
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//
|
|
109
|
+
|
|
110
|
+
const json = editor.toJSON();
|
|
111
|
+
const project = json.project;
|
|
112
|
+
|
|
113
|
+
//
|
|
114
|
+
|
|
115
|
+
const loader = new THREE.ObjectLoader();
|
|
116
|
+
|
|
117
|
+
const camera = loader.parse( json.camera );
|
|
118
|
+
camera.aspect = imageWidth.getValue() / imageHeight.getValue();
|
|
119
|
+
camera.updateProjectionMatrix();
|
|
120
|
+
camera.updateMatrixWorld();
|
|
121
|
+
|
|
122
|
+
const scene = loader.parse( json.scene );
|
|
123
|
+
|
|
124
|
+
const renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
125
|
+
renderer.setSize( imageWidth.getValue(), imageHeight.getValue() );
|
|
126
|
+
|
|
127
|
+
if ( project.shadows !== undefined ) renderer.shadowMap.enabled = project.shadows;
|
|
128
|
+
if ( project.shadowType !== undefined ) renderer.shadowMap.type = project.shadowType;
|
|
129
|
+
if ( project.toneMapping !== undefined ) renderer.toneMapping = project.toneMapping;
|
|
130
|
+
if ( project.toneMappingExposure !== undefined ) renderer.toneMappingExposure = project.toneMappingExposure;
|
|
131
|
+
|
|
132
|
+
// popup
|
|
133
|
+
|
|
134
|
+
const width = imageWidth.getValue() / window.devicePixelRatio;
|
|
135
|
+
const height = imageHeight.getValue() / window.devicePixelRatio;
|
|
136
|
+
|
|
137
|
+
const left = ( screen.width - width ) / 2;
|
|
138
|
+
const top = ( screen.height - height ) / 2;
|
|
139
|
+
|
|
140
|
+
const output = window.open( '', '_blank', `location=no,left=${left},top=${top},width=${width},height=${height}` );
|
|
141
|
+
|
|
142
|
+
const meta = document.createElement( 'meta' );
|
|
143
|
+
meta.name = 'viewport';
|
|
144
|
+
meta.content = 'width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0';
|
|
145
|
+
output.document.head.appendChild( meta );
|
|
146
|
+
|
|
147
|
+
output.document.body.style.background = '#000';
|
|
148
|
+
output.document.body.style.margin = '0px';
|
|
149
|
+
output.document.body.style.overflow = 'hidden';
|
|
150
|
+
|
|
151
|
+
const canvas = renderer.domElement;
|
|
152
|
+
canvas.style.width = width + 'px';
|
|
153
|
+
canvas.style.height = height + 'px';
|
|
154
|
+
output.document.body.appendChild( canvas );
|
|
155
|
+
|
|
156
|
+
//
|
|
157
|
+
|
|
158
|
+
switch ( shadingTypeSelect.getValue() ) {
|
|
159
|
+
|
|
160
|
+
case 'solid':
|
|
161
|
+
|
|
162
|
+
renderer.render( scene, camera );
|
|
163
|
+
renderer.dispose();
|
|
164
|
+
|
|
165
|
+
break;
|
|
166
|
+
|
|
167
|
+
case 'realistic':
|
|
168
|
+
|
|
169
|
+
const status = document.createElement( 'div' );
|
|
170
|
+
status.style.position = 'absolute';
|
|
171
|
+
status.style.top = '10px';
|
|
172
|
+
status.style.left = '10px';
|
|
173
|
+
status.style.color = 'white';
|
|
174
|
+
status.style.fontFamily = 'system-ui';
|
|
175
|
+
status.style.fontSize = '12px';
|
|
176
|
+
output.document.body.appendChild( status );
|
|
177
|
+
|
|
178
|
+
const pathTracer = new ViewportPathtracer( renderer );
|
|
179
|
+
pathTracer.init( scene, camera );
|
|
180
|
+
pathTracer.setSize( imageWidth.getValue(), imageHeight.getValue() );
|
|
181
|
+
|
|
182
|
+
const maxSamples = Math.max( pathTracerMinSamples, Math.min( pathTracerMaxSamples, samplesNumber.getValue() ) );
|
|
183
|
+
|
|
184
|
+
function animate() {
|
|
185
|
+
|
|
186
|
+
if ( output.closed === true ) return;
|
|
187
|
+
|
|
188
|
+
const samples = Math.floor( pathTracer.getSamples() ) + 1;
|
|
189
|
+
|
|
190
|
+
if ( samples < maxSamples ) {
|
|
191
|
+
|
|
192
|
+
requestAnimationFrame( animate );
|
|
193
|
+
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
pathTracer.update();
|
|
197
|
+
|
|
198
|
+
const progress = Math.floor( samples / maxSamples * 100 );
|
|
199
|
+
|
|
200
|
+
status.textContent = `${ samples } / ${ maxSamples } ( ${ progress }% )`;
|
|
201
|
+
|
|
202
|
+
if ( progress === 100 ) {
|
|
203
|
+
|
|
204
|
+
status.textContent += ' ✓';
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
animate();
|
|
211
|
+
|
|
212
|
+
break;
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
} );
|
|
217
|
+
container.add( renderButton );
|
|
218
|
+
|
|
219
|
+
//
|
|
220
|
+
|
|
221
|
+
return container;
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { SidebarProjectImage };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { UIBreak, UIPanel, UIRow, UIText, UIListbox, UIButton } from './libs/ui.js';
|
|
2
|
+
|
|
3
|
+
import { SetMaterialCommand } from './commands/SetMaterialCommand.js';
|
|
4
|
+
|
|
5
|
+
function SidebarProjectMaterials( editor ) {
|
|
6
|
+
|
|
7
|
+
const signals = editor.signals;
|
|
8
|
+
const strings = editor.strings;
|
|
9
|
+
|
|
10
|
+
const container = new UIPanel();
|
|
11
|
+
|
|
12
|
+
const headerRow = new UIRow();
|
|
13
|
+
headerRow.add( new UIText( strings.getKey( 'sidebar/project/materials' ).toUpperCase() ) );
|
|
14
|
+
|
|
15
|
+
container.add( headerRow );
|
|
16
|
+
|
|
17
|
+
const listbox = new UIListbox();
|
|
18
|
+
container.add( listbox );
|
|
19
|
+
|
|
20
|
+
container.add( new UIBreak() );
|
|
21
|
+
|
|
22
|
+
const buttonsRow = new UIRow();
|
|
23
|
+
container.add( buttonsRow );
|
|
24
|
+
|
|
25
|
+
const assignMaterial = new UIButton( strings.getKey( 'sidebar/project/Assign' ) );
|
|
26
|
+
assignMaterial.onClick( function () {
|
|
27
|
+
|
|
28
|
+
const selectedObject = editor.selected;
|
|
29
|
+
|
|
30
|
+
if ( selectedObject !== null ) {
|
|
31
|
+
|
|
32
|
+
const oldMaterial = selectedObject.material;
|
|
33
|
+
|
|
34
|
+
// only assing materials to objects with a material property (e.g. avoid assigning material to THREE.Group)
|
|
35
|
+
|
|
36
|
+
if ( oldMaterial !== undefined ) {
|
|
37
|
+
|
|
38
|
+
const material = editor.getMaterialById( parseInt( listbox.getValue() ) );
|
|
39
|
+
|
|
40
|
+
if ( material !== undefined ) {
|
|
41
|
+
|
|
42
|
+
editor.removeMaterial( oldMaterial );
|
|
43
|
+
editor.execute( new SetMaterialCommand( editor, selectedObject, material ) );
|
|
44
|
+
editor.addMaterial( material );
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} );
|
|
53
|
+
buttonsRow.add( assignMaterial );
|
|
54
|
+
|
|
55
|
+
// Signals
|
|
56
|
+
|
|
57
|
+
function refreshMaterialBrowserUI() {
|
|
58
|
+
|
|
59
|
+
listbox.setItems( Object.values( editor.materials ) );
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
signals.objectSelected.add( function ( object ) {
|
|
64
|
+
|
|
65
|
+
if ( object !== null ) {
|
|
66
|
+
|
|
67
|
+
const index = Object.values( editor.materials ).indexOf( object.material );
|
|
68
|
+
listbox.selectIndex( index );
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
} );
|
|
73
|
+
|
|
74
|
+
signals.materialAdded.add( refreshMaterialBrowserUI );
|
|
75
|
+
signals.materialChanged.add( refreshMaterialBrowserUI );
|
|
76
|
+
signals.materialRemoved.add( refreshMaterialBrowserUI );
|
|
77
|
+
|
|
78
|
+
return container;
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { SidebarProjectMaterials };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
import { UINumber, UIPanel, UIRow, UISelect, UIText } from './libs/ui.js';
|
|
4
|
+
import { UIBoolean } from './libs/ui.three.js';
|
|
5
|
+
|
|
6
|
+
function SidebarProjectRenderer( editor ) {
|
|
7
|
+
|
|
8
|
+
const config = editor.config;
|
|
9
|
+
const signals = editor.signals;
|
|
10
|
+
const strings = editor.strings;
|
|
11
|
+
|
|
12
|
+
let currentRenderer = null;
|
|
13
|
+
|
|
14
|
+
const container = new UIPanel();
|
|
15
|
+
container.setBorderTop( '0px' );
|
|
16
|
+
|
|
17
|
+
// Antialias
|
|
18
|
+
|
|
19
|
+
const antialiasRow = new UIRow();
|
|
20
|
+
container.add( antialiasRow );
|
|
21
|
+
|
|
22
|
+
antialiasRow.add( new UIText( strings.getKey( 'sidebar/project/antialias' ) ).setClass( 'Label' ) );
|
|
23
|
+
|
|
24
|
+
const antialiasBoolean = new UIBoolean( config.getKey( 'project/renderer/antialias' ) ).onChange( createRenderer );
|
|
25
|
+
antialiasRow.add( antialiasBoolean );
|
|
26
|
+
|
|
27
|
+
// Shadows
|
|
28
|
+
|
|
29
|
+
const shadowsRow = new UIRow();
|
|
30
|
+
container.add( shadowsRow );
|
|
31
|
+
|
|
32
|
+
shadowsRow.add( new UIText( strings.getKey( 'sidebar/project/shadows' ) ).setClass( 'Label' ) );
|
|
33
|
+
|
|
34
|
+
const shadowsBoolean = new UIBoolean( config.getKey( 'project/renderer/shadows' ) ).onChange( updateShadows );
|
|
35
|
+
shadowsRow.add( shadowsBoolean );
|
|
36
|
+
|
|
37
|
+
const shadowTypeSelect = new UISelect().setOptions( {
|
|
38
|
+
0: 'Basic',
|
|
39
|
+
1: 'PCF',
|
|
40
|
+
2: 'PCF Soft',
|
|
41
|
+
// 3: 'VSM'
|
|
42
|
+
} ).setWidth( '125px' ).onChange( updateShadows );
|
|
43
|
+
shadowTypeSelect.setValue( config.getKey( 'project/renderer/shadowType' ) );
|
|
44
|
+
shadowsRow.add( shadowTypeSelect );
|
|
45
|
+
|
|
46
|
+
function updateShadows() {
|
|
47
|
+
|
|
48
|
+
currentRenderer.shadowMap.enabled = shadowsBoolean.getValue();
|
|
49
|
+
currentRenderer.shadowMap.type = parseFloat( shadowTypeSelect.getValue() );
|
|
50
|
+
|
|
51
|
+
signals.rendererUpdated.dispatch();
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Tonemapping
|
|
56
|
+
|
|
57
|
+
const toneMappingRow = new UIRow();
|
|
58
|
+
container.add( toneMappingRow );
|
|
59
|
+
|
|
60
|
+
toneMappingRow.add( new UIText( strings.getKey( 'sidebar/project/toneMapping' ) ).setClass( 'Label' ) );
|
|
61
|
+
|
|
62
|
+
const toneMappingSelect = new UISelect().setOptions( {
|
|
63
|
+
0: 'No',
|
|
64
|
+
1: 'Linear',
|
|
65
|
+
2: 'Reinhard',
|
|
66
|
+
3: 'Cineon',
|
|
67
|
+
4: 'ACESFilmic',
|
|
68
|
+
6: 'AgX',
|
|
69
|
+
7: 'Neutral'
|
|
70
|
+
} ).setWidth( '120px' ).onChange( updateToneMapping );
|
|
71
|
+
toneMappingSelect.setValue( config.getKey( 'project/renderer/toneMapping' ) );
|
|
72
|
+
toneMappingRow.add( toneMappingSelect );
|
|
73
|
+
|
|
74
|
+
const toneMappingExposure = new UINumber( config.getKey( 'project/renderer/toneMappingExposure' ) );
|
|
75
|
+
toneMappingExposure.setDisplay( toneMappingSelect.getValue() === '0' ? 'none' : '' );
|
|
76
|
+
toneMappingExposure.setWidth( '30px' ).setMarginLeft( '10px' );
|
|
77
|
+
toneMappingExposure.setRange( 0, 10 );
|
|
78
|
+
toneMappingExposure.onChange( updateToneMapping );
|
|
79
|
+
toneMappingRow.add( toneMappingExposure );
|
|
80
|
+
|
|
81
|
+
function updateToneMapping() {
|
|
82
|
+
|
|
83
|
+
toneMappingExposure.setDisplay( toneMappingSelect.getValue() === '0' ? 'none' : '' );
|
|
84
|
+
|
|
85
|
+
currentRenderer.toneMapping = parseFloat( toneMappingSelect.getValue() );
|
|
86
|
+
currentRenderer.toneMappingExposure = toneMappingExposure.getValue();
|
|
87
|
+
signals.rendererUpdated.dispatch();
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//
|
|
92
|
+
|
|
93
|
+
function createRenderer() {
|
|
94
|
+
|
|
95
|
+
currentRenderer = new THREE.WebGLRenderer( { antialias: antialiasBoolean.getValue() } );
|
|
96
|
+
currentRenderer.shadowMap.enabled = shadowsBoolean.getValue();
|
|
97
|
+
currentRenderer.shadowMap.type = parseFloat( shadowTypeSelect.getValue() );
|
|
98
|
+
currentRenderer.toneMapping = parseFloat( toneMappingSelect.getValue() );
|
|
99
|
+
currentRenderer.toneMappingExposure = toneMappingExposure.getValue();
|
|
100
|
+
|
|
101
|
+
signals.rendererCreated.dispatch( currentRenderer );
|
|
102
|
+
signals.rendererUpdated.dispatch();
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
createRenderer();
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
// Signals
|
|
110
|
+
|
|
111
|
+
signals.editorCleared.add( function () {
|
|
112
|
+
|
|
113
|
+
currentRenderer.shadowMap.enabled = true;
|
|
114
|
+
currentRenderer.shadowMap.type = THREE.PCFShadowMap;
|
|
115
|
+
currentRenderer.toneMapping = THREE.NoToneMapping;
|
|
116
|
+
currentRenderer.toneMappingExposure = 1;
|
|
117
|
+
|
|
118
|
+
shadowsBoolean.setValue( currentRenderer.shadowMap.enabled );
|
|
119
|
+
shadowTypeSelect.setValue( currentRenderer.shadowMap.type );
|
|
120
|
+
toneMappingSelect.setValue( currentRenderer.toneMapping );
|
|
121
|
+
toneMappingExposure.setValue( currentRenderer.toneMappingExposure );
|
|
122
|
+
toneMappingExposure.setDisplay( currentRenderer.toneMapping === 0 ? 'none' : '' );
|
|
123
|
+
|
|
124
|
+
signals.rendererUpdated.dispatch();
|
|
125
|
+
|
|
126
|
+
} );
|
|
127
|
+
|
|
128
|
+
signals.rendererUpdated.add( function () {
|
|
129
|
+
|
|
130
|
+
config.setKey(
|
|
131
|
+
'project/renderer/antialias', antialiasBoolean.getValue(),
|
|
132
|
+
'project/renderer/shadows', shadowsBoolean.getValue(),
|
|
133
|
+
'project/renderer/shadowType', parseFloat( shadowTypeSelect.getValue() ),
|
|
134
|
+
'project/renderer/toneMapping', parseFloat( toneMappingSelect.getValue() ),
|
|
135
|
+
'project/renderer/toneMappingExposure', toneMappingExposure.getValue()
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
} );
|
|
139
|
+
|
|
140
|
+
return container;
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { SidebarProjectRenderer };
|