From 7db877385f8befa404442525d58ebdf70b7339a7 Mon Sep 17 00:00:00 2001 From: Maksims Mihejevs Date: Fri, 20 Nov 2015 15:34:09 +0000 Subject: [PATCH] remove ballsocketjoint, add vec2, vec3, vec4 script attribute types --- build/dependencies.txt | 3 - .../particlesystem/particlesystem_system.js | 6 +- .../joints/ballsocketjoint_component.js | 84 --------- .../physics/joints/ballsocketjoint_data.js | 25 --- .../physics/joints/ballsocketjoint_system.js | 172 ------------------ .../components/script/script_system.js | 18 +- src/framework/framework_application.js | 1 - 7 files changed, 16 insertions(+), 293 deletions(-) delete mode 100644 src/framework/components/physics/joints/ballsocketjoint_component.js delete mode 100644 src/framework/components/physics/joints/ballsocketjoint_data.js delete mode 100644 src/framework/components/physics/joints/ballsocketjoint_system.js diff --git a/build/dependencies.txt b/build/dependencies.txt index 80b134cee9e..b68fd3c9c3e 100644 --- a/build/dependencies.txt +++ b/build/dependencies.txt @@ -131,9 +131,6 @@ ../src/framework/components/physics/collision/collision_system.js ../src/framework/components/physics/collision/collision_component.js ../src/framework/components/physics/collision/collision_data.js -../src/framework/components/physics/joints/ballsocketjoint_system.js -../src/framework/components/physics/joints/ballsocketjoint_component.js -../src/framework/components/physics/joints/ballsocketjoint_data.js ../src/framework/components/particlesystem/particlesystem_system.js ../src/framework/components/particlesystem/particlesystem_component.js ../src/framework/components/particlesystem/particlesystem_data.js diff --git a/src/framework/components/particlesystem/particlesystem_system.js b/src/framework/components/particlesystem/particlesystem_system.js index c7d32fd83f9..2ea4e98db8c 100644 --- a/src/framework/components/particlesystem/particlesystem_system.js +++ b/src/framework/components/particlesystem/particlesystem_system.js @@ -66,8 +66,8 @@ pc.extend(pc, function() { ]; this.propertyTypes = { - emitterExtents: 'vector', - wrapBounds: 'vector', + emitterExtents: 'vec3', + wrapBounds: 'vec3', localVelocityGraph: 'curveset', localVelocityGraph2: 'curveset', velocityGraph: 'curveset', @@ -103,7 +103,7 @@ pc.extend(pc, function() { data[prop] = _data[prop]; } - if (types[prop] === 'vector') { + if (types[prop] === 'vec3') { if (pc.type(data[prop]) === 'array') { data[prop] = new pc.Vec3(data[prop][0], data[prop][1], data[prop][2]); } diff --git a/src/framework/components/physics/joints/ballsocketjoint_component.js b/src/framework/components/physics/joints/ballsocketjoint_component.js deleted file mode 100644 index 6a952b0d6f1..00000000000 --- a/src/framework/components/physics/joints/ballsocketjoint_component.js +++ /dev/null @@ -1,84 +0,0 @@ -pc.extend(pc, function () { - /** - * @private - * @component - * @name pc.BallSocketJointComponent - * @description Create a new BallSocketJointComponent - * @class A ball-socket joint limits translation such that the local pivot points of two rigid bodies - * match in world space. A chain of rigidbodies can be connected using this constraint. - * @param {pc.BallSocketJointComponentSystem} system The ComponentSystem that created this Component - * @param {pc.Entity} entity The Entity that this Component is attached to. - * @extends pc.Component - */ - /** - * @private - * @field - * @type pc.Vec3 - * @name pc.BallSocketJointComponent#pivot - * @description The position of the pivot in the local space of the entity. - */ - /** - * @private - * @field - * @type pc.Vec3 - * @name pc.BallSocketJointComponent#position - * @description The world space position of the constraint. - */ - var BallSocketJointComponent = function BallSocketJointComponent (system, entity) { - this.on('set_pivot', this.onSetPivot, this); - this.on('set_position', this.onSetPosition, this); - this.on('set_tau', this.onSetTau, this); - this.on('set_damping', this.onSetDamping, this); - this.on('set_impulseClamp', this.onSetImpulseClamp, this); - }; - BallSocketJointComponent = pc.inherits(BallSocketJointComponent, pc.Component); - - pc.extend(BallSocketJointComponent.prototype, { - - onSetPivot: function (name, oldValue, newValue) { - if (typeof Ammo !== 'undefined') { - if (this.data.constraint) { - var pivotA = new Ammo.btVector3(newValue.x, newValue.y, newValue.z); - this.data.constraint.setPivotA(pivotA); - } - } - }, - - onSetPosition: function (name, oldValue, newValue) { - if (typeof Ammo !== 'undefined') { - if (this.data.constraint) { - var pivotB = new Ammo.btVector3(newValue.x, newValue.y, newValue.z); - this.data.constraint.setPivotB(pivotB); - } - } - }, - - onSetTau: function (name, oldValue, newValue) { - if (typeof Ammo !== 'undefined') { - if (this.data.constraint) { - this.data.constraint.get_m_setting().set_m_tau(newValue); - } - } - }, - - onSetDamping: function (name, oldValue, newValue) { - if (typeof Ammo !== 'undefined') { - if (this.data.constraint) { - this.data.constraint.get_m_setting().set_m_damping(newValue); - } - } - }, - - onSetImpulseClamp: function (name, oldValue, newValue) { - if (typeof Ammo !== 'undefined') { - if (this.data.constraint) { - this.data.constraint.get_m_setting().set_m_impulseClamp(newValue); - } - } - } - }); - - return { - BallSocketJointComponent: BallSocketJointComponent - }; -}()); diff --git a/src/framework/components/physics/joints/ballsocketjoint_data.js b/src/framework/components/physics/joints/ballsocketjoint_data.js deleted file mode 100644 index 946ebbb60ad..00000000000 --- a/src/framework/components/physics/joints/ballsocketjoint_data.js +++ /dev/null @@ -1,25 +0,0 @@ -pc.extend(pc, function () { - - /** - * @private - * @name pc.BallSocketJointComponentData - * @description Create a new BallSocketJointComponentData - * @class Data definition for ball-socket joints. - * @extends pc.ComponentData - */ - var BallSocketJointComponentData = function () { - this.pivot = new pc.Vec3(0, 0, 0); - this.position = new pc.Vec3(0, 0, 0); - this.tau = 0.3; - this.damping = 1; - this.impulseClamp = 0; - - // Non-serialized properties - this.constraint = null; - }; - BallSocketJointComponentData = pc.inherits(BallSocketJointComponentData, pc.ComponentData); - - return { - BallSocketJointComponentData: BallSocketJointComponentData - }; -}()); diff --git a/src/framework/components/physics/joints/ballsocketjoint_system.js b/src/framework/components/physics/joints/ballsocketjoint_system.js deleted file mode 100644 index 5e6f3e46fc9..00000000000 --- a/src/framework/components/physics/joints/ballsocketjoint_system.js +++ /dev/null @@ -1,172 +0,0 @@ -pc.extend(pc, function () { - /** - * @private - * @name pc.BallSocketJointComponentSystem - * @description Create a new BallSocketJointComponentSystem - * @class Manages creation of BallSocketJointComponents - * @param {pc.Application} app The running {pc.Application} - * @extends pc.ComponentSystem - */ - var BallSocketJointComponentSystem = function BallSocketJointComponentSystem(app) { - this.id = "ballsocketjoint"; - app.systems.add(this.id, this); - - this.ComponentType = pc.BallSocketJointComponent; - this.DataType = pc.BallSocketJointComponentData; - - this.schema = [{ - name: "pivot", - displayName: "Pivot", - description: "Local space pivot", - type: "vector", - options: { - min: 0, - step: 0.1 - }, - defaultValue: [0, 0, 0] - }, { - name: "position", - displayName: "Position", - description: "World space joint position", - type: "vector", - options: { - min: 0, - step: 0.1 - }, - defaultValue: [0, 0, 0] - }, { - name: "tau", - displayName: "Tau", - description: "TBD", - type: "number", - defaultValue: 0.001, - options: { - min: 0, - max: 1 - } - }, { - name: "damping", - displayName: "Damping", - description: "Damping", - type: "number", - defaultValue: 1, - options: { - min: 0, - max: 1 - } - }, { - name: "impulseClamp", - displayName: "Impulse Clamp", - description: "Impulse Clamp", - type: "number", - defaultValue: 0, - options: { - min: 0, - max: 100 - } - }, { - name: "constraint", - exposed: false - }]; - - this.debugRender = false; - - this.on('remove', this.onRemove, this); - - pc.ComponentSystem.on('update', this.onUpdate, this); - pc.ComponentSystem.on('toolsUpdate', this.onToolsUpdate, this); - }; - BallSocketJointComponentSystem = pc.inherits(BallSocketJointComponentSystem, pc.ComponentSystem); - - BallSocketJointComponentSystem.prototype = pc.extend(BallSocketJointComponentSystem.prototype, { - onLibraryLoaded: function () { - if (typeof Ammo !== 'undefined') { - // Only register update event if Ammo is loaded - } else { - pc.ComponentSystem.off('update', this.onUpdate, this); - } - }, - - initializeComponentData: function (component, _data, properties) { - // duplicate the input data because we are modifying it - var data = pc.extend({}, _data); - - if (typeof Ammo !== 'undefined') { - if (component.entity.rigidbody) { - if (data.pivot && pc.type(data.pivot) === 'array') { - data.pivot = new pc.Vec3(data.pivot[0], data.pivot[1], data.pivot[2]); - } - - if (data.position && pc.type(data.position) === 'array') { - data.position = new pc.Vec3(data.position[0], data.position[1], data.position[2]); - } - - var pivotA = new Ammo.btVector3(data.pivot.x, data.pivot.y, data.pivot.z); - var body = component.entity.rigidbody.body; - data.constraint = new Ammo.btPoint2PointConstraint(body, pivotA); - - var pivotB = data.constraint.getPivotInB(); - data.position = [ pivotB.x(), pivotB.y(), pivotB.z() ]; - - var app = this.app; - app.systems.rigidbody.addConstraint(data.constraint); - } - } - - properties = ['constraint', 'pivot', 'position', 'tau', 'damping', 'impulseClamp']; - - BallSocketJointComponentSystem._super.initializeComponentData.call(this, component, data, properties); - }, - - cloneComponent: function (entity, clone) { - // overridden to make sure pivotA is duplicated - var data = { - pivot: [ entity.ballsocketjoint.pivot.x, entity.ballsocketjoint.pivot.y, entity.ballsocketjoint.pivot.z ], - position: [ entity.ballsocketjoint.position.x, entity.ballsocketjoint.position.y, entity.ballsocketjoint.position.z ], - tau: entity.ballsocketjoint.tau, - damping: entity.ballsocketjoint.damping, - impulseClamp: entity.ballsocketjoint.impulseClamp - }; - return this.addComponent(clone, data); - }, - - onRemove: function (entity, data) { - if (data.constraint) { - this.app.systems.rigidbody.removeConstraint(data.constraint); - } - }, - - /** - * @private - * @function - * @name pc.BallSocketJointComponentSystem#setDebugRender - * @description Display debug representation of the joint - * @param {Boolean} value Enable or disable - */ - setDebugRender: function (value) { - this.debugRender = value; - }, - - onUpdate: function (dt) { - if (this.debugRender) { - this.updateDebugShapes(); - } - }, - - onToolsUpdate: function (dt) { - this.updateDebugShapes(); - }, - - updateDebugShapes: function () { - var components = this.store; - for (var id in components) { - var entity = components[id].entity; - var data = components[id].data; - } - } - }); - - return { - BallSocketJointComponentSystem: BallSocketJointComponentSystem - }; -}()); diff --git a/src/framework/components/script/script_system.js b/src/framework/components/script/script_system.js index 8ba4712ae9a..656efba2fa6 100644 --- a/src/framework/components/script/script_system.js +++ b/src/framework/components/script/script_system.js @@ -559,14 +559,22 @@ pc.extend(pc, function () { new pc.Color(attribute.value[0], attribute.value[1], attribute.value[2]) : new pc.Color(attribute.value[0], attribute.value[1], attribute.value[2], attribute.value[3]); } - } else if (attribute.type === 'vector') { - if (pc.type(attribute.value) === 'array') { + } else if (attribute.type === 'vec2') { + if (pc.type(attribute.value) === 'array') + attribute.value = new pc.Vec2(attribute.value[0], attribute.value[1]); + + } else if (attribute.type === 'vec3' || attribute.type === 'vector') { + if (pc.type(attribute.value) === 'array') attribute.value = new pc.Vec3(attribute.value[0], attribute.value[1], attribute.value[2]); - } + + } else if (attribute.type === 'vec4') { + if (pc.type(attribute.value) === 'array') + attribute.value = new pc.Vec4(attribute.value[0], attribute.value[1], attribute.value[2], attribute.value[3]); + } else if (attribute.type === 'entity') { - if (attribute.value !== null && typeof attribute.value === 'string') { + if (attribute.value !== null && typeof attribute.value === 'string') attribute.value = this.app.root.findByGuid(attribute.value); - } + } else if (attribute.type === 'curve' || attribute.type === 'colorcurve') { var curveType = attribute.value.keys[0] instanceof Array ? pc.CurveSet : pc.Curve; attribute.value = new curveType(attribute.value.keys); diff --git a/src/framework/framework_application.js b/src/framework/framework_application.js index e2ecb5aa99b..c206aff7905 100644 --- a/src/framework/framework_application.js +++ b/src/framework/framework_application.js @@ -93,7 +93,6 @@ pc.extend(pc, function () { var rigidbodysys = new pc.RigidBodyComponentSystem(this); var collisionsys = new pc.CollisionComponentSystem(this); - var ballsocketjointsys = new pc.BallSocketJointComponentSystem(this); var animationsys = new pc.AnimationComponentSystem(this); var modelsys = new pc.ModelComponentSystem(this); var camerasys = new pc.CameraComponentSystem(this);