sunrize 1.2.0 → 1.2.2

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.
@@ -152,7 +152,8 @@ module .exports = class ScriptEditor extends Interface
152
152
 
153
153
  if (this .node)
154
154
  {
155
- this .node ._url .removeFieldCallback (this);
155
+ this .node ._url .removeFieldCallback (this);
156
+ this .node ._loadState .removeFieldCallback (this);
156
157
 
157
158
  switch (this .node .getTypeName ())
158
159
  {
@@ -190,7 +191,10 @@ module .exports = class ScriptEditor extends Interface
190
191
 
191
192
  this .monaco .restoreViewState (this .monaco .viewState);
192
193
 
193
- this .node ._url .addFieldCallback (this, this .set_url .bind (this));
194
+ this .node ._url .addFieldCallback (this, this .set_url .bind (this));
195
+ this .node ._loadState .addFieldCallback (this, this .set_loadState .bind (this));
196
+
197
+ this .set_loadState ();
194
198
 
195
199
  switch (this .node .getTypeName ())
196
200
  {
@@ -438,7 +442,7 @@ function set_field (value, time)
438
442
 
439
443
  UndoManager .shared .endUndo ();
440
444
 
441
- this .setNode (nodes [0]);
445
+ this .nodeList .setNode (nodes [0]);
442
446
  }
443
447
 
444
448
  async createShader ()
@@ -492,7 +496,7 @@ main ()
492
496
 
493
497
  UndoManager .shared .endUndo ();
494
498
 
495
- this .setNode (nodes [0] ._parts [0] .getValue ());
499
+ this .nodeList .setNode (nodes [0] ._parts [0] .getValue ());
496
500
  }
497
501
 
498
502
  apply ()
@@ -518,6 +522,26 @@ main ()
518
522
  this .monaco .getModel () .setValue (this .node ._url [0]);
519
523
  }
520
524
 
525
+ set_loadState ()
526
+ {
527
+ this .applyButton .removeClass (["red", "green", "yellow"]);
528
+
529
+ switch (this .node .checkLoadState ())
530
+ {
531
+ case X3D .X3DConstants .NOT_STATED_STATE:
532
+ break;
533
+ case X3D .X3DConstants .IN_PROGRESS_STATE:
534
+ this .applyButton .addClass ("yellow");
535
+ break;
536
+ case X3D .X3DConstants .COMPLETE_STATE:
537
+ this .applyButton .addClass ("green");
538
+ break;
539
+ case X3D .X3DConstants .FAILED_STATE:
540
+ this .applyButton .addClass ("red");
541
+ break;
542
+ }
543
+ }
544
+
521
545
  debugFindActions (editor)
522
546
  {
523
547
  for (const action of editor .getSupportedActions ())
@@ -3,6 +3,7 @@
3
3
  const
4
4
  X3DNodeTool = require ("./X3DNodeTool"),
5
5
  X3D = require ("../../X3D"),
6
+ Editor = require ("../../Undo/Editor"),
6
7
  UndoManager = require ("../../Undo/UndoManager"),
7
8
  _ = require ("../../Application/GetText");
8
9
 
@@ -10,6 +11,9 @@ class X3DChildNodeTool extends X3DNodeTool
10
11
  {
11
12
  static #tools = new Set ();
12
13
 
14
+ #groupedTools = new Set ();
15
+ #initialValues = new Map ();
16
+
13
17
  getMustDisplay ()
14
18
  {
15
19
  return true;
@@ -40,71 +44,86 @@ class X3DChildNodeTool extends X3DNodeTool
40
44
  this .finishUndo ()
41
45
  }
42
46
 
43
- prepareUndo (center = false)
47
+ prepareUndo ()
44
48
  {
45
49
  // Begin undo.
46
50
 
47
51
  const
48
- tool = center ? 3 : this .tool .activeTool,
49
- typeName = this .getTypeName (),
50
- name = this .getDisplayName ();
52
+ typeName = this .getTypeName (),
53
+ name = this .getDisplayName (),
54
+ description = this .getUndoDescription (this .tool .activeTool, name);
55
+
56
+ UndoManager .shared .beginUndo (description, typeName, name);
57
+
58
+ // Prepare undo.
59
+
60
+ if (this .beginUndo () === false)
61
+ return;
62
+
63
+ this .#groupedTools .add (this);
64
+
65
+ if (this .tool .group === "NONE")
66
+ return;
67
+
68
+ // Prepare grouping.
69
+
70
+ for (const other of X3DChildNodeTool .#tools)
71
+ {
72
+ if (other .tool .group === `${this .tool .activeTool}_TOOL`)
73
+ other .tool .grouping = true;
74
+ }
75
+
76
+ for (const other of X3DChildNodeTool .#tools)
77
+ {
78
+ if (other === this)
79
+ continue;
80
+
81
+ if (other .tool .group !== this .tool .group)
82
+ continue;
83
+
84
+ if (other .beginUndo () === false)
85
+ continue;
86
+
87
+ this .#groupedTools .add (other);
88
+ }
89
+ }
51
90
 
52
- switch (tool)
91
+ getUndoDescription (activeTool, name)
92
+ {
93
+ switch (activeTool)
53
94
  {
54
- case 0: // "TRANSLATE"
95
+ case "TRANSLATE":
55
96
  {
56
97
  if (name)
57
- UndoManager .shared .beginUndo (_ ("Translate %s »%s«"), typeName, name);
58
- else
59
- UndoManager .shared .beginUndo (_ ("Translate %s"), typeName);
60
- break;
98
+ return _ ("Translate %s »%s«");
99
+
100
+ return _ ("Translate %s");
61
101
  }
62
- case 1: // "ROTATE"
102
+ case "ROTATE":
63
103
  {
64
104
  if (name)
65
- UndoManager .shared .beginUndo (_ ("Rotate %s »%s«"), typeName, name);
66
- else
67
- UndoManager .shared .beginUndo (_ ("Rotate %s"), typeName);
68
- break;
105
+ return _ ("Rotate %s »%s«");
106
+
107
+ return _ ("Rotate %s");
69
108
  }
70
- case 2: // "SCALE"
109
+ case "SCALE":
71
110
  {
72
111
  if (name)
73
- UndoManager .shared .beginUndo (_ ("Scale %s »%s«"), typeName, name);
74
- else
75
- UndoManager .shared .beginUndo (_ ("Scale %s"), typeName);
76
- break;
112
+ return _ ("Scale %s »%s«");
113
+
114
+ return _ ("Scale %s");
77
115
  }
78
- case 3: // "CENTER"
116
+ case "CENTER":
79
117
  {
80
118
  if (name)
81
- UndoManager .shared .beginUndo (_ ("Translate Center Of %s »%s«"), typeName, name);
82
- else
83
- UndoManager .shared .beginUndo (_ ("Translate Center Of %s"), typeName);
84
- break;
85
- }
86
- }
87
-
88
- // Prepare grouping.
119
+ return _ ("Translate Center of Node %s »%s«");
89
120
 
90
- for (const other of X3DChildNodeTool .#tools)
91
- {
92
- if (other !== this)
93
- {
94
- if (other .tool .group === "NONE")
95
- continue;
121
+ return _ ("Translate Center of Node %s");
96
122
  }
97
-
98
- if (!center)
123
+ default:
99
124
  {
100
- if (other .tool .group !== this .tool .group)
101
- continue;
125
+ return `No Undo Description Available For '${activeTool}'`;
102
126
  }
103
-
104
- if (other .beginUndo (this) === false)
105
- continue;
106
-
107
- other .tool .grouped = true;
108
127
  }
109
128
  }
110
129
 
@@ -112,20 +131,44 @@ class X3DChildNodeTool extends X3DNodeTool
112
131
  {
113
132
  for (const other of X3DChildNodeTool .#tools)
114
133
  {
115
- if (!other .tool .grouped)
116
- continue;
117
-
118
- other .tool .grouped = false;
134
+ if (other .tool .grouping)
135
+ other .tool .grouping = false;
136
+ }
119
137
 
138
+ for (const other of this .#groupedTools)
120
139
  other .endUndo ();
121
- }
140
+
141
+ this .#groupedTools .clear ();
122
142
 
123
143
  UndoManager .shared .endUndo ();
124
144
  }
125
145
 
126
146
  beginUndo () { }
127
147
 
128
- endUndo () { }
148
+ endUndo ()
149
+ {
150
+ this .undoSetValues ();
151
+ }
152
+
153
+ undoSaveInitialValues (fields)
154
+ {
155
+ for (const name of fields)
156
+ this .#initialValues .set (name, this .getField (name) .copy ());
157
+ }
158
+
159
+ undoSetValues ()
160
+ {
161
+ for (const [name, initialValue] of this .#initialValues)
162
+ {
163
+ const value = this .getField (name) .copy ();
164
+
165
+ this .getField (name) .assign (initialValue);
166
+
167
+ Editor .setFieldValue (this .getExecutionContext (), this .node, this .getField (name), value);
168
+ }
169
+
170
+ this .#initialValues .clear ();
171
+ }
129
172
 
130
173
  traverse (type, renderObject)
131
174
  {
@@ -4,8 +4,7 @@ const
4
4
  path = require ("path"),
5
5
  url = require ("url"),
6
6
  X3D = require ("../../X3D"),
7
- Traverse = require ("../../Application/Traverse"),
8
- DEBUG = false && process .env .SUNRISE_ENVIRONMENT === "DEVELOPMENT";
7
+ Traverse = require ("../../Application/Traverse");
9
8
 
10
9
  const
11
10
  _tool = Symbol .for ("Sunrize.tool"),
@@ -56,6 +55,10 @@ const handler =
56
55
  },
57
56
  }
58
57
 
58
+ const
59
+ _proxy = Symbol (),
60
+ _externalNodes = Symbol ();
61
+
59
62
  class X3DNodeTool
60
63
  {
61
64
  static createOnSelection = true;
@@ -68,9 +71,11 @@ class X3DNodeTool
68
71
  node .setUserData (_tool, proxy);
69
72
  node .setUserData (_changing, true);
70
73
 
71
- this .proxy = proxy;
72
- this .node = node;
73
- this .externalNodes = new Map ();
74
+ X3D .SFNodeCache .add (proxy, X3D .SFNodeCache .get (node));
75
+
76
+ this .node = node;
77
+ this [_proxy] = proxy;
78
+ this [_externalNodes] = new Map ();
74
79
 
75
80
  this .replaceNode (node, proxy);
76
81
  proxy .setupTool ();
@@ -80,7 +85,7 @@ class X3DNodeTool
80
85
 
81
86
  getInnerNode ()
82
87
  {
83
- return this .proxy;
88
+ return this [_proxy];
84
89
  }
85
90
 
86
91
  replaceNode (node, replacement)
@@ -124,7 +129,7 @@ class X3DNodeTool
124
129
 
125
130
  addTool ()
126
131
  {
127
- return this .proxy;
132
+ return this [_proxy];
128
133
  }
129
134
 
130
135
  static #scenes = new Map ();
@@ -135,7 +140,7 @@ class X3DNodeTool
135
140
  protoURL = url .pathToFileURL (path .resolve (... args)),
136
141
  promise = X3DNodeTool .#scenes .get (protoURL .href);
137
142
 
138
- if (promise && !DEBUG)
143
+ if (promise)
139
144
  {
140
145
  return this .toolPromise = promise .then (scene => this .tool = this .createTool (scene));
141
146
  }
@@ -181,7 +186,7 @@ class X3DNodeTool
181
186
  {
182
187
  field .addInterest ("addExternalNode", this);
183
188
 
184
- this .externalNodes .set (field .getValue (), field);
189
+ this [_externalNodes] .set (field .getValue (), field);
185
190
  }
186
191
 
187
192
  removeTool (action = "createOnDemand")
@@ -196,14 +201,16 @@ class X3DNodeTool
196
201
  this .node .removeUserData (_tool);
197
202
  this .node .setUserData (_changing, true);
198
203
 
204
+ X3D .SFNodeCache .delete (this [_proxy]);
205
+
199
206
  const nodesToDispose = [ ]
200
207
 
201
208
  Traverse .traverse (this .tool, Traverse .ROOT_NODES | Traverse .INLINE_SCENE | Traverse .PROTOTYPE_INSTANCES, node => nodesToDispose .push (node));
202
209
 
203
- for (const node of nodesToDispose .filter (node => !this .externalNodes .has (node)))
210
+ for (const node of nodesToDispose .filter (node => !this [_externalNodes] .has (node)))
204
211
  node .dispose ();
205
212
 
206
- for (const field of this .externalNodes .values ())
213
+ for (const field of this [_externalNodes] .values ())
207
214
  field .removeInterest ("addExternalNode", this);
208
215
 
209
216
  this .replaceNode (this, this .node);
@@ -20,26 +20,9 @@ class X3DEnvironmentalSensorNodeTool extends X3DChildNodeTool
20
20
  this .tool .boxColor = this .toolBoxColor;
21
21
  }
22
22
 
23
- #initialSize;
24
- #initialCenter;
25
-
26
23
  beginUndo ()
27
24
  {
28
- this .#initialSize = this ._size .copy ();
29
- this .#initialCenter = this ._center .copy ();
30
- }
31
-
32
- endUndo ()
33
- {
34
- const
35
- size = this ._size .copy (),
36
- center = this ._center .copy ();
37
-
38
- this ._size = this .#initialSize;
39
- this ._center = this .#initialCenter;
40
-
41
- Editor .setFieldValue (this .getExecutionContext (), this .node, this ._size, size);
42
- Editor .setFieldValue (this .getExecutionContext (), this .node, this ._center, center);
25
+ this .undoSaveInitialValues (["size", "center"]);
43
26
  }
44
27
  }
45
28
 
@@ -17,13 +17,13 @@
17
17
  <ProtoInterface>
18
18
  <field accessType='inputOutput' type='SFBool' name='selected'/>
19
19
  <field accessType='inputOutput' type='SFString' name='group' value='TRANSFORM_TOOL'/>
20
- <field accessType='inputOutput' type='SFBool' name='grouped'/>
20
+ <field accessType='inputOutput' type='SFBool' name='grouping'/>
21
21
  <field accessType='inputOutput' type='SFBool' name='undo' value='true'/>
22
22
  <field accessType='inputOutput' type='SFColor' name='boxColor' value='0.35 1 0.7'/>
23
23
  <field accessType='inputOutput' type='SFVec3f' name='size' value='1 1 1'/>
24
24
  <field accessType='inputOutput' type='SFVec3f' name='center'/>
25
25
  <field accessType='outputOnly' type='SFNode' name='transformTool'/>
26
- <field accessType='outputOnly' type='SFInt32' name='activeTool'/>
26
+ <field accessType='outputOnly' type='SFString' name='activeTool'/>
27
27
  <field accessType='outputOnly' type='SFBool' name='isActive'/>
28
28
  </ProtoInterface>
29
29
  <ProtoBody>
@@ -63,7 +63,7 @@
63
63
  directOutput='true'>
64
64
  <field accessType='inputOutput' type='SFBool' name='selected'/>
65
65
  <field accessType='inputOutput' type='SFColor' name='color'/>
66
- <field accessType='inputOutput' type='SFInt32' name='activeTool'/>
66
+ <field accessType='inputOutput' type='SFString' name='activeTool'/>
67
67
  <field accessType='inputOutput' type='SFBool' name='active'/>
68
68
  <field accessType='initializeOnly' type='SFNode' name='material'>
69
69
  <Material USE='BoxMaterial'/>
@@ -82,8 +82,6 @@
82
82
 
83
83
  async function initialize ()
84
84
  {
85
- set_color ();
86
-
87
85
  const tool = await transform .getValue () .addTool () .getToolInstance ();
88
86
 
89
87
  Browser .addRoute (tool, "activeTool", this, "activeTool");
@@ -30,8 +30,7 @@ class X3DTransformNodeTool extends X3DChildNodeTool
30
30
  this .tool .getField ("scaleOrientation") .addReference (this .node ._scaleOrientation);
31
31
  this .tool .getField ("center") .addReference (this .node ._center);
32
32
 
33
- this .tool .getField ("isCenterActive") .addInterest ("handleUndo", this);
34
- this .tool .getField ("isActive") .addInterest ("handleUndo", this);
33
+ this .tool .getField ("isActive") .addInterest ("handleUndo", this);
35
34
 
36
35
  this .tool .bboxColor = this .toolBBoxColor;
37
36
  }
@@ -79,7 +78,7 @@ class X3DTransformNodeTool extends X3DChildNodeTool
79
78
 
80
79
  prepareUndo ()
81
80
  {
82
- super .prepareUndo (this .tool .isCenterActive);
81
+ super .prepareUndo ();
83
82
  }
84
83
 
85
84
  beginUndo ()
@@ -114,6 +113,14 @@ class X3DTransformNodeTool extends X3DChildNodeTool
114
113
  this ._scaleOrientation = this .#initialScaleOrientation;
115
114
  this ._center = this .#initialCenter;
116
115
 
116
+ Editor .roundToIntegerIfAlmostEqual (translation);
117
+ Editor .roundToIntegerIfAlmostEqual (rotation);
118
+ Editor .roundToIntegerIfAlmostEqual (scale);
119
+ Editor .roundToIntegerIfAlmostEqual (scaleOrientation);
120
+
121
+ if (Editor .almostEqual (scale .x, scale .y) && Editor .almostEqual (scale .x, scale .z))
122
+ scaleOrientation .assign (new X3D .SFRotation ());
123
+
117
124
  Editor .setFieldValue (this .getExecutionContext (), this .node, this ._translation, translation);
118
125
  Editor .setFieldValue (this .getExecutionContext (), this .node, this ._rotation, rotation);
119
126
  Editor .setFieldValue (this .getExecutionContext (), this .node, this ._scale, scale);
@@ -129,6 +136,18 @@ class X3DTransformNodeTool extends X3DChildNodeTool
129
136
  if (!this .tool .isActive)
130
137
  return;
131
138
 
139
+ if (!this .tool .activeTool .match (/^(?:TRANSLATE|ROTATE|SCALE)$/))
140
+ return;
141
+
142
+ if (this .isHidden ())
143
+ return;
144
+
145
+ if (!this ._visible .getValue ())
146
+ return;
147
+
148
+ if (this .tool .group === "NONE")
149
+ return;
150
+
132
151
  const differenceMatrix = this .#initialMatrix .copy ()
133
152
  .multRight (this .#modelMatrix)
134
153
  .inverse ()
@@ -146,9 +165,6 @@ class X3DTransformNodeTool extends X3DChildNodeTool
146
165
  if (!other ._visible .getValue ())
147
166
  continue;
148
167
 
149
- if (other .tool .group === "NONE")
150
- continue;
151
-
152
168
  if (other .tool .group !== this .tool .group)
153
169
  continue;
154
170
 
@@ -214,14 +230,6 @@ class X3DTransformNodeTool extends X3DChildNodeTool
214
230
 
215
231
  matrix .get (translation, rotation, scale, scaleOrientation, center);
216
232
 
217
- Editor .roundToIntegerIfAlmostEqual (translation);
218
- Editor .roundToIntegerIfAlmostEqual (rotation);
219
- Editor .roundToIntegerIfAlmostEqual (scale);
220
- Editor .roundToIntegerIfAlmostEqual (scaleOrientation);
221
-
222
- if (Editor .almostEqual (scale .x, scale .y) && Editor .almostEqual (scale .x, scale .z))
223
- scaleOrientation .set (0, 0, 1, 0);
224
-
225
233
  this ._translation = translation;
226
234
  this ._rotation = rotation;
227
235
  this ._scale = scale;