gui color update sends property, colors and axis for grids

beta.r3js.org
-=yb4f310 2017-11-11 11:57:07 +01:00
parent 69ba8b16fd
commit 237816ad7e
4 changed files with 196 additions and 6 deletions

View File

@ -63,7 +63,7 @@ GameLib.Color.prototype.createInstance = function() {
/** /**
* Updates the instance color, calls updateInstance on the parent object * Updates the instance color, calls updateInstance on the parent object
*/ */
GameLib.Color.prototype.updateInstance = function() { GameLib.Color.prototype.updateInstance = function(property) {
this.instance.r = this.r; this.instance.r = this.r;
this.instance.g = this.g; this.instance.g = this.g;
@ -71,7 +71,7 @@ GameLib.Color.prototype.updateInstance = function() {
if (this.parentObject && if (this.parentObject &&
this.parentObject.updateInstance) { this.parentObject.updateInstance) {
this.parentObject.updateInstance(); this.parentObject.updateInstance(property);
} }
}; };

View File

@ -9,6 +9,10 @@
* @param images * @param images
* @param fog * @param fog
* @param renderCamera - this is a camera which takes precedence over the renderer camera at time of render * @param renderCamera - this is a camera which takes precedence over the renderer camera at time of render
* @param showGrid
* @param showAxis
* @param gridSize
* @param gridColor
* @param parentEntity * @param parentEntity
* @constructor * @constructor
*/ */
@ -22,6 +26,10 @@ GameLib.D3.API.Scene = function(
images, images,
fog, fog,
renderCamera, renderCamera,
showGrid,
showAxis,
gridSize,
gridColor,
parentEntity parentEntity
) { ) {
@ -70,6 +78,26 @@ GameLib.D3.API.Scene = function(
} }
this.renderCamera = renderCamera; this.renderCamera = renderCamera;
if (GameLib.Utils.UndefinedOrNull(showGrid)) {
showGrid = true;
}
this.showGrid = showGrid;
if (GameLib.Utils.UndefinedOrNull(showAxis)) {
showAxis = true;
}
this.showAxis = showAxis;
if (GameLib.Utils.UndefinedOrNull(gridSize)) {
gridSize = 10;
}
this.gridSize = gridSize;
if (GameLib.Utils.UndefinedOrNull(gridColor)) {
gridColor = new GameLib.API.Color(0.1, 0.1, 0.1);
}
this.gridColor = gridColor;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) { if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null; parentEntity = null;
} }
@ -163,6 +191,10 @@ GameLib.D3.API.Scene.FromObject = function(objectScene) {
apiImages, apiImages,
objectScene.fog, objectScene.fog,
objectScene.renderCamera, objectScene.renderCamera,
objectScene.showGrid,
objectScene.showAxis,
objectScene.gridSize,
objectScene.gridColor,
objectScene.parentEntity objectScene.parentEntity
); );

View File

@ -31,6 +31,10 @@ GameLib.D3.Scene = function (
apiScene.images, apiScene.images,
apiScene.fog, apiScene.fog,
apiScene.renderCamera, apiScene.renderCamera,
apiScene.showGrid,
apiScene.showAxis,
apiScene.gridSize,
apiScene.gridColor,
apiScene.parentEntity apiScene.parentEntity
); );
@ -139,6 +143,14 @@ GameLib.D3.Scene = function (
) )
} }
if (this.gridColor instanceof GameLib.API.Color) {
this.gridColor = new GameLib.Color(
this.graphics,
this.gridColor,
this
)
}
/** /**
* Runtime scenes have helpers (just used to store which helper belongs to which scene) * Runtime scenes have helpers (just used to store which helper belongs to which scene)
* @type {Array} * @type {Array}
@ -147,6 +159,10 @@ GameLib.D3.Scene = function (
this.clones = []; this.clones = [];
this.grid = [];
this.axis = [];
this.storeClones = false; this.storeClones = false;
GameLib.Component.call( GameLib.Component.call(
@ -218,6 +234,14 @@ GameLib.D3.Scene.prototype.createInstance = function() {
}.bind(this) }.bind(this)
); );
if (this.showGrid) {
this.drawGrid();
}
if (this.showAxis) {
this.drawAxis();
}
GameLib.Component.prototype.createInstance.call(this); GameLib.Component.prototype.createInstance.call(this);
}; };
@ -287,7 +311,28 @@ GameLib.D3.Scene.prototype.updateInstance = function(property) {
} }
}.bind(this) }.bind(this)
) );
if (
property === 'showGrid' ||
property === 'gridSize' ||
property === 'gridColor'
) {
if (this.showGrid) {
this.drawGrid();
} else {
this.removeGrid();
}
}
if (property === 'showAxis') {
if (this.showAxis) {
this.drawAxis();
} else {
this.removeAxis();
}
}
}; };
/** /**
@ -355,6 +400,10 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
apiImages, apiImages,
GameLib.Utils.IdOrNull(this.fog), GameLib.Utils.IdOrNull(this.fog),
GameLib.Utils.IdOrNull(this.renderCamera), GameLib.Utils.IdOrNull(this.renderCamera),
this.showGrid,
this.showAxis,
this.gridSize,
this.gridColor,
GameLib.Utils.IdOrNull(this.parentEntity) GameLib.Utils.IdOrNull(this.parentEntity)
); );
}; };
@ -483,4 +532,113 @@ GameLib.D3.Scene.prototype.removeObject = function(object) {
} }
// this.buildIdToObject(); // this.buildIdToObject();
}; };
GameLib.D3.Scene.prototype.drawGrid = function() {
this.removeGrid();
var lineMaterial = new THREE.LineBasicMaterial({
color: this.gridColor.toHex(),
linewidth: 1
});
for (var y = -this.gridSize; y <= this.gridSize; y += 1) {
var Xgeometry = new THREE.Geometry();
Xgeometry.vertices.push(
new THREE.Vector3( y, 0, this.gridSize * -1 ),
new THREE.Vector3( y, 0, this.gridSize )
);
var lineX = new THREE.Line(Xgeometry, lineMaterial);
this.instance.add(lineX);
this.grid.push(lineX);
var Ygeometry = new THREE.Geometry();
Ygeometry.vertices.push(
new THREE.Vector3( this.gridSize * -1 , 0, y ),
new THREE.Vector3( this.gridSize, 0, y )
);
var lineY = new THREE.Line(Ygeometry, lineMaterial);
this.instance.add(lineY);
this.grid.push(lineY);
}
};
GameLib.D3.Scene.prototype.removeGrid = function() {
this.grid.map(
function(object) {
this.instance.remove(object);
}.bind(this)
);
};
GameLib.D3.Scene.prototype.drawAxis = function() {
this.removeAxis();
var Xmaterial = new THREE.LineBasicMaterial({
color: 0xff0000,
linewidth: 2
});
var Xgeometry = new THREE.Geometry();
Xgeometry.vertices.push(
new THREE.Vector3( 0, 0, 0 ),
new THREE.Vector3( 100, 0, 0 )
);
var lineX = new THREE.Line(Xgeometry, Xmaterial);
this.instance.add(lineX);
this.axis.push(lineX);
var Ymaterial = new THREE.LineBasicMaterial({
color: 0x00ff00,
linewidth: 2
});
var Ygeometry = new THREE.Geometry();
Ygeometry.vertices.push(
new THREE.Vector3( 0, 0, 0 ),
new THREE.Vector3( 0, 100, 0 )
);
var lineY = new THREE.Line(Ygeometry, Ymaterial);
this.instance.add(lineY);
this.axis.push(lineY);
var Zmaterial = new THREE.LineBasicMaterial({
color: 0x0000ff,
linewidth: 2
});
var Zgeometry = new THREE.Geometry();
Zgeometry.vertices.push(
new THREE.Vector3( 0, 0, 0 ),
new THREE.Vector3( 0, 0, 100 )
);
var lineZ = new THREE.Line(Zgeometry, Zmaterial);
this.instance.add(lineZ);
this.axis.push(lineZ);
};
GameLib.D3.Scene.prototype.removeAxis = function() {
this.axis.map(
function(object) {
this.instance.remove(object);
}.bind(this)
);
};

View File

@ -583,7 +583,7 @@ GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTempl
componentTemplate.affected.map( componentTemplate.affected.map(
function(component) { function(component) {
component[property].fromHex(value); component[property].fromHex(value);
component[property].updateInstance(); component[property].updateInstance(property);
} }
) )
} }
@ -597,7 +597,7 @@ GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTempl
componentTemplate.affected.map( componentTemplate.affected.map(
function(component) { function(component) {
component[property].fromHex(value); component[property].fromHex(value);
component[property].updateInstance(); component[property].updateInstance(property);
} }
) )
} }