groups and winding order2

beta.r3js.org
-=yb4f310 2018-03-07 07:52:58 +01:00
parent 6196c77605
commit c1749c7482
5 changed files with 47 additions and 14 deletions

View File

@ -1982,6 +1982,13 @@ GameLib.Component.ConstructFromObject = function(rawComponentObject) {
var runtimeComponent = null;
// if (
// rawComponentObject.componentType === 34 &&
// rawComponentObject.name.indexOf('Mesh') !== -1
// ) {
// rawComponentObject.componentType = 7;
// }
var info = GameLib.Component.GetComponentInfo(rawComponentObject.componentType);
var runtime = GameLib.Component.GetRuntimeObject(info.runtime);

View File

@ -44,6 +44,19 @@ GameLib.D3.API.Mesh = function(
if (GameLib.Utils.UndefinedOrNull(geometry)) {
geometry = null;
/**
* Backwards compatibility
*/
// if (apiD3Object.faces && apiD3Object.vertices) {
// geometry = new GameLib.D3.API.Geometry.Normal(
// {
// faces : apiD3Object.faces,
// vertices : apiD3Object.vertices
// }
// );
// }
}
this.geometry = geometry;

View File

@ -38,15 +38,11 @@ GameLib.D3.Geometry.Buffer = function(
this.groups = this.groups.map(
function(group) {
if (group instanceof GameLib.API.Group) {
return new GameLib.Group(
this.graphics,
group,
this
)
} else {
return group;
}
return new GameLib.Group(
this.graphics,
group,
this
)
}.bind(this)
);
@ -460,7 +456,15 @@ GameLib.D3.Geometry.Buffer.prototype.toSingleMaterial = function() {
0
);
this.groups = this.instance.groups;
this.groups = this.instance.groups.map(
function(group) {
return new GameLib.Group(
this.graphics,
group,
this
)
}.bind(this)
)
} else {
console.warn('this is not an indexed buffer geometry or geometry not loaded');

View File

@ -143,8 +143,9 @@ GameLib.D3.Geometry.Normal.prototype.createInstance = function() {
this.applyToInstance('vertices');
//TODO: Below is actually for blender data - fix this server side and then remove this eventually
//this.instance.computeFaceNormals();
//this.instance.computeVertexNormals();
this.invertWindingOrder();
this.computeFaceNormals();
this.computeVertexNormals();
GameLib.D3.Geometry.prototype.createInstance.call(this);
};
@ -470,6 +471,14 @@ GameLib.D3.Geometry.Normal.prototype.computeVertexNormals = function() {
this.instance.computeVertexNormals();
};
/**
* Re-compute vertex normals
*/
GameLib.D3.Geometry.Normal.prototype.computeFaceNormals = function() {
console.log('re-computing face normals');
this.instance.computeFaceNormals();
};
/**
* Invert winding order
*/

View File

@ -594,7 +594,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) {
*/
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE_IMAGE).map(
function(texture) {
if (texture.image === data.component) {
if (texture.instance && texture.image === data.component) {
texture.updateInstance('image');
}
}
@ -602,7 +602,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) {
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE_CUBE).map(
function(texture) {
if (texture.images.indexOf(data.component) !== -1) {
if (texture.instance && texture.images.indexOf(data.component) !== -1) {
texture.updateInstance('images');
}
}