Merge branch 'render_update_v2'

beta.r3js.org
-=yb4f310 2018-01-06 16:48:53 +01:00
commit d4ed87868f
8 changed files with 210 additions and 243 deletions

View File

@ -3,16 +3,16 @@
* @param id * @param id
* @param name * @param name
* @param components GameLib.Component[] * @param components GameLib.Component[]
* @param renderer
* @param parentEntity GameLib.Entity * @param parentEntity GameLib.Entity
* @param parentEntityManager
* @constructor * @constructor
*/ */
GameLib.API.Entity = function( GameLib.API.Entity = function(
id, id,
name, name,
components, components,
parentEntity, renderer,
parentEntityManager parentEntity
) { ) {
if (GameLib.Utils.UndefinedOrNull(id)) { if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId(); id = GameLib.Utils.RandomId();
@ -29,18 +29,16 @@ GameLib.API.Entity = function(
} }
this.components = components; this.components = components;
if (GameLib.Utils.UndefinedOrNull(renderer)) {
renderer = null;
}
this.renderer = renderer;
GameLib.API.Component.call( GameLib.API.Component.call(
this, this,
GameLib.Component.ENTITY, GameLib.Component.ENTITY,
parentEntity parentEntity
); );
if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) {
parentEntityManager = null;
}
this.parentEntityManager = parentEntityManager;
this.activeComponent = null;
}; };
GameLib.API.Entity.prototype = Object.create(GameLib.Component.prototype); GameLib.API.Entity.prototype = Object.create(GameLib.Component.prototype);
@ -56,7 +54,7 @@ GameLib.API.Entity.FromObject = function(objectEntity) {
objectEntity.id, objectEntity.id,
objectEntity.name, objectEntity.name,
objectEntity.components, objectEntity.components,
objectEntity.parentEntity, objectEntity.renderer,
objectEntity.parentEntityManager objectEntity.parentEntity
) )
}; };

View File

@ -0,0 +1,121 @@
/**
* Raw Mesh.Plane API object
* @constructor
* @param apiMesh
* @param width
* @param height
* @param widthSegments
* @param heightSegments
* @param heightMapScale
* @param isHeightMap
* @param isDotMap
* @param dotObject
*/
GameLib.D3.API.Mesh.Plane = function(
apiMesh,
width,
height,
widthSegments,
heightSegments,
heightMapScale,
isHeightMap,
isDotMap,
dotObject
) {
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
apiMesh = {
meshType : GameLib.D3.API.Mesh.MESH_TYPE_PLANE
};
}
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 1;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 1;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(widthSegments)) {
widthSegments = 5;
}
this.widthSegments = widthSegments;
if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
heightSegments = 5;
}
this.heightSegments = heightSegments;
if (GameLib.Utils.UndefinedOrNull(heightMapScale)) {
heightMapScale = 1;
}
this.heightMapScale = heightMapScale;
if (GameLib.Utils.UndefinedOrNull(isHeightMap)) {
isHeightMap = false;
}
this.isHeightMap = isHeightMap;
if (GameLib.Utils.UndefinedOrNull(isDotMap)) {
isDotMap = false;
}
this.isDotMap = isDotMap;
if (GameLib.Utils.UndefinedOrNull(dotObject)) {
dotObject = null;
}
this.dotObject = dotObject;
GameLib.D3.API.Mesh.call(
this,
apiMesh.id,
apiMesh.meshType,
apiMesh.name,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,
apiMesh.parentMesh,
apiMesh.parentScene,
apiMesh.skeleton,
apiMesh.skinIndices,
apiMesh.skinWeights,
apiMesh.position,
apiMesh.quaternion,
apiMesh.rotation,
apiMesh.scale,
apiMesh.up,
apiMesh.modelMatrix,
apiMesh.renderOrder,
apiMesh.isBufferMesh,
apiMesh.useQuaternion,
apiMesh.visible,
apiMesh.parentEntity
);
};
GameLib.D3.API.Mesh.Plane.prototype = Object.create(GameLib.D3.API.Mesh.prototype);
GameLib.D3.API.Mesh.Plane.prototype.constructor = GameLib.D3.API.Mesh.Plane;
/**
* Returns an API Mesh from an Object mesh
* @param objectMesh
* @constructor
*/
GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){
return new GameLib.D3.API.Mesh.Plane(
GameLib.D3.API.Mesh.FromObject(objectMesh),
objectMesh.width,
objectMesh.height,
objectMesh.widthSegments,
objectMesh.heightSegments,
objectMesh.heightMapScale,
objectMesh.isHeightMap,
objectMesh.isDotMap,
GameLib.Utils.IdOrNull(objectMesh.dotObject)
);
};

View File

@ -138,6 +138,10 @@ GameLib.D3.Mesh = function (
'skeleton' : GameLib.D3.Skeleton 'skeleton' : GameLib.D3.Skeleton
}; };
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) {
linkedObjects.dotObject = GameLib.D3.Mesh;
}
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) { if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) {
linkedObjects.font = GameLib.D3.Font; linkedObjects.font = GameLib.D3.Font;
} }

View File

@ -1,93 +1,47 @@
/** /**
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created * Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
* @param graphics GameLib.GraphicsRuntime * @param graphics GameLib.GraphicsRuntime
* @param apiMesh GameLib.D3.API.Mesh * @param apiMeshPlane
* @param width
* @param height
* @param widthSegments
* @param heightSegments
* @param heightMapScale
* @param isHeightMap
* @param isClippingPlane
* @param distanceFromOrigin
* @constructor * @constructor
*/ */
GameLib.D3.Mesh.Plane = function ( GameLib.D3.Mesh.Plane = function (
graphics, graphics,
apiMesh, apiMeshPlane
width,
height,
widthSegments,
heightSegments,
heightMapScale,
isHeightMap,
isClippingPlane,
distanceFromOrigin
) { ) {
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiMesh)) { if (GameLib.Utils.UndefinedOrNull(apiMeshPlane)) {
apiMesh = { apiMeshPlane = {
meshType: GameLib.D3.API.Mesh.MESH_TYPE_PLANE meshType : GameLib.D3.API.Mesh.MESH_TYPE_PLANE
}; };
} }
if (apiMesh instanceof GameLib.D3.Mesh.Plane) { GameLib.D3.API.Mesh.Plane.call(
return apiMesh; this,
} apiMeshPlane,
apiMeshPlane.width,
if (GameLib.Utils.UndefinedOrNull(width)) { apiMeshPlane.height,
width = 1; apiMeshPlane.widthSegments,
} apiMeshPlane.heightSegments,
this.width = width; apiMeshPlane.heightMapScale,
apiMeshPlane.isHeightMap,
if (GameLib.Utils.UndefinedOrNull(height)) { apiMeshPlane.isDotMap,
height = 1; apiMeshPlane.dotObject
} );
this.height = height;
if (GameLib.Utils.UndefinedOrNull(widthSegments)) {
widthSegments = 1;
}
this.widthSegments = widthSegments;
if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
heightSegments = 1
}
this.heightSegments = heightSegments;
if (GameLib.Utils.UndefinedOrNull(heightMapScale)) {
heightMapScale = 1;
}
this.heightMapScale = heightMapScale;
if (GameLib.Utils.UndefinedOrNull(isHeightMap)) {
isHeightMap = false;
}
this.isHeightMap = isHeightMap;
if (GameLib.Utils.UndefinedOrNull(isClippingPlane)) {
isClippingPlane = false;
}
this.isClippingPlane = isClippingPlane;
if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) {
distanceFromOrigin = 0;
}
this.distanceFromOrigin = distanceFromOrigin;
GameLib.D3.Mesh.call( GameLib.D3.Mesh.call(
this, this,
this.graphics, graphics,
apiMesh apiMeshPlane
); );
}; };
GameLib.D3.Mesh.Plane.prototype = Object.create(GameLib.D3.Mesh.prototype); GameLib.D3.Mesh.Plane.prototype = Object.create(GameLib.D3.Mesh.prototype);
GameLib.D3.Mesh.Plane.prototype.constructor = GameLib.D3.Mesh.Plane; GameLib.D3.Mesh.Plane.prototype.constructor = GameLib.D3.Mesh.Plane;
GameLib.D3.Mesh.Plane.prototype.createInstance = function() { GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
var geometry = null; var geometry = null;
@ -119,23 +73,8 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
*/ */
GameLib.D3.Mesh.prototype.createInstance.call(this); GameLib.D3.Mesh.prototype.createInstance.call(this);
/** if (this.isDotMap && this.dotObject) {
* Apply some plane specific data to the instance console.log('todo: construct dotmap here')
*/
this.instance.userData.width = this.width;
this.instance.userData.height = this.height;
this.instance.userData.widthSegments = this.widthSegments;
this.instance.userData.heightSegments = this.heightSegments;
this.instance.userData.heightMapScale = this.heightMapScale;
this.instance.userData.isHeightMap = this.isHeightMap;
this.instance.userData.isClippingPlane = this.isClippingPlane;
this.instance.userData.distanceFromOrigin = this.distanceFromOrigin;
if (this.isClippingPlane) {
this.instance.clipping = new THREE.Plane(
geometry.faces[0].normal,
this.distanceFromOrigin
);
} }
}; };
@ -146,26 +85,16 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
var geometry = null; var geometry = null;
if ( if (
this.instance.userData.width !== this.width || property === 'width' ||
this.instance.userData.height !== this.height || property === 'height' ||
this.instance.userData.widthSegments !== this.widthSegments || property === 'widthSegments' ||
this.instance.userData.heightSegments !== this.heightSegments || property === 'heightSegments' ||
this.instance.userData.isHeightMap !== this.isHeightMap || property === 'isHeightMap' ||
this.instance.userData.heightMapScale !== this.heightMapScale || property === 'heightMapScale'
this.instance.userData.isClippingPlane !== this.isClippingPlane ||
this.instance.userData.distanceFromOrigin !== this.distanceFromOrigin
) { ) {
this.instance.userData.width = this.width;
this.instance.userData.height = this.height;
this.instance.userData.widthSegments = this.widthSegments;
this.instance.userData.heightSegments = this.heightSegments;
this.instance.userData.isHeightMap = this.isHeightMap;
this.instance.userData.heightMapScale = this.heightMapScale;
this.instance.userData.isClippingPlane = this.isClippingPlane;
this.instance.userData.distanceFromOrigin = this.distanceFromOrigin;
geometry = new THREE.PlaneGeometry( geometry = new THREE.PlaneGeometry(
this.width, this.width,
this.height, this.height,
this.widthSegments, this.widthSegments,
@ -175,19 +104,19 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
this.updateVerticesFromGeometryInstance(geometry); this.updateVerticesFromGeometryInstance(geometry);
if (this.isHeightMap) { if (this.isHeightMap) {
this.generateHeightMapFromBumpMap(); this.generateHeightMapFromBumpMap();
} }
geometry = this.createInstanceGeometry(); geometry = this.createInstanceGeometry();
this.instance.geometry = geometry; this.instance.geometry = geometry;
}
if (this.isClippingPlane) { if (
this.instance.clipping = new THREE.Plane( property === 'isDotMap' ||
geometry.faces[0].normal, property === 'dotObject'
this.distanceFromOrigin ) {
) console.log('todo: implement dotmap');
}
} }
GameLib.D3.Mesh.prototype.updateInstance.call(this, property); GameLib.D3.Mesh.prototype.updateInstance.call(this, property);
@ -199,22 +128,22 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
*/ */
GameLib.D3.Mesh.Plane.prototype.toApiObject = function() { GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this); var apiMeshPlane = new GameLib.D3.API.Mesh.Plane(
GameLib.D3.API.Mesh.prototype.toApiObject.call(this),
this.width,
this.height,
this.widthSegments,
this.heightSegments,
this.heightMapScale,
this.isHeightMap,
this.isDotMap,
this.dotObject
);
apiMesh.width = this.width; return apiMeshPlane;
apiMesh.height = this.height;
apiMesh.widthSegments = this.widthSegments;
apiMesh.heightSegments = this.heightSegments;
apiMesh.heightMapScale = this.heightMapScale;
apiMesh.isHeightMap = this.isHeightMap;
apiMesh.isClippingPlane = this.isClippingPlane;
apiMesh.distanceFromOrigin = this.distanceFromOrigin;
return apiMesh;
}; };
/** /**
* TODO fix all this weird loading shit
* Converts a standard object mesh to a GameLib.D3.Mesh * Converts a standard object mesh to a GameLib.D3.Mesh
* @param graphics GameLib.GraphicsRuntime * @param graphics GameLib.GraphicsRuntime
* @param objectMesh {Object} * @param objectMesh {Object}
@ -222,19 +151,11 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
*/ */
GameLib.D3.Mesh.Plane.FromObject = function(graphics, objectMesh) { GameLib.D3.Mesh.Plane.FromObject = function(graphics, objectMesh) {
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); var apiMeshPlane = GameLib.D3.API.Mesh.Plane.FromObject(objectMesh);
return new GameLib.D3.Mesh.Plane( return new GameLib.D3.Mesh.Plane(
graphics, graphics,
apiMesh, apiMeshPlane
objectMesh.width,
objectMesh.height,
objectMesh.widthSegments,
objectMesh.heightSegments,
objectMesh.heightMapScale,
objectMesh.isHeightMap,
objectMesh.isClippingPlane,
objectMesh.distanceFromOrigin
); );
}; };

View File

@ -36,6 +36,11 @@ GameLib.EntityManager = function(apiEntityManager) {
this.registerComponent.bind(this) this.registerComponent.bind(this)
); );
GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
);
GameLib.Event.Subscribe( GameLib.Event.Subscribe(
GameLib.Event.REMOVE_COMPONENT, GameLib.Event.REMOVE_COMPONENT,
this.removeComponent.bind(this) this.removeComponent.bind(this)
@ -59,6 +64,12 @@ GameLib.EntityManager.prototype.createInstance = function() {
GameLib.Component.prototype.createInstance.call(this); GameLib.Component.prototype.createInstance.call(this);
}; };
GameLib.EntityManager.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.Entity) {
this.addEntity(data.component);
}
};
GameLib.EntityManager.prototype.registerComponent = function(data) { GameLib.EntityManager.prototype.registerComponent = function(data) {
var updated = false; var updated = false;
@ -139,38 +150,6 @@ GameLib.EntityManager.prototype.removeComponent = function(data) {
}; };
/**
* Creates an GameLib.Entity and adds it to entities array
* @returns {*}
*/
GameLib.EntityManager.prototype.createEntity = function(name) {
var apiEntity = new GameLib.API.Entity(
null,
name,
null,
null,
this
);
var entity = new GameLib.Entity(
apiEntity
);
this.entities.push(entity);
this.defaultEntity = entity;
GameLib.Event.Emit(
GameLib.Event.NEW_ENTITY,
{
entity : entity
}
);
return entity;
};
/** /**
* Returns an entity by ID or null * Returns an entity by ID or null
* @param id * @param id
@ -253,7 +232,6 @@ GameLib.EntityManager.prototype.findSceneByObject = function(object) {
* @param entity GameLib.Entity * @param entity GameLib.Entity
*/ */
GameLib.EntityManager.prototype.addEntity = function(entity) { GameLib.EntityManager.prototype.addEntity = function(entity) {
entity.parentEntityManager = this;
this.entities.push(entity); this.entities.push(entity);
}; };
@ -289,8 +267,6 @@ GameLib.EntityManager.prototype.removeEntity = function(entity) {
} }
this.entities.splice(index, 1); this.entities.splice(index, 1);
entity.parentEntityManager = null;
return true; return true;
}; };

View File

@ -19,15 +19,15 @@ GameLib.Entity = function (
apiEntity.id, apiEntity.id,
apiEntity.name, apiEntity.name,
apiEntity.components, apiEntity.components,
apiEntity.parentEntity, apiEntity.renderer,
apiEntity.parentEntityManager apiEntity.parentEntity
); );
GameLib.Component.call( GameLib.Component.call(
this, this,
{ {
'components' : [GameLib.Component], 'components' : [GameLib.Component],
'activeComponent' : GameLib.Component 'renderer' : GameLib.D3.Renderer
} }
); );
}; };
@ -195,8 +195,8 @@ GameLib.Entity.prototype.toApiObject = function() {
this.id, this.id,
this.name, this.name,
apiComponents, apiComponents,
GameLib.Utils.IdOrNull(this.parentEntity), GameLib.Utils.IdOrNull(this.renderer),
GameLib.Utils.IdOrNull(this.parentEntityManager) GameLib.Utils.IdOrNull(this.parentEntity)
); );
}; };
@ -204,11 +204,10 @@ GameLib.Entity.prototype.toApiObject = function() {
/** /**
* Entity from Object * Entity from Object
* @param objectEntity Object * @param objectEntity Object
* @param parentEntityManager GameLib.D3.EntityManager
* @returns {GameLib.Entity} * @returns {GameLib.Entity}
* @constructor * @constructor
*/ */
GameLib.Entity.FromObject = function(objectEntity, parentEntityManager) { GameLib.Entity.FromObject = function(objectEntity) {
var apiEntity = GameLib.API.Entity.FromObject(objectEntity); var apiEntity = GameLib.API.Entity.FromObject(objectEntity);
@ -216,11 +215,7 @@ GameLib.Entity.FromObject = function(objectEntity, parentEntityManager) {
apiEntity apiEntity
); );
if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) { GameLib.EntityManager.Instance.addEntity(entity);
return entity;
}
parentEntityManager.addEntity(entity);
return entity; return entity;
}; };

View File

@ -244,11 +244,6 @@ GameLib.System.GUI.prototype.start = function() {
this.meshDeslected this.meshDeslected
); );
this.newEntitySubscription = this.subscribe(
GameLib.Event.NEW_ENTITY,
this.newEntity
);
this.componentRemovedSubscription = this.subscribe( this.componentRemovedSubscription = this.subscribe(
GameLib.Event.REMOVE_COMPONENT, GameLib.Event.REMOVE_COMPONENT,
this.removeComponent this.removeComponent
@ -452,7 +447,7 @@ GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemp
}; };
/** /**
* Builds an Entity Selection control * Builds a Paren Selection control
* @param folder * @param folder
* @param componentTemplate * @param componentTemplate
* @param property * @param property
@ -1869,10 +1864,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
} }
if ( if (
templateProperty === 'parentEntity' || templateProperty.indexOf('parent') === 0
templateProperty === 'parentPhysicsWorld' ||
templateProperty === 'parentMesh' ||
templateProperty === 'parentScene'
) { ) {
this.buildParentSelectionControl(folder, componentTemplate, templateProperty); this.buildParentSelectionControl(folder, componentTemplate, templateProperty);
continue; continue;
@ -1919,42 +1911,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
} }
this.buildControl(folder, componentTemplate, templateProperty); this.buildControl(folder, componentTemplate, templateProperty);
// if ( }
// component.linkedObjects &&
// component.linkedObjects[property]
// ) {
// if (property === 'parentEntity') {
// this.buildEntitySelectionControlFromArray(
// folder,
// component,
// property,
// entityManager
// )
// } else if (component.linkedObjects[property] instanceof Array) {
// this.buildArrayManager(
// folder,
// component,
// property,
// component.linkedObjects[property],
// entityManager
// )
// } else {
// this.buildSelectControl(folder, component, property, entityManager, component.linkedObjects[property]);
// }
//
// } else if (typeof (component[property]) === 'object') {
//
// if (this.isColor(component[property])) {
// this.buildControl(folder, component, property);
// } else {
// //console.log('ignored: ' + property);
// }
// } else {
// this.buildControl(folder, component, property, entityManager);
// }
}
} }
}.bind(this) }.bind(this)
); );
@ -1987,11 +1944,6 @@ GameLib.System.GUI.prototype.removeComponent = function(data) {
}; };
GameLib.System.GUI.prototype.newEntity = function(data) {
};
GameLib.System.GUI.prototype.castSourceChanged = function(data) { GameLib.System.GUI.prototype.castSourceChanged = function(data) {
this.buildGUI(null); this.buildGUI(null);
}; };