Update: CC - Demo New - Entity Loaded (tuby5lj4di.js) 1444 bytes modified

beta.r3js.org
-=yb4f310 2018-02-16 12:15:28 +01:00
parent 7ffda44b05
commit d11f122f49
1 changed files with 59 additions and 9 deletions

View File

@ -51,7 +51,14 @@ this.keyUp = GameLib.EntityManager.Instance.findComponentById('ip0443a52d');
/**
* Program parameters
*/
this.attributeData = null;
this.attributeData = null;
this.updateInformation = [];
/**
* Attributes
*/
this.offsetAttribute = null;
this.scaleAttribute = null;
/**
* Generates new Attribute Data based on the image index according to 'width' and 'height'
@ -64,7 +71,7 @@ GameLib.CustomCode.prototype.generateAttributeData = function(index, width, heig
var scales = [];
var orientations = [];
var x, y, z = 0;
var x, y, z, scale = 0;
for (x = 0; x < width; x++) {
for (y = 0; y < height; y++) {
@ -113,7 +120,7 @@ GameLib.CustomCode.prototype.buildInstancedGeometry = function(index) {
this.instancedGeometry.instance.attributes.normal = this.boxGeometry.instance.attributes.normal;
this.instancedGeometry.instance.attributes.uv = this.boxGeometry.instance.attributes.uv;
var offsetAttribute = new THREE.InstancedBufferAttribute(
this.offsetAttribute = new THREE.InstancedBufferAttribute(
new Float32Array(this.attributeData.offsets),
3
).setDynamic(true);
@ -123,26 +130,69 @@ GameLib.CustomCode.prototype.buildInstancedGeometry = function(index) {
4
);
var scaleAttribute = new THREE.InstancedBufferAttribute(
this.scaleAttribute = new THREE.InstancedBufferAttribute(
new Float32Array(this.attributeData.scales),
3
).setDynamic(true);
this.instancedGeometry.instance.addAttribute('offset', offsetAttribute);
this.instancedGeometry.instance.addAttribute('offset', this.offsetAttribute);
this.instancedGeometry.instance.addAttribute('orientation', orientationAttribute);
this.instancedGeometry.instance.addAttribute('scale', scaleAttribute);
this.instancedGeometry.instance.addAttribute('scale', this.scaleAttribute);
}.bind(this);
GameLib.CustomCode.prototype.startAnimation = function(attributeData) {
this.beforeRender.currentAttributeData = this.attributeData;
this.beforeRender.freshAttributeData = attributeData;
this.generateAnimationVectors(attributeData);
this.beforeRender.animate = true;
}.bind(this);
GameLib.CustomCode.prototype.generateAnimationVectors = function(attributeData) {
if (!attributeData) {
console.warn('animation not ready');
}
var i;
this.updateInformation = [];
for (i = 0; i < this.offsetAttribute.count; i++) {
this.updateInformation.push(
{
offset : {
current : new THREE.Vector3(
this.offsetAttribute.array[i+0],
this.offsetAttribute.array[i+1],
this.offsetAttribute.array[i+2]
),
target : new THREE.Vector3(
attributeData.offset[i+0],
attributeData.offset[i+1],
attributeData.offset[i+2]
)
},
scale : {
current : new THREE.Vector3(
this.scaleAttribute.array[i+0],
this.scaleAttribute.array[i+1],
this.scaleAttribute.array[i+2]
),
target : new THREE.Vector3(
attributeData.scale[i+0],
attributeData.scale[i+1],
attributeData.scale[i+2]
)
}
}
);
}
}.bind(this);
this.buildInstancedGeometry(0);
this.beforeRender.entityLoaded = this;
this.keyUp.entityLoaded = this;
//@ sourceURL=entiyLoaded.js
//@ sourceURL=entityLoaded.js