summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/assets/javascripts/rectangles/engine/sculpture/_sculpture.js24
-rw-r--r--public/assets/javascripts/rectangles/engine/sculpture/types/_object.js91
-rw-r--r--public/assets/javascripts/rectangles/engine/sculpture/types/image.js110
-rw-r--r--public/assets/javascripts/rectangles/models/floor.js7
-rw-r--r--public/assets/javascripts/rectangles/models/vec3.js9
-rw-r--r--public/assets/javascripts/ui/editor/EditorSettings.js3
-rw-r--r--server/lib/schemas/Project.js1
-rw-r--r--views/partials/scripts.ejs1
8 files changed, 149 insertions, 97 deletions
diff --git a/public/assets/javascripts/rectangles/engine/sculpture/_sculpture.js b/public/assets/javascripts/rectangles/engine/sculpture/_sculpture.js
index eb64e92..c8c90d3 100644
--- a/public/assets/javascripts/rectangles/engine/sculpture/_sculpture.js
+++ b/public/assets/javascripts/rectangles/engine/sculpture/_sculpture.js
@@ -4,7 +4,6 @@ var Sculpture = new function(){
var base = this;
base.list = {}
- base.nextMedia = null
base.mouse = new mouse ({ use_offset: false, mousedownUsesCapture: true })
@@ -12,29 +11,28 @@ var Sculpture = new function(){
}
base.add = function(opt){
- var scene_media
+ var sculpture
switch (opt.media.type) {
case 'image':
- scene_media = new Sculpture.types.image (opt)
+ sculpture = new Sculpture.types.image (opt)
break
}
- base.list[scene_media.id] = scene_media
- return scene_media
+ base.list[sculpture.id] = sculpture
+ return sculpture
}
- base.addNextToWall = function(opt){
+ base.addNext = function(opt){
opt.newMedia = true
- opt.media = base.nextMedia
- opt.index = opt.index || 0
- var scene_media = base.add(opt)
+ opt.media = Scenery.nextMedia
+ var sculpture = base.add(opt)
- // test if scenery was placed here
- if (! scene_media) {
+ // test if sculpture was placed here
+ if (! sculpture) {
return null
}
else {
- base.nextMedia = null
- return scene_media
+ Scenery.nextMedia = null
+ return sculpture
}
}
diff --git a/public/assets/javascripts/rectangles/engine/sculpture/types/_object.js b/public/assets/javascripts/rectangles/engine/sculpture/types/_object.js
new file mode 100644
index 0000000..fa6b0b1
--- /dev/null
+++ b/public/assets/javascripts/rectangles/engine/sculpture/types/_object.js
@@ -0,0 +1,91 @@
+Sculpture.types.base = Fiber.extend(function(base){
+
+ var exports = {
+
+ init: function(opt){
+ this.id = opt.id || Sculpture.uid("sculpture")
+ // this.move = new Sculpture.move (this)
+ this.media = opt.media
+ this.naturalDimensions = new vec2(this.media.width, this.media.height)
+
+ this.set_scale( opt.scale || this.media.scale || 1.0 )
+ this.position = new vec2(0,0)
+ },
+
+ set_scale: function(scale){
+ this.scale = scale || 1.0
+ if (this.mx) {
+ this.mx.scale = this.mx.ops.scale = this.scale
+ }
+ this.dimensions = this.naturalDimensions.clone().mul(this.scale)
+ },
+
+ place: function(opt){
+ if (opt.data) {
+ this.deserialize(opt.data)
+ }
+ else {
+ this.mx.move(opt.position)
+ }
+ },
+
+ bind: function(){
+ // this.move.bind()
+ },
+
+ unbind: function(){
+ // this.move.unbind()
+ },
+
+ remove: function(){
+ if (this.removed) return
+ this.removed = true
+
+ UndoStack.push({
+ type: 'destroy-sculpture',
+ undo: this.serialize(),
+ redo: { id: this.id },
+ })
+
+ // TODO: watch individual scenery object here
+ Minotaur.watch( app.router.editorView.settings )
+
+ Sculpture.remove(this.id)
+
+ // Sculpture.resize.hide()
+ if (app.controller.sculptureEditor) {
+ app.controller.sculptureEditor.tainted = false
+ app.controller.sculptureEditor.hide()
+ }
+ },
+
+ destroy: function(){
+ this.unbind()
+ scene.remove(this.mx)
+ this.mx.media = null
+ this.mx.ops = null
+ this.mx = null
+ this.move = null
+ this.media = null
+ this.dimensions = null
+ this.naturalDimensions = null
+ this.wall = null
+ this.bounds = null
+ this.center = null
+ },
+
+ serialize: function(){
+ var data = {
+ id: this.id,
+ dimensions: this.dimensions.serialize(),
+ position: app.position(this.mx),
+ scale: this.scale,
+ media: this.media,
+ }
+ return data
+ },
+ }
+
+ return exports
+
+})
diff --git a/public/assets/javascripts/rectangles/engine/sculpture/types/image.js b/public/assets/javascripts/rectangles/engine/sculpture/types/image.js
index af538f7..ae62133 100644
--- a/public/assets/javascripts/rectangles/engine/sculpture/types/image.js
+++ b/public/assets/javascripts/rectangles/engine/sculpture/types/image.js
@@ -1,98 +1,48 @@
-Scenery.types.base = Fiber.extend(function(base){
- var exports = {
+Sculpture.types.image = Sculpture.types.base.extend(function(base){
+ var exports = {
+
+ type: 'image',
+
init: function(opt){
- _.bindAll(this, 'enter', 'leave')
- this.id = opt.id || Scenery.uid("scenery")
- this.move = new Scenery.move (this)
- this.media = opt.media
- this.naturalDimensions = new vec2(this.media.width, this.media.height)
-
- this.set_scale( opt.scale || this.media.scale || 1.0 )
- this.position = new vec2(0,0)
- },
+ opt.scale = opt.scale || (opt.data && opt.data.scale) || DEFAULT_PICTURE_WIDTH / max(DEFAULT_PICTURE_WIDTH, opt.media.width)
- set_scale: function(scale){
- this.scale = scale || 1.0
- if (this.mx) {
- this.mx.scale = this.mx.ops.scale = this.scale
- }
- this.dimensions = this.naturalDimensions.clone().mul(this.scale)
- },
-
- bind: function(){
- this.move.bind()
-// $(this.mx.el).bind({
-// mouseenter: this.enter,
-// mouseleave: this.leave,
-// })
- },
-
- unbind: function(){
- this.move.unbind()
-// $(this.mx.el).unbind({
-// mouseenter: this.enter,
-// mouseleave: this.leave,
-// })
- },
-
- remove: function(){
- if (this.removed) return
- this.removed = true
-
- UndoStack.push({
- type: 'destroy-sculpture',
- undo: this.serialize(),
- redo: { id: this.id },
- })
+ base.init.call(this, opt)
- // TODO: watch individual scenery object here
- Minotaur.watch( app.router.editorView.settings )
+ this.build(opt)
+ this.bind()
+ this.place(opt)
+ },
- Scenery.remove(this.id)
+ build: function(opt){
+ this.footprint = new MX.Object3D()
+ this.mx = new MX.Image({
+ src: this.media.url,
+ scale: this.scale,
+ media: this.media,
+ backface: true,
+ })
- Scenery.resize.hide()
- if (app.controller.mediaEditor) {
- app.controller.mediaEditor.tainted = false
- app.controller.mediaEditor.hide()
- }
- if (app.controller.textEditor) {
- app.controller.textEditor.tainted = false
- app.controller.textEditor.hide()
- }
- },
+ opt.position.y = opt.position.y || this.scale * this.media.height/2,
+ opt.position.rotationY = opt.position.rotationY || scene.camera.rotationY,
- destroy: function(){
- this.unbind()
- scene.remove(this.mx)
- this.mx.media = null
- this.mx.ops = null
- this.mx = null
- this.move = null
- this.media = null
- this.dimensions = null
- this.naturalDimensions = null
- this.wall = null
- this.bounds = null
- this.center = null
+ scene.add( this.mx )
},
serialize: function(){
- var data = {
- id: this.id,
- wall_id: this.wall && this.wall.id,
- side: this.wall && this.wall.side,
- dimensions: this.dimensions.serialize(),
- position: app.position(this.mx),
- scale: this.scale,
- media: this.media,
- }
+ var data = base.serialize.call(this)
return data
},
+
+ deserialize: function(data){
+ this.mx.move(data.position)
+ this.mx.ops.width = data.dimensions.a
+ this.mx.ops.height = data.dimensions.b
+ this.dimensions.deserialize(data.dimensions)
+ },
}
return exports
-
})
diff --git a/public/assets/javascripts/rectangles/models/floor.js b/public/assets/javascripts/rectangles/models/floor.js
index 7b020a9..530de2b 100644
--- a/public/assets/javascripts/rectangles/models/floor.js
+++ b/public/assets/javascripts/rectangles/models/floor.js
@@ -79,9 +79,8 @@
if (Scenery.nextMedia) {
e.preventDefault()
- var sculpture = Sculpture.addNextToWall({
- index: index,
- position: pos,
+ var sculpture = Sculpture.addNext({
+ position: { x: x, y: 0, z: z },
})
// scenery was not placed
@@ -91,7 +90,7 @@
}
app.controller.toolbar.resetPermissions()
- Sculpture.resize.show(sculpture)
+ // Sculpture.resize.show(sculpture)
Sculpture.hovering = true
// app.controller.pick(sculpture)
diff --git a/public/assets/javascripts/rectangles/models/vec3.js b/public/assets/javascripts/rectangles/models/vec3.js
index c44dfe6..97329ed 100644
--- a/public/assets/javascripts/rectangles/models/vec3.js
+++ b/public/assets/javascripts/rectangles/models/vec3.js
@@ -32,3 +32,12 @@ vec3.prototype.apply_projection = function (m) {
return this;
}
+
+vec3.prototype.serialize = function(){
+ return [ round(this.a), round(this.b), round(this.c) ]
+}
+vec3.prototype.deserialize = function(data){
+ this.a = data[0]
+ this.b = data[1]
+ this.c = data[2]
+} \ No newline at end of file
diff --git a/public/assets/javascripts/ui/editor/EditorSettings.js b/public/assets/javascripts/ui/editor/EditorSettings.js
index b319404..460863e 100644
--- a/public/assets/javascripts/ui/editor/EditorSettings.js
+++ b/public/assets/javascripts/ui/editor/EditorSettings.js
@@ -77,6 +77,7 @@ var EditorSettings = FormView.extend({
data.privacy && this.$privacy.find("[value=" + data.privacy + "]").prop("checked", "checked")
data.media && Scenery.deserialize(data.media)
+ data.sculpture && Sculpture.deserialize(data.sculpture)
}
},
@@ -112,6 +113,7 @@ var EditorSettings = FormView.extend({
clear: function(e){
e.preventDefault()
Scenery.removeAll()
+ Sculpture.removeAll()
},
destroy: function(){
@@ -191,6 +193,7 @@ var EditorSettings = FormView.extend({
fd.append( "walls", JSON.stringify( Walls.serialize() ) )
fd.append( "colors", JSON.stringify( Walls.colors ) )
fd.append( "media", JSON.stringify( Scenery.serialize() ) )
+ fd.append( "sculpture", JSON.stringify( Sculpture.serialize() ) )
fd.append( "startPosition", JSON.stringify( this.startPosition || false ) )
fd.append( "lastPosition", JSON.stringify( app.position(scene.camera) ) )
diff --git a/server/lib/schemas/Project.js b/server/lib/schemas/Project.js
index a923d85..e9501fc 100644
--- a/server/lib/schemas/Project.js
+++ b/server/lib/schemas/Project.js
@@ -30,6 +30,7 @@ var ProjectSchema = new mongoose.Schema({
rooms: [mongoose.Schema.Types.Mixed],
walls: [mongoose.Schema.Types.Mixed],
media: [mongoose.Schema.Types.Mixed],
+ sculpture: [mongoose.Schema.Types.Mixed],
colors: mongoose.Schema.Types.Mixed,
startPosition: mongoose.Schema.Types.Mixed,
lastPosition: mongoose.Schema.Types.Mixed,
diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs
index 6cc5315..ca6cc94 100644
--- a/views/partials/scripts.ejs
+++ b/views/partials/scripts.ejs
@@ -74,6 +74,7 @@
<script type="text/javascript" src="/assets/javascripts/rectangles/engine/scenery/types/video.js"></script>
<script type="text/javascript" src="/assets/javascripts/rectangles/engine/sculpture/_sculpture.js"></script>
+<script type="text/javascript" src="/assets/javascripts/rectangles/engine/sculpture/types/_object.js"></script>
<script type="text/javascript" src="/assets/javascripts/rectangles/engine/sculpture/types/image.js"></script>
<script type="text/javascript" src="/assets/javascripts/rectangles/engine/map/_map.js"></script>