mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:44:21 +02:00
Adding possible solution to issue#1934.
This commit is contained in:
parent
986318ccfd
commit
bd6905b3d2
4 changed files with 85 additions and 38 deletions
|
@ -1660,14 +1660,28 @@ QVector<QUuid> 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<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
|
||||
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());
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue