Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
Removes replay feature
Browse files Browse the repository at this point in the history
The replay feature is a pain to maintain.

- it's very easy to screw up a replay file because you have to track
  almost every changes in the app (mesh edit, UI, camera movement, file
  loading...)
- a single mistake and all the replay files are completely screwed (with no possibily
  of repair)
- each changes in the code invalidates all the previous replay file, so,
  in order to read an old replay file we need an old version of the app
- it's complicated if you want to handle stuffs such as camera small animation
  • Loading branch information
stephomi committed May 31, 2015
1 parent 0b595d8 commit 07862ae
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 1,923 deletions.
40 changes: 1 addition & 39 deletions src/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ define([
'editor/Sculpt',
'editor/Subdivision',
'files/Import',
'files/ReplayWriter',
'files/ReplayReader',
'gui/Gui',
'math3d/Camera',
'math3d/Picking',
Expand All @@ -22,7 +20,7 @@ define([
'render/Rtt',
'render/shaders/ShaderMatcap',
'render/WebGLCaps'
], function (glm, getUrlOptions, Utils, Sculpt, Subdivision, Import, ReplayWriter, ReplayReader, Gui, Camera, Picking, Background, Selection, Grid, Mesh, Multimesh, Primitive, States, Contour, Render, Rtt, ShaderMatcap, WebGLCaps) {
], function (glm, getUrlOptions, Utils, Sculpt, Subdivision, Import, Gui, Camera, Picking, Background, Selection, Grid, Mesh, Multimesh, Primitive, States, Contour, Render, Rtt, ShaderMatcap, WebGLCaps) {

'use strict';

Expand Down Expand Up @@ -54,11 +52,6 @@ define([
this.focusGui_ = false; // if the gui is being focused
this.gui_ = new Gui(this);

// misc stuffs
this.replayerWriter_ = new ReplayWriter(this); // the user event stack replayer
this.replayerReader_ = new ReplayReader(this); // reader replayer
this.isReplayed_ = false; // if we want to save the replay mode

this.preventRender_ = false; // prevent multiple render per frame
this.drawFullScene_ = false; // render everything on the rtt
this.autoMatrix_ = opts.scalecenter; // scale and center the imported meshes
Expand All @@ -80,13 +73,6 @@ define([
this.gui_.initGui();
this.onCanvasResize();
this.addSphere();
this.getReplayReader().checkURL();
},
getReplayWriter: function () {
return this.replayerWriter_;
},
getReplayReader: function () {
return this.replayerReader_;
},
getBackground: function () {
return this.background_;
Expand Down Expand Up @@ -121,12 +107,6 @@ define([
getStates: function () {
return this.states_;
},
isReplayed: function () {
return this.isReplayed_;
},
setReplayed: function (isReplayed) {
this.isReplayed_ = isReplayed;
},
setMesh: function (mesh) {
return this.setOrUnsetMesh(mesh);
},
Expand Down Expand Up @@ -291,9 +271,6 @@ define([
var newWidth = this.gl_.viewportWidth = this.camera_.width_ = this.canvas_.width;
var newHeight = this.gl_.viewportHeight = this.camera_.height_ = this.canvas_.height;

if (!this.isReplayed())
this.getReplayWriter().pushAction('CAMERA_SIZE', newWidth, newHeight);

this.background_.onResize(newWidth, newHeight);
this.rtt_.onResize(newWidth, newHeight);
this.contour_.onResize(newWidth, newHeight);
Expand Down Expand Up @@ -352,9 +329,6 @@ define([
},
/** Load the sphere */
addSphere: function () {
if (!this.isReplayed())
this.getReplayWriter().pushAction('ADD_SPHERE');

// make a cube and subdivide it
var mesh = new Multimesh(Primitive.createCube(this.gl_));
while (mesh.getNbFaces() < 50000)
Expand All @@ -366,9 +340,6 @@ define([
return this.addNewMesh(mesh);
},
addCube: function () {
if (!this.isReplayed())
this.getReplayWriter().pushAction('ADD_CUBE');

var mesh = new Multimesh(Primitive.createCube(this.gl_));
glm.mat4.scale(mesh.getMatrix(), mesh.getMatrix(), [0.7, 0.7, 0.7]);
Subdivision.LINEAR = true;
Expand Down Expand Up @@ -405,9 +376,6 @@ define([
meshes.push(mesh);
}

if (!this.isReplayed())
this.getReplayWriter().pushLoadMeshes(newMeshes, fileData, fileType, autoMatrix);

if (autoMatrix)
this.scaleAndCenterMeshes(newMeshes);
this.states_.pushStateAdd(newMeshes);
Expand All @@ -425,15 +393,11 @@ define([
this.autoMatrix_ = opts.scalecenter;
this.setMesh(null);
this.mouseButton_ = 0;
this.getReplayWriter().reset();
},
deleteCurrentSelection: function () {
if (!this.mesh_)
return;

if (!this.isReplayed())
this.getReplayWriter().pushAction('DELETE_SELECTION');

this.removeMeshes(this.selectMeshes_);
this.states_.pushStateRemove(this.selectMeshes_.slice());
this.selectMeshes_.length = 0;
Expand Down Expand Up @@ -485,8 +449,6 @@ define([
if (tool && tool.ctrlAlpha_) tool.ctrlAlpha_.setValue(id);
},
loadAlphaTexture: function (u8, w, h, name) {
if (!this.isReplayed() && name)
this.getReplayWriter().pushLoadAlpha(u8, w, h);
var ans = Picking.ALPHAS_NAMES;
ans.push(name || 'alpha_' + ans.length);
return Picking.addAlpha(u8, w, h);
Expand Down
55 changes: 16 additions & 39 deletions src/Sculptgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,15 @@ define([
this.onDeviceUp();
},
onDoubleTap: function (e) {
if (!this.isReplayed()) {
if (this.focusGui_)
return;
var evProxy = this.eventProxy_;
evProxy.pageX = e.center.x;
evProxy.pageY = e.center.y;
this.setMousePosition(evProxy);
}
if (this.focusGui_)
return;
var evProxy = this.eventProxy_;
evProxy.pageX = e.center.x;
evProxy.pageY = e.center.y;
this.setMousePosition(evProxy);

var mouseX = this.mouseX_;
var mouseY = this.mouseY_;
if (!this.isReplayed())
this.getReplayWriter().pushAction('DOUBLE_TAP', mouseX, mouseY);

var picking = this.picking_;
var res = picking.intersectionMouseMeshes(this.meshes_, mouseX, mouseY);
Expand Down Expand Up @@ -216,7 +213,6 @@ define([
if (lower.endsWith('.sgl')) return 'sgl';
if (lower.endsWith('.stl')) return 'stl';
if (lower.endsWith('.ply')) return 'ply';
if (lower.endsWith('.rep')) return 'rep';
return;
},
/** Load file */
Expand All @@ -228,8 +224,6 @@ define([
var file = files[i];
var fileType = this.getFileType(file.name);
this.readFile(file, fileType);
if (fileType === 'rep')
return;
}
},
readFile: function (file, ftype) {
Expand All @@ -240,10 +234,7 @@ define([
var reader = new FileReader();
var self = this;
reader.onload = function (evt) {
if (fileType === 'rep')
self.getReplayReader().import(evt.target.result, null, file.name.substr(0, file.name.length - 4));
else
self.loadScene(evt.target.result, fileType, self.autoMatrix_);
self.loadScene(evt.target.result, fileType, self.autoMatrix_);
document.getElementById('fileopen').value = '';
};

Expand All @@ -270,9 +261,6 @@ define([
this.onDeviceUp();
},
onDeviceUp: function () {
if (!this.isReplayed())
this.getReplayWriter().pushDeviceUp();

this.canvas_.style.cursor = 'default';
this.mouseButton_ = 0;
Multimesh.RENDER_HINT = Multimesh.NONE;
Expand All @@ -295,9 +283,6 @@ define([
this.onDeviceWheel(dir > 0 ? 1 : -1);
},
onDeviceWheel: function (dir) {
if (!this.isReplayed())
this.getReplayWriter().pushAction('DEVICE_WHEEL', dir);

this.camera_.start(this.mouseX_, this.mouseY_, this);
this.camera_.zoom(dir * 0.02);
Multimesh.RENDER_HINT = Multimesh.CAMERA;
Expand Down Expand Up @@ -326,18 +311,14 @@ define([
this.onDeviceMove(event);
},
onDeviceDown: function (event) {
if (!this.isReplayed()) {
if (this.focusGui_)
return;
this.setMousePosition(event);
}
if (this.focusGui_)
return;
this.setMousePosition(event);

var mouseX = this.mouseX_;
var mouseY = this.mouseY_;
var button = this.mouseButton_ = event.which;

if (!this.isReplayed())
this.getReplayWriter().pushDeviceDown(button, mouseX, mouseY, event);

if (button === 1)
this.sculpt_.start(this, event.shiftKey);
var picking = this.picking_;
Expand Down Expand Up @@ -368,18 +349,14 @@ define([
this.lastMouseY_ = mouseY;
},
onDeviceMove: function (event) {
if (!this.isReplayed()) {
if (this.focusGui_)
return;
this.setMousePosition(event);
}
if (this.focusGui_)
return;
this.setMousePosition(event);

var mouseX = this.mouseX_;
var mouseY = this.mouseY_;
var button = this.mouseButton_;

if (!this.isReplayed())
this.getReplayWriter().pushDeviceMove(mouseX, mouseY, event);

if (button !== 1 || this.sculpt_.allowPicking()) {
Multimesh.RENDER_HINT = Multimesh.PICKING;
if (this.mesh_ && button === 1)
Expand Down
8 changes: 1 addition & 7 deletions src/editor/Sculpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@ define([
tool.start(main, ctrl);
if (!main.getPicking().getMesh() || !this.isUsingContinuous())
return;
// we do not execute this code if we are replaying
if (main.isReplayed())
return;
this.sculptTimer_ = window.setInterval(function () {
main.getReplayWriter().pushAction('SCULPT_UPDATE_CONTINOUS');
tool.updateContinuous(main);
}, 16.6);
this.sculptTimer_ = window.setInterval(tool.updateContinuous.bind(tool, main), 16.6);
},
/** End sculpting */
end: function () {
Expand Down
5 changes: 2 additions & 3 deletions src/files/ExportSketchfab.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ define([
domStatus.innerHTML = 'Uploading : ' + Math.round(event.loaded * 100.0 / event.total) + '%';
};
var hideStatus = function () {
if (!statusWidget.replay)
statusWidget.setVisibility(false);
statusWidget.setVisibility(false);
statusWidget.sketchfab = false;
};
xhr.onerror = hideStatus;
Expand Down Expand Up @@ -69,7 +68,7 @@ define([
var fd = new FormData();
fd.append('token', key);
fd.append('modelFile', blob, 'sculptglModel.zip');
fd.append('name', 'My model - ' + main.getReplayWriter().uid_);
fd.append('name', 'My model');
fd.append('tags', 'sculptgl');
xhr.send(fd);
};
Expand Down
Loading

0 comments on commit 07862ae

Please sign in to comment.