fixed mesh delay error

beta.r3js.org
polygonboutique 2016-11-29 16:11:56 +01:00
parent b2bacd2d7e
commit 563f18fc99
2 changed files with 37 additions and 15 deletions

View File

@ -44,9 +44,9 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function(
//
var tmpVector = new THREE.Vector3(
parentEntity.position.x,
parentEntity.position.y,
parentEntity.position.z
this.parentEntity.position.x,
this.parentEntity.position.y,
this.parentEntity.position.z
).applyQuaternion(
new THREE.Quaternion(
this.parent.quaternion.x,
@ -76,6 +76,21 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function(
this.parentEntity.scale.z = this.parent.scale.z;
this.parentEntity.mesh.updateMatrix();
/*//
this.parentEntity.mesh.position.x = this.parentEntity.position.x;
this.parentEntity.mesh.position.y = this.parentEntity.position.y;
this.parentEntity.mesh.position.z = this.parentEntity.position.z;
this.parentEntity.mesh.quaternion.x = this.parentEntity.quaternion.x;
this.parentEntity.mesh.quaternion.y = this.parentEntity.quaternion.y;
this.parentEntity.mesh.quaternion.z = this.parentEntity.quaternion.z;
this.parentEntity.mesh.quaternion.w = this.parentEntity.quaternion.w;
this.parentEntity.mesh.scale.x = this.parentEntity.scale.x;
this.parentEntity.mesh.scale.y = this.parentEntity.scale.y;
this.parentEntity.mesh.scale.z = this.parentEntity.scale.z;*/
}
};

View File

@ -38,6 +38,21 @@ GameLib.D3.Entity = function Entity(
this.scale = scale;
};
GameLib.D3.Entity.prototype.updateMesh = function() {
if(this.mesh) {
this.mesh.position.set(this.position.x, this.position.y, this.position.z);
this.mesh.scale.set(this.scale.x, this.scale.y, this.scale.z);
this.mesh.quaternion.set(this.quaternion.x, this.quaternion.y, this.quaternion.z, this.quaternion.w).normalize();
// normalize the quaternion, if we have a mesh.
// if we don't do this, then the mesh will get stretched
this.quaternion.x = this.mesh.quaternion.x;
this.quaternion.y = this.mesh.quaternion.y;
this.quaternion.z = this.mesh.quaternion.z;
this.quaternion.w = this.mesh.quaternion.w;
}
};
/**
* Updates the Entity and it's components
* @param deltaTime Number
@ -53,18 +68,8 @@ GameLib.D3.Entity.prototype.update = function(
}
}
if(this.mesh) {
this.mesh.position.set(this.position.x, this.position.y, this.position.z);
this.mesh.scale.set(this.scale.x, this.scale.y, this.scale.z);
this.mesh.quaternion.set(this.quaternion.x, this.quaternion.y, this.quaternion.z, this.quaternion.w).normalize();
// normalize the quaternion, if we have a mesh.
// if we don't do this, then the mesh will get stretched
this.quaternion.x = this.mesh.quaternion.x;
this.quaternion.y = this.mesh.quaternion.y;
this.quaternion.z = this.mesh.quaternion.z;
this.quaternion.w = this.mesh.quaternion.w;
}
// todo: maybe we only need to call this AFTER late update
this.updateMesh();
this.onUpdate(deltaTime);
};
@ -84,6 +89,8 @@ GameLib.D3.Entity.prototype.lateUpdate = function(
}
}
this.updateMesh();
this.onLateUpdate(deltaTime);
};