From bcb38b6626f093d12ca0c189a9257871512276ea Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 29 Mar 2019 09:00:25 -0700 Subject: [PATCH] Add damping to new dynamic entities in Create --- scripts/system/edit.js | 54 +++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 894ea2b696..7c5af27b82 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -282,6 +282,28 @@ function checkEditPermissionsAndUpdate() { } } +// Copies the properties in `b` into `a`. `a` will be modified. +function copyProperties(a, b) { + for (var key in b) { + a[key] = b[key]; + } + return a; +} + +const DEFAULT_DYNAMIC_PROPERTIES = { + dynamic: true, + damping: 0.39347, + angularDamping: 0.39347, + gravity: { x: 0, y: -9.8, z: 0 }, +}; + +const DEFAULT_NON_DYNAMIC_PROPERTIES = { + dynamic: false, + damping: 0, + angularDamping: 0, + gravity: { x: 0, y: 0, z: 0 }, +}; + const DEFAULT_ENTITY_PROPERTIES = { All: { description: "", @@ -299,26 +321,14 @@ const DEFAULT_ENTITY_PROPERTIES = { y: 0, z: 0 }, - damping: 0, angularVelocity: { x: 0, y: 0, z: 0 }, - angularDamping: 0, restitution: 0.5, friction: 0.5, density: 1000, - gravity: { - x: 0, - y: 0, - z: 0 - }, - acceleration: { - x: 0, - y: 0, - z: 0 - }, dynamic: false, }, Shape: { @@ -484,11 +494,6 @@ var toolBar = (function () { dialogWindow = null, tablet = null; - function applyProperties(originalProperties, newProperties) { - for (var key in newProperties) { - originalProperties[key] = newProperties[key]; - } - } function createNewEntity(requestedProperties) { var dimensions = requestedProperties.dimensions ? requestedProperties.dimensions : DEFAULT_DIMENSIONS; var position = getPositionToCreateEntity(); @@ -496,17 +501,23 @@ var toolBar = (function () { var properties = {}; - applyProperties(properties, DEFAULT_ENTITY_PROPERTIES.All); + copyProperties(properties, DEFAULT_ENTITY_PROPERTIES.All); var type = requestedProperties.type; if (type === "Box" || type === "Sphere") { - applyProperties(properties, DEFAULT_ENTITY_PROPERTIES.Shape); + copyProperties(properties, DEFAULT_ENTITY_PROPERTIES.Shape); } else { - applyProperties(properties, DEFAULT_ENTITY_PROPERTIES[type]); + copyProperties(properties, DEFAULT_ENTITY_PROPERTIES[type]); } // We apply the requested properties first so that they take priority over any default properties. - applyProperties(properties, requestedProperties); + copyProperties(properties, requestedProperties); + + if (properties.dynamic) { + copyProperties(properties, DEFAULT_DYNAMIC_PROPERTIES); + } else { + copyProperties(properties, DEFAULT_NON_DYNAMIC_PROPERTIES); + } if (position !== null && position !== undefined) { @@ -675,7 +686,6 @@ var toolBar = (function () { grabbable: result.grabbable }, dynamic: dynamic, - gravity: dynamic ? { x: 0, y: -10, z: 0 } : { x: 0, y: 0, z: 0 } }); } }