Skip to content

Commit 472ed08

Browse files
committed
Merged changes from master- into dev-branch mrdoob#17
- Resulting issues: mrdoob#29, mrdoob#30 - Player behaviour where the player stops when a command is executed, undone or redone removed.
1 parent 353a27e commit 472ed08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3300
-237
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.swp
33
.project
44
node_modules
5+
.idea/

editor/css/dark.css

+8-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ input.Number {
127127
#menubar .menu .options .option:active {
128128
background: transparent;
129129
}
130-
130+
131+
#menubar .menu .options .inactive {
132+
color: #444;
133+
background-color: transparent;
134+
padding: 5px 10px;
135+
margin: 0px !important;
136+
}
137+
131138
#sidebar {
132139
position: absolute;
133140
right: 0px;

editor/css/light.css

+7
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ input.Number {
122122
background: transparent;
123123
}
124124

125+
#menubar .menu .options .inactive {
126+
color: #bbb;
127+
background-color: transparent;
128+
padding: 5px 10px;
129+
margin: 0px !important;
130+
}
131+
125132
#sidebar {
126133
position: absolute;
127134
right: 0px;

editor/index.html

+35
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,30 @@
114114
<script src="js/Sidebar.Geometry.TorusKnotGeometry.js"></script>
115115
<script src="js/Sidebar.Material.js"></script>
116116
<script src="js/Sidebar.Script.js"></script>
117+
<script src="js/Sidebar.History.js"></script>
117118
<script src="js/Toolbar.js"></script>
118119
<script src="js/Viewport.js"></script>
119120
<script src="js/Viewport.Info.js"></script>
121+
<script src="js/Cmd.js"></script>
122+
<script src="js/CmdAddObject.js"></script>
123+
<script src="js/CmdRemoveObject.js"></script>
124+
<script src="js/CmdMoveObject.js"></script>
125+
<script src="js/CmdSetPosition.js"></script>
126+
<script src="js/CmdSetRotation.js"></script>
127+
<script src="js/CmdSetScale.js"></script>
128+
<script src="js/CmdToggleBoolean.js"></script>
129+
<script src="js/CmdSetValue.js"></script>
130+
<script src="js/CmdSetUuid.js"></script>
131+
<script src="js/CmdSetColor.js"></script>
132+
<script src="js/CmdSetGeometry.js"></script>
133+
<script src="js/CmdSetGeometryValue.js"></script>
134+
<script src="js/CmdMultiCmds.js"></script>
135+
<script src="js/CmdAddScript.js"></script>
136+
<script src="js/CmdRemoveScript.js"></script>
137+
<script src="js/CmdSetScriptName.js"></script>
138+
<script src="js/CmdSetScriptSource.js"></script>
139+
<script src="js/CmdSetMaterialValue.js"></script>
140+
<script src="js/CmdSetScene.js"></script>
120141

121142
<script>
122143

@@ -218,6 +239,7 @@
218239
signals.materialChanged.add( saveState );
219240
signals.sceneGraphChanged.add( saveState );
220241
signals.scriptChanged.add( saveState );
242+
signals.historyChanged.add( saveState );
221243

222244
/*
223245
var showDialog = function ( content ) {
@@ -271,6 +293,19 @@
271293
editor.select( parent );
272294

273295
break;
296+
297+
case 90: // Register Ctrl-Z for Undo, Ctrl-Shift-Z for Redo
298+
299+
if ( event.ctrlKey && event.shiftKey ) {
300+
301+
editor.redo();
302+
303+
} else if ( event.ctrlKey ) {
304+
305+
editor.undo();
306+
307+
}
308+
break;
274309

275310
}
276311

editor/js/Cmd.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Created by Daniel on 20.07.15.
3+
*/
4+
5+
Cmd = function () {
6+
7+
this.id = -1;
8+
this.serialized = false;
9+
this.updatable = false;
10+
this.type = '';
11+
12+
};
13+
14+
Cmd.prototype.toJSON = function () {
15+
16+
var output = {};
17+
output.type = this.type;
18+
output.id = this.id;
19+
return output;
20+
21+
};
22+
23+
Cmd.prototype.fromJSON = function ( json ) {
24+
25+
this.type = json.type;
26+
this.id = json.id;
27+
28+
};

editor/js/CmdAddObject.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Created by Daniel on 20.07.15.
3+
*/
4+
5+
CmdAddObject = function ( object ) {
6+
7+
Cmd.call( this );
8+
9+
this.type = 'CmdAddObject';
10+
11+
this.object = object;
12+
if ( object !== undefined ) {
13+
14+
object.updateMatrixWorld( true );
15+
meta = {
16+
geometries: {},
17+
materials: {},
18+
textures: {},
19+
images: {}
20+
};
21+
this.objectJSON = object.toJSON( meta );
22+
23+
}
24+
25+
};
26+
27+
CmdAddObject.prototype = {
28+
29+
execute: function () {
30+
31+
this.editor.addObject( this.object );
32+
33+
},
34+
35+
undo: function () {
36+
37+
this.editor.removeObject( this.object );
38+
this.editor.deselect();
39+
40+
},
41+
42+
toJSON: function () {
43+
44+
var output = Cmd.prototype.toJSON.call( this );
45+
46+
output.object = this.objectJSON;
47+
48+
return output;
49+
50+
},
51+
52+
fromJSON: function ( json ) {
53+
54+
Cmd.prototype.fromJSON.call( this, json );
55+
56+
this.objectJSON = json.object;
57+
this.object = this.editor.objectByUuid( json.object.object.uuid );
58+
59+
if ( this.object === undefined ) {
60+
61+
var loader = new THREE.ObjectLoader();
62+
this.object = loader.parse( json.object );
63+
64+
}
65+
66+
}
67+
68+
};

editor/js/CmdAddScript.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Created by Daniel on 20.07.15.
3+
*/
4+
5+
CmdAddScript = function ( object, script ) {
6+
7+
Cmd.call( this );
8+
9+
this.type = 'CmdAddScript';
10+
11+
this.object = object;
12+
this.objectUuid = object !== undefined ? object.uuid : undefined;
13+
14+
this.script = script;
15+
};
16+
17+
CmdAddScript.prototype = {
18+
19+
execute: function () {
20+
21+
if ( this.editor.scripts[ this.object.uuid ] === undefined ) {
22+
23+
this.editor.scripts[ this.object.uuid ] = [];
24+
25+
}
26+
27+
this.editor.scripts[ this.object.uuid ].push( this.script );
28+
29+
this.editor.signals.scriptAdded.dispatch( this.script );
30+
31+
},
32+
33+
undo: function () {
34+
35+
if ( this.editor.scripts[ this.object.uuid ] === undefined ) return;
36+
37+
var index = this.editor.scripts[ this.object.uuid ].indexOf( this.script );
38+
39+
if ( index !== - 1 ) {
40+
41+
this.editor.scripts[ this.object.uuid ].splice( index, 1 );
42+
43+
}
44+
45+
this.editor.signals.scriptRemoved.dispatch( this.script );
46+
47+
},
48+
49+
toJSON: function () {
50+
51+
var output = Cmd.prototype.toJSON.call( this );
52+
53+
output.objectUuid = this.objectUuid;
54+
output.script = this.script;
55+
56+
return output;
57+
58+
},
59+
60+
fromJSON: function ( json ) {
61+
62+
Cmd.prototype.fromJSON.call( this, json );
63+
64+
this.objectUuid = json.objectUuid;
65+
this.script = json.script;
66+
this.object = this.editor.objectByUuid( json.objectUuid );
67+
68+
}
69+
70+
};

editor/js/CmdMoveObject.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Created by Daniel on 20.07.15.
3+
*/
4+
5+
CmdMoveObject = function ( object, newParent, newBefore ) {
6+
7+
Cmd.call( this );
8+
9+
this.type = 'CmdMoveObject';
10+
11+
this.object = object;
12+
this.objectUuid = object !== undefined ? object.uuid : undefined;
13+
14+
this.oldParent = object !== undefined ? object.parent : undefined;
15+
this.oldParentUuid = this.oldParent !== undefined ? this.oldParent.uuid : undefined;
16+
this.oldIndex = this.oldParent !== undefined ? this.oldParent.children.indexOf( this.object ) : undefined;
17+
18+
this.newParent = newParent;
19+
this.newParentUuid = newParent !== undefined ? newParent.uuid : undefined;
20+
21+
if ( newBefore !== undefined ) {
22+
23+
this.newIndex = newParent !== undefined ? newParent.children.indexOf( newBefore ) : undefined;
24+
25+
} else {
26+
27+
this.newIndex = newParent !== undefined ? newParent.children.length : undefined;
28+
29+
}
30+
31+
if ( this.oldParent === this.newParent && this.newIndex > this.oldIndex ) {
32+
33+
this.newIndex --;
34+
35+
}
36+
37+
this.newBefore = newBefore;
38+
39+
};
40+
41+
CmdMoveObject.prototype = {
42+
43+
execute: function () {
44+
45+
this.oldParent.remove( this.object );
46+
47+
var children = this.newParent.children;
48+
children.splice( this.newIndex, 0, this.object );
49+
this.object.parent = this.newParent;
50+
51+
this.editor.signals.sceneGraphChanged.dispatch();
52+
53+
},
54+
55+
undo: function () {
56+
57+
this.newParent.remove( this.object );
58+
59+
var children = this.oldParent.children;
60+
children.splice( this.oldIndex, 0, this.object );
61+
this.object.parent = this.oldParent;
62+
63+
this.editor.signals.sceneGraphChanged.dispatch();
64+
65+
},
66+
67+
toJSON: function () {
68+
69+
var output = Cmd.prototype.toJSON.call( this );
70+
71+
output.objectUuid = this.objectUuid;
72+
output.newParentUuid = this.newParentUuid;
73+
output.oldParentUuid = this.oldParentUuid;
74+
output.newIndex = this.newIndex;
75+
output.oldIndex = this.oldIndex;
76+
77+
return output;
78+
79+
},
80+
81+
fromJSON: function ( json ) {
82+
83+
Cmd.prototype.fromJSON.call( this, json );
84+
85+
this.object = this.editor.objectByUuid( json.objectUuid );
86+
this.objectUuid = json.objectUuid;
87+
88+
this.oldParent = this.editor.objectByUuid( json.oldParentUuid );
89+
this.oldParentUuid = json.oldParentUuid;
90+
91+
this.newParent = this.editor.objectByUuid( json.newParentUuid );
92+
this.newParentUuid = json.newParentUuid;
93+
94+
this.newIndex = json.newIndex;
95+
this.oldIndex = json.oldIndex;
96+
97+
}
98+
99+
};

0 commit comments

Comments
 (0)