From 986318ccfdfe367c08756dbde6ad9caff03bdf41 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Mon, 14 May 2018 16:33:28 -0700 Subject: [PATCH 1/6] Adding preliminary scripts to repro getChildren issue. --- scripts/defaultScripts.js | 4 ++- scripts/system/createobject.js | 60 ++++++++++++++++++++++++++++++++++ scripts/system/deleteobject.js | 41 +++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 scripts/system/createobject.js create mode 100644 scripts/system/deleteobject.js diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 71755e3abb..13994a7e3c 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -30,7 +30,9 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/dialTone.js", "system/firstPersonHMD.js", "system/tablet-ui/tabletUI.js", - "system/emote.js" + "system/emote.js", + "system/createobject.js", + "system/deleteobject.js" ]; var DEFAULT_SCRIPTS_SEPARATE = [ "system/controllers/controllerScripts.js" diff --git a/scripts/system/createobject.js b/scripts/system/createobject.js new file mode 100644 index 0000000000..527bf64315 --- /dev/null +++ b/scripts/system/createobject.js @@ -0,0 +1,60 @@ +(function(){ + var button; + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + + function createEntity(description, position, parent) { + var entity = Entities.addEntity({ + type: "Sphere", + position: position, + dimensions: Vec3.HALF, + dynamic: true, + collisionless: true, + parentID: parent, + lifetime: 300 // Delete after 5 minutes. + }); + print(description + ": " + entity); + return entity; + } + + + function createBabies() { + var position = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, {x: 0, y: 2, z: -5})); + var root = createEntity("Root", position, Uuid.NULL); + var ctr; + var avatarChildren = []; + // make five children. + for(var ctr = 0; ctr < 5; ctr++) { + avatarChildren.append(CreateEntity("Child" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), root)); + }} + + button = tablet.addButton({ + icon: "icons/tablet-icons/clap-i.svg", + text: "Create OBJ", + sortOrder: 1 + }); + + button.clicked.connect(createBabies); + + Script.scriptEnding.connect(function () { + button.clicked.disconnect(createBabies); + if (tablet) { + tablet.removeButton(button); + } + }); + +/* var entityID = Entities.addEntity({*/ + //type: "Box", + //position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0.75, z: -5 })), + //dimensions: { x: 0.5, y: 0.5, z: 0.5 }, + //dynamic: true, + //collisionless: false, + //userData: "{ \"grabbableKey\": { \"grabbable\": true, \"kinematic\": false } }", + //lifetime: 300 // Delete after 5 minutes. + //}); + + /*var actionID = Entities.addAction("slider", entityID, {*/ + //axis: { x: 0, y: 1, z: 0 }, + //linearLow: 0, + //linearHigh: 0.6 + /*});*/ +}()); diff --git a/scripts/system/deleteobject.js b/scripts/system/deleteobject.js new file mode 100644 index 0000000000..2c366b5546 --- /dev/null +++ b/scripts/system/deleteobject.js @@ -0,0 +1,41 @@ +(function(){ + var button; + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + + function destroyBabies() { + var avatarEntityID = + for(var ctr = 0; ctr < getChildrenIDs(); ctr++) { + avatarChildren.append(CreateEntity("Child" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), root)); + }} + + button = tablet.addButton({ + icon: "icons/tablet-icons/clap-i.svg", + text: "Destroy OBJ", + sortOrder: 1 + }); + + button.clicked.connect(createBabies); + + Script.scriptEnding.connect(function () { + button.clicked.disconnect(createBabies); + if (tablet) { + tablet.removeButton(button); + } + }); + +/* var entityID = Entities.addEntity({*/ + //type: "Box", + //position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0.75, z: -5 })), + //dimensions: { x: 0.5, y: 0.5, z: 0.5 }, + //dynamic: true, + //collisionless: false, + //userData: "{ \"grabbableKey\": { \"grabbable\": true, \"kinematic\": false } }", + //lifetime: 300 // Delete after 5 minutes. + //}); + + /*var actionID = Entities.addAction("slider", entityID, {*/ + //axis: { x: 0, y: 1, z: 0 }, + //linearLow: 0, + //linearHigh: 0.6 + /*});*/ +}()); From bd6905b3d2c73d75d281cd0d0a98db7aa8b943a2 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Mon, 14 May 2018 18:25:39 -0700 Subject: [PATCH 2/6] Adding possible solution to issue#1934. --- .../entities/src/EntityScriptingInterface.cpp | 28 +++++-- scripts/defaultScripts.js | 3 +- scripts/system/createobject.js | 77 ++++++++++++++----- scripts/system/deleteobject.js | 15 ++-- 4 files changed, 85 insertions(+), 38 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 7c16214a78..65bacfec5a 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -1660,14 +1660,28 @@ QVector EntityScriptingInterface::getChildrenIDs(const QUuid& parentID) { return result; } - EntityItemPointer entity = _entityTree->findEntityByEntityItemID(parentID); - if (!entity) { - qCDebug(entities) << "EntityScriptingInterface::getChildrenIDs - no entity with ID" << parentID; - return result; - } - + //EntityItemPointer entity = _entityTree->findEntityByEntityItemID(parentID); + //if (!entity) { + // qCDebug(entities) << "EntityScriptingInterface::getChildrenIDs - no entity with ID" << parentID; + // return result; + //} _entityTree->withReadLock([&] { - entity->forEachChild([&](SpatiallyNestablePointer child) { + QSharedPointer parentFinder = DependencyManager::get(); + if (!parentFinder) { + return; + } + bool success; + SpatiallyNestableWeakPointer parentWP = parentFinder->find(parentID, success); + if (!success) { + return; + } + SpatiallyNestablePointer parent = parentWP.lock(); + if (!parent) { + return; + } + //_entityTree->withReadLock([&] { + //entity->forEachChild([&](SpatiallyNestablePointer child) { + parent->forEachChild([&](SpatiallyNestablePointer child) { result.push_back(child->getID()); }); }); diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 13994a7e3c..12e9a4fd58 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -31,8 +31,7 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/firstPersonHMD.js", "system/tablet-ui/tabletUI.js", "system/emote.js", - "system/createobject.js", - "system/deleteobject.js" + "system/createobject.js" ]; var DEFAULT_SCRIPTS_SEPARATE = [ "system/controllers/controllerScripts.js" diff --git a/scripts/system/createobject.js b/scripts/system/createobject.js index 527bf64315..887313130c 100644 --- a/scripts/system/createobject.js +++ b/scripts/system/createobject.js @@ -3,34 +3,69 @@ var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); function createEntity(description, position, parent) { - var entity = Entities.addEntity({ - type: "Sphere", - position: position, - dimensions: Vec3.HALF, - dynamic: true, - collisionless: true, - parentID: parent, - lifetime: 300 // Delete after 5 minutes. - }); - print(description + ": " + entity); - return entity; + var entity = Entities.addEntity({ + type: "Sphere", + position: position, + dimensions: Vec3.HALF, + dynamic: true, + collisionless: true, + parentID: parent, + lifetime: 300 // Delete after 5 minutes. + }); + //print(description + ": " + entity); + return entity; } - function createBabies() { - var position = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, {x: 0, y: 2, z: -5})); - var root = createEntity("Root", position, Uuid.NULL); - var ctr; - var avatarChildren = []; - // make five children. - for(var ctr = 0; ctr < 5; ctr++) { - avatarChildren.append(CreateEntity("Child" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), root)); - }} + var position = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, {x: 0, y: 2, z: -5})); + //var root = createEntity("Root", position, Uuid.NULL); + var avatarChildren = []; + var overlayChildren = []; + var entityChildren = []; + var avatar = MyAvatar.sessionUUID; + if (avatar === Uuid.NULL) { + avatar = MyAvatar.SELF_ID; + } + var textToWrite = "Avatar UUID: " + avatar + "\n\n"; + // make five children. + for(var ctr = 0; ctr < 5; ctr++) { + var entity = createEntity("AvatarChild" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), avatar); + avatarChildren.push(entity); + textToWrite += "AvatarChild" + ctr + " UUID: " + entity + "\n"; + } + var overlay = Overlays.addOverlay("cube", { + position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -3 })), + rotation: MyAvatar.orientation, + dimensions: { x: 0.3, y: 0.3, z: 0.3 }, + solid: true + }); + textToWrite += "\nOverlay UUID: " + overlay + "\n\n"; + for(var ctr = 0; ctr < 5; ctr++) { + var entity = createEntity("OverlayChild" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), overlay); + overlayChildren.push(entity); + textToWrite += "OverlayChild" + ctr + " UUID: " + entity + "\n"; + } + var rootEntity = Entities.addEntity({ + type: "Sphere", + position: position, + dimensions: Vec3.HALF, + dynamic: true, + collisionless: true, + lifetime: 300 // Delete after 5 minutes. + }); + textToWrite += "\nEntity UUID: " + rootEntity + "\n\n"; + for(var ctr = 0; ctr < 5; ctr++) { + var entity = createEntity("EntityChild" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), rootEntity); + entityChildren.push(entity); + textToWrite += "EntityChild" + ctr + " UUID: " + entity + "\n"; + } + console.log(textToWrite); + } button = tablet.addButton({ icon: "icons/tablet-icons/clap-i.svg", text: "Create OBJ", - sortOrder: 1 + sortOrder: 12 }); button.clicked.connect(createBabies); diff --git a/scripts/system/deleteobject.js b/scripts/system/deleteobject.js index 2c366b5546..ff65762497 100644 --- a/scripts/system/deleteobject.js +++ b/scripts/system/deleteobject.js @@ -3,21 +3,20 @@ var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); function destroyBabies() { - var avatarEntityID = - for(var ctr = 0; ctr < getChildrenIDs(); ctr++) { - avatarChildren.append(CreateEntity("Child" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), root)); - }} + // TODO: destroy babies + } + button = tablet.addButton({ - icon: "icons/tablet-icons/clap-i.svg", + icon: "icons/tablet-icons/clap-a.svg", text: "Destroy OBJ", - sortOrder: 1 + sortOrder: 13 }); - button.clicked.connect(createBabies); + button.clicked.connect(destroyBabies); Script.scriptEnding.connect(function () { - button.clicked.disconnect(createBabies); + button.clicked.disconnect(destroyBabies); if (tablet) { tablet.removeButton(button); } From f82e597ac7bf45dc654a1f0e3b6d1e5d85b1a7a9 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 15 May 2018 09:34:07 -0700 Subject: [PATCH 3/6] Updating documentation for getChildrenIDs + fixing issue #1934 --- interface/src/ui/overlays/Overlays.h | 2 +- libraries/entities/src/EntityScriptingInterface.cpp | 8 -------- libraries/entities/src/EntityScriptingInterface.h | 8 ++++---- scripts/defaultScripts.js | 3 +-- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index cf1151b46a..b2728e68b2 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -482,7 +482,7 @@ public slots: /**jsdoc * Check if there is an overlay of a given ID. - * @function Overlays.isAddedOverly + * @function Overlays.isAddedOverlay * @param {Uuid} overlayID - The ID to check. * @returns {boolean} true if an overlay with the given ID exists, false otherwise. */ diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 65bacfec5a..2558cb4ed7 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -1659,12 +1659,6 @@ QVector EntityScriptingInterface::getChildrenIDs(const QUuid& parentID) { if (!_entityTree) { return result; } - - //EntityItemPointer entity = _entityTree->findEntityByEntityItemID(parentID); - //if (!entity) { - // qCDebug(entities) << "EntityScriptingInterface::getChildrenIDs - no entity with ID" << parentID; - // return result; - //} _entityTree->withReadLock([&] { QSharedPointer parentFinder = DependencyManager::get(); if (!parentFinder) { @@ -1679,8 +1673,6 @@ QVector EntityScriptingInterface::getChildrenIDs(const QUuid& parentID) { if (!parent) { return; } - //_entityTree->withReadLock([&] { - //entity->forEachChild([&](SpatiallyNestablePointer child) { parent->forEachChild([&](SpatiallyNestablePointer child) { result.push_back(child->getID()); }); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 7e47d9e2d4..46a994e183 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -1216,12 +1216,12 @@ public slots: /**jsdoc - * Get the IDs of entities, overlays, and avatars that are directly parented to an entity. To get all descendants of an - * entity, recurse on the IDs returned by the function. + * Get the IDs of entities, overlays, and avatars that are directly parented to an entity, overlay, or avatar model. To get all descendants of an + * entity; overlay; or avatar, recurse on the IDs returned by the function. * @function Entities.getChildrenIDs - * @param {Uuid} parentID - The ID of the entity to get the children IDs of. + * @param {Uuid} parentID - The ID of the entity, overlay, or avatar to get the children IDs of. * @returns {Uuid[]} An array of entity, overlay, and avatar IDs that are parented directly to the parentID - * entity. Does not include children's children, etc. The array is empty if no children can be found or + * entity, overlay, or avatar. Does not include children's children, etc. The array is empty if no children can be found or * parentID cannot be found. * @example Report the children of an entity. * function createEntity(description, position, parent) { diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 12e9a4fd58..71755e3abb 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -30,8 +30,7 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/dialTone.js", "system/firstPersonHMD.js", "system/tablet-ui/tabletUI.js", - "system/emote.js", - "system/createobject.js" + "system/emote.js" ]; var DEFAULT_SCRIPTS_SEPARATE = [ "system/controllers/controllerScripts.js" From 839d4a3bdaa961a0614b80bd67c665f68dc95839 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 15 May 2018 09:36:32 -0700 Subject: [PATCH 4/6] removing test script --- scripts/system/createobject.js | 95 ---------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 scripts/system/createobject.js diff --git a/scripts/system/createobject.js b/scripts/system/createobject.js deleted file mode 100644 index 887313130c..0000000000 --- a/scripts/system/createobject.js +++ /dev/null @@ -1,95 +0,0 @@ -(function(){ - var button; - var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - - function createEntity(description, position, parent) { - var entity = Entities.addEntity({ - type: "Sphere", - position: position, - dimensions: Vec3.HALF, - dynamic: true, - collisionless: true, - parentID: parent, - lifetime: 300 // Delete after 5 minutes. - }); - //print(description + ": " + entity); - return entity; - } - - function createBabies() { - var position = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, {x: 0, y: 2, z: -5})); - //var root = createEntity("Root", position, Uuid.NULL); - var avatarChildren = []; - var overlayChildren = []; - var entityChildren = []; - var avatar = MyAvatar.sessionUUID; - if (avatar === Uuid.NULL) { - avatar = MyAvatar.SELF_ID; - } - var textToWrite = "Avatar UUID: " + avatar + "\n\n"; - // make five children. - for(var ctr = 0; ctr < 5; ctr++) { - var entity = createEntity("AvatarChild" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), avatar); - avatarChildren.push(entity); - textToWrite += "AvatarChild" + ctr + " UUID: " + entity + "\n"; - } - var overlay = Overlays.addOverlay("cube", { - position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -3 })), - rotation: MyAvatar.orientation, - dimensions: { x: 0.3, y: 0.3, z: 0.3 }, - solid: true - }); - textToWrite += "\nOverlay UUID: " + overlay + "\n\n"; - for(var ctr = 0; ctr < 5; ctr++) { - var entity = createEntity("OverlayChild" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), overlay); - overlayChildren.push(entity); - textToWrite += "OverlayChild" + ctr + " UUID: " + entity + "\n"; - } - var rootEntity = Entities.addEntity({ - type: "Sphere", - position: position, - dimensions: Vec3.HALF, - dynamic: true, - collisionless: true, - lifetime: 300 // Delete after 5 minutes. - }); - textToWrite += "\nEntity UUID: " + rootEntity + "\n\n"; - for(var ctr = 0; ctr < 5; ctr++) { - var entity = createEntity("EntityChild" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), rootEntity); - entityChildren.push(entity); - textToWrite += "EntityChild" + ctr + " UUID: " + entity + "\n"; - } - console.log(textToWrite); - } - - button = tablet.addButton({ - icon: "icons/tablet-icons/clap-i.svg", - text: "Create OBJ", - sortOrder: 12 - }); - - button.clicked.connect(createBabies); - - Script.scriptEnding.connect(function () { - button.clicked.disconnect(createBabies); - if (tablet) { - tablet.removeButton(button); - } - }); - -/* var entityID = Entities.addEntity({*/ - //type: "Box", - //position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0.75, z: -5 })), - //dimensions: { x: 0.5, y: 0.5, z: 0.5 }, - //dynamic: true, - //collisionless: false, - //userData: "{ \"grabbableKey\": { \"grabbable\": true, \"kinematic\": false } }", - //lifetime: 300 // Delete after 5 minutes. - //}); - - /*var actionID = Entities.addAction("slider", entityID, {*/ - //axis: { x: 0, y: 1, z: 0 }, - //linearLow: 0, - //linearHigh: 0.6 - /*});*/ -}()); From 9269bd261965dee53c1f489fcdd0ec1267bd9beb Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 15 May 2018 09:37:42 -0700 Subject: [PATCH 5/6] removing dummy script --- scripts/system/deleteobject.js | 40 ---------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 scripts/system/deleteobject.js diff --git a/scripts/system/deleteobject.js b/scripts/system/deleteobject.js deleted file mode 100644 index ff65762497..0000000000 --- a/scripts/system/deleteobject.js +++ /dev/null @@ -1,40 +0,0 @@ -(function(){ - var button; - var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - - function destroyBabies() { - // TODO: destroy babies - } - - - button = tablet.addButton({ - icon: "icons/tablet-icons/clap-a.svg", - text: "Destroy OBJ", - sortOrder: 13 - }); - - button.clicked.connect(destroyBabies); - - Script.scriptEnding.connect(function () { - button.clicked.disconnect(destroyBabies); - if (tablet) { - tablet.removeButton(button); - } - }); - -/* var entityID = Entities.addEntity({*/ - //type: "Box", - //position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0.75, z: -5 })), - //dimensions: { x: 0.5, y: 0.5, z: 0.5 }, - //dynamic: true, - //collisionless: false, - //userData: "{ \"grabbableKey\": { \"grabbable\": true, \"kinematic\": false } }", - //lifetime: 300 // Delete after 5 minutes. - //}); - - /*var actionID = Entities.addAction("slider", entityID, {*/ - //axis: { x: 0, y: 1, z: 0 }, - //linearLow: 0, - //linearHigh: 0.6 - /*});*/ -}()); From 92e9a8e064058644efd50f25bb03692c5c003597 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Tue, 15 May 2018 16:32:01 -0700 Subject: [PATCH 6/6] fixing typo in documentation. --- libraries/entities/src/EntityScriptingInterface.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 46a994e183..eefb254c2a 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -1216,8 +1216,7 @@ public slots: /**jsdoc - * Get the IDs of entities, overlays, and avatars that are directly parented to an entity, overlay, or avatar model. To get all descendants of an - * entity; overlay; or avatar, recurse on the IDs returned by the function. + * Get the IDs of entities, overlays, and avatars that are directly parented to an entity, overlay, or avatar model. Recurse on the IDs returned by the function to get all descendants of an entity, overlay, or avatar. * @function Entities.getChildrenIDs * @param {Uuid} parentID - The ID of the entity, overlay, or avatar to get the children IDs of. * @returns {Uuid[]} An array of entity, overlay, and avatar IDs that are parented directly to the parentID