Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions src/framework/components/model/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ import { ModelComponent } from './component.js';
* @import { AppBase } from '../../app-base.js'
*/

// order matters here
const _properties = [
'material',
'materialAsset',
'asset',
'castShadows',
'receiveShadows',
'castShadowsLightmap',
'lightmapped',
'lightmapSizeMultiplier',
'type',
'mapping',
'layers',
'isStatic',
'batchGroupId'
];

/**
* Allows an Entity to render a model or a primitive shape like a box, capsule, sphere, cylinder,
* cone etc.
Expand All @@ -35,24 +52,7 @@ class ModelComponentSystem extends ComponentSystem {
this.on('beforeremove', this.onRemove, this);
}

initializeComponentData(component, _data, properties) {
// order matters here
properties = [
'material',
'materialAsset',
'asset',
'castShadows',
'receiveShadows',
'castShadowsLightmap',
'lightmapped',
'lightmapSizeMultiplier',
'type',
'mapping',
'layers',
'isStatic',
'batchGroupId'
];

initializeComponentData(component, _data) {
if (_data.batchGroupId === null || _data.batchGroupId === undefined) {
_data.batchGroupId = -1;
}
Expand All @@ -62,9 +62,9 @@ class ModelComponentSystem extends ComponentSystem {
_data.layers = _data.layers.slice(0);
}

for (let i = 0; i < properties.length; i++) {
if (_data.hasOwnProperty(properties[i])) {
component[properties[i]] = _data[properties[i]];
for (let i = 0; i < _properties.length; i++) {
if (_data.hasOwnProperty(_properties[i])) {
component[_properties[i]] = _data[_properties[i]];
}
}

Expand All @@ -77,20 +77,26 @@ class ModelComponentSystem extends ComponentSystem {

cloneComponent(entity, clone) {
const data = {
type: entity.model.type,
asset: entity.model.asset,
castShadows: entity.model.castShadows,
receiveShadows: entity.model.receiveShadows,
castShadowsLightmap: entity.model.castShadowsLightmap,
lightmapped: entity.model.lightmapped,
lightmapSizeMultiplier: entity.model.lightmapSizeMultiplier,
isStatic: entity.model.isStatic,
enabled: entity.model.enabled,
layers: entity.model.layers,
batchGroupId: entity.model.batchGroupId,
mapping: extend({}, entity.model.mapping)
enabled: entity.model.enabled
};

for (let i = 0; i < _properties.length; i++) {
const property = _properties[i];
switch (property) {
// material and materialAsset are handled below, after the
// appropriate one to clone has been determined
case 'material':
case 'materialAsset':
break;
case 'mapping':
data.mapping = extend({}, entity.model.mapping);
break;
default:
data[property] = entity.model[property];
break;
}
}

// if original has a different material
// than the assigned materialAsset then make sure we
// clone that one instead of the materialAsset one
Expand Down
53 changes: 23 additions & 30 deletions src/framework/components/rigid-body/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,20 @@ class ContactResult {
}
}

const _properties = [
'mass',
'linearDamping',
'angularDamping',
'linearFactor',
'angularFactor',
'friction',
'rollingFriction',
'restitution',
'type',
'group',
'mask'
];

/**
* The RigidBodyComponentSystem manages the physics simulation for all rigid body components
* in the application. It creates and maintains the underlying Ammo.js physics world, handles
Expand Down Expand Up @@ -468,22 +482,8 @@ class RigidBodyComponentSystem extends ComponentSystem {
}
}

initializeComponentData(component, data, properties) {
const props = [
'mass',
'linearDamping',
'angularDamping',
'linearFactor',
'angularFactor',
'friction',
'rollingFriction',
'restitution',
'type',
'group',
'mask'
];

for (const property of props) {
initializeComponentData(component, data) {
for (const property of _properties) {
if (data.hasOwnProperty(property)) {
const value = data[property];
if (Array.isArray(value)) {
Expand All @@ -498,23 +498,16 @@ class RigidBodyComponentSystem extends ComponentSystem {
}

cloneComponent(entity, clone) {
// create new data block for clone
const rigidbody = entity.rigidbody;
const c = entity.rigidbody;

const data = {
enabled: rigidbody.enabled,
mass: rigidbody.mass,
linearDamping: rigidbody.linearDamping,
angularDamping: rigidbody.angularDamping,
linearFactor: [rigidbody.linearFactor.x, rigidbody.linearFactor.y, rigidbody.linearFactor.z],
angularFactor: [rigidbody.angularFactor.x, rigidbody.angularFactor.y, rigidbody.angularFactor.z],
friction: rigidbody.friction,
rollingFriction: rigidbody.rollingFriction,
restitution: rigidbody.restitution,
type: rigidbody.type,
group: rigidbody.group,
mask: rigidbody.mask
enabled: c.enabled
};

for (const property of _properties) {
data[property] = c[property];
}

return this.addComponent(clone, data);
}

Expand Down
91 changes: 44 additions & 47 deletions src/framework/components/sound/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import { SoundComponent } from './component.js';
* @import { SoundManager } from '../../../platform/sound/manager.js'
*/

const _properties = [
'volume',
'pitch',
'positional',
'refDistance',
'maxDistance',
'rollOffFactor',
'distanceModel',
'slots'
];

/**
* Manages creation of {@link SoundComponent}s.
*
Expand Down Expand Up @@ -67,63 +78,49 @@ class SoundComponentSystem extends ComponentSystem {
return this.manager.context;
}

initializeComponentData(component, data, properties) {
properties = [
'volume',
'pitch',
'positional',
'refDistance',
'maxDistance',
'rollOffFactor',
'distanceModel',
'slots'
];

for (let i = 0; i < properties.length; i++) {
if (data.hasOwnProperty(properties[i])) {
component[properties[i]] = data[properties[i]];
initializeComponentData(component, data) {
for (let i = 0; i < _properties.length; i++) {
if (data.hasOwnProperty(_properties[i])) {
component[_properties[i]] = data[_properties[i]];
}
}

super.initializeComponentData(component, data);
}

cloneComponent(entity, clone) {
const srcComponent = entity.sound;
const srcSlots = srcComponent.slots;

// convert 'slots' back to
// simple option objects
const slots = {};
for (const key in srcSlots) {
const srcSlot = srcSlots[key];
slots[key] = {
name: srcSlot.name,
volume: srcSlot.volume,
pitch: srcSlot.pitch,
loop: srcSlot.loop,
duration: srcSlot.duration,
startTime: srcSlot.startTime,
overlap: srcSlot.overlap,
autoPlay: srcSlot.autoPlay,
asset: srcSlot.asset
};
}
const c = entity.sound;

const cloneData = {
distanceModel: srcComponent.distanceModel,
enabled: srcComponent.enabled,
maxDistance: srcComponent.maxDistance,
pitch: srcComponent.pitch,
positional: srcComponent.positional,
refDistance: srcComponent.refDistance,
rollOffFactor: srcComponent.rollOffFactor,
slots: slots,
volume: srcComponent.volume
const data = {
enabled: c.enabled
};

// add component with new data
return this.addComponent(clone, cloneData);
for (let i = 0; i < _properties.length; i++) {
const property = _properties[i];
if (property === 'slots') {
// convert 'slots' back to simple option objects
const slots = {};
for (const key in c.slots) {
const srcSlot = c.slots[key];
slots[key] = {
name: srcSlot.name,
volume: srcSlot.volume,
pitch: srcSlot.pitch,
loop: srcSlot.loop,
duration: srcSlot.duration,
startTime: srcSlot.startTime,
overlap: srcSlot.overlap,
autoPlay: srcSlot.autoPlay,
asset: srcSlot.asset
};
}
data.slots = slots;
} else {
data[property] = c[property];
}
}

return this.addComponent(clone, data);
}

onUpdate(dt) {
Expand Down