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 name
* @param components GameLib.Component[]
* @param renderer
* @param parentEntity GameLib.Entity
* @param parentEntityManager
* @constructor
*/
GameLib.API.Entity = function(
id,
name,
components,
parentEntity,
parentEntityManager
renderer,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
@ -29,18 +29,16 @@ GameLib.API.Entity = function(
}
this.components = components;
if (GameLib.Utils.UndefinedOrNull(renderer)) {
renderer = null;
}
this.renderer = renderer;
GameLib.API.Component.call(
this,
GameLib.Component.ENTITY,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) {
parentEntityManager = null;
}
this.parentEntityManager = parentEntityManager;
this.activeComponent = null;
};
GameLib.API.Entity.prototype = Object.create(GameLib.Component.prototype);
@ -56,7 +54,7 @@ GameLib.API.Entity.FromObject = function(objectEntity) {
objectEntity.id,
objectEntity.name,
objectEntity.components,
objectEntity.parentEntity,
objectEntity.parentEntityManager
objectEntity.renderer,
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
};
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) {
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
* @param graphics GameLib.GraphicsRuntime
* @param apiMesh GameLib.D3.API.Mesh
* @param width
* @param height
* @param widthSegments
* @param heightSegments
* @param heightMapScale
* @param isHeightMap
* @param isClippingPlane
* @param distanceFromOrigin
* @param apiMeshPlane
* @constructor
*/
GameLib.D3.Mesh.Plane = function (
graphics,
apiMesh,
width,
height,
widthSegments,
heightSegments,
heightMapScale,
isHeightMap,
isClippingPlane,
distanceFromOrigin
apiMeshPlane
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
apiMesh = {
meshType: GameLib.D3.API.Mesh.MESH_TYPE_PLANE
if (GameLib.Utils.UndefinedOrNull(apiMeshPlane)) {
apiMeshPlane = {
meshType : GameLib.D3.API.Mesh.MESH_TYPE_PLANE
};
}
if (apiMesh instanceof GameLib.D3.Mesh.Plane) {
return apiMesh;
}
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 = 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.API.Mesh.Plane.call(
this,
apiMeshPlane,
apiMeshPlane.width,
apiMeshPlane.height,
apiMeshPlane.widthSegments,
apiMeshPlane.heightSegments,
apiMeshPlane.heightMapScale,
apiMeshPlane.isHeightMap,
apiMeshPlane.isDotMap,
apiMeshPlane.dotObject
);
GameLib.D3.Mesh.call(
this,
this.graphics,
apiMesh
graphics,
apiMeshPlane
);
};
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.createInstance = function() {
var geometry = null;
@ -119,23 +73,8 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
*/
GameLib.D3.Mesh.prototype.createInstance.call(this);
/**
* Apply some plane specific data to the instance
*/
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
);
if (this.isDotMap && this.dotObject) {
console.log('todo: construct dotmap here')
}
};
@ -146,26 +85,16 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
var geometry = null;
if (
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
if (
property === 'width' ||
property === 'height' ||
property === 'widthSegments' ||
property === 'heightSegments' ||
property === 'isHeightMap' ||
property === 'heightMapScale'
) {
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.height,
this.widthSegments,
@ -175,19 +104,19 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
this.updateVerticesFromGeometryInstance(geometry);
if (this.isHeightMap) {
this.generateHeightMapFromBumpMap();
}
this.generateHeightMapFromBumpMap();
}
geometry = this.createInstanceGeometry();
geometry = this.createInstanceGeometry();
this.instance.geometry = geometry;
}
if (this.isClippingPlane) {
this.instance.clipping = new THREE.Plane(
geometry.faces[0].normal,
this.distanceFromOrigin
)
}
if (
property === 'isDotMap' ||
property === 'dotObject'
) {
console.log('todo: implement dotmap');
}
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() {
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;
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;
return apiMeshPlane;
};
/**
* TODO fix all this weird loading shit
* Converts a standard object mesh to a GameLib.D3.Mesh
* @param graphics GameLib.GraphicsRuntime
* @param objectMesh {Object}
@ -222,19 +151,11 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
*/
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(
graphics,
apiMesh,
objectMesh.width,
objectMesh.height,
objectMesh.widthSegments,
objectMesh.heightSegments,
objectMesh.heightMapScale,
objectMesh.isHeightMap,
objectMesh.isClippingPlane,
objectMesh.distanceFromOrigin
apiMeshPlane
);
};

View File

@ -36,6 +36,11 @@ GameLib.EntityManager = function(apiEntityManager) {
this.registerComponent.bind(this)
);
GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
);
GameLib.Event.Subscribe(
GameLib.Event.REMOVE_COMPONENT,
this.removeComponent.bind(this)
@ -59,6 +64,12 @@ GameLib.EntityManager.prototype.createInstance = function() {
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) {
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
* @param id
@ -253,7 +232,6 @@ GameLib.EntityManager.prototype.findSceneByObject = function(object) {
* @param entity GameLib.Entity
*/
GameLib.EntityManager.prototype.addEntity = function(entity) {
entity.parentEntityManager = this;
this.entities.push(entity);
};
@ -289,8 +267,6 @@ GameLib.EntityManager.prototype.removeEntity = function(entity) {
}
this.entities.splice(index, 1);
entity.parentEntityManager = null;
return true;
};

View File

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

View File

@ -244,11 +244,6 @@ GameLib.System.GUI.prototype.start = function() {
this.meshDeslected
);
this.newEntitySubscription = this.subscribe(
GameLib.Event.NEW_ENTITY,
this.newEntity
);
this.componentRemovedSubscription = this.subscribe(
GameLib.Event.REMOVE_COMPONENT,
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 componentTemplate
* @param property
@ -1869,10 +1864,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
}
if (
templateProperty === 'parentEntity' ||
templateProperty === 'parentPhysicsWorld' ||
templateProperty === 'parentMesh' ||
templateProperty === 'parentScene'
templateProperty.indexOf('parent') === 0
) {
this.buildParentSelectionControl(folder, componentTemplate, templateProperty);
continue;
@ -1919,42 +1911,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
}
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)
);
@ -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) {
this.buildGUI(null);
};