mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 19:10:49 +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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(parentID);
|
//EntityItemPointer entity = _entityTree->findEntityByEntityItemID(parentID);
|
||||||
if (!entity) {
|
//if (!entity) {
|
||||||
qCDebug(entities) << "EntityScriptingInterface::getChildrenIDs - no entity with ID" << parentID;
|
// qCDebug(entities) << "EntityScriptingInterface::getChildrenIDs - no entity with ID" << parentID;
|
||||||
return result;
|
// return result;
|
||||||
}
|
//}
|
||||||
|
|
||||||
_entityTree->withReadLock([&] {
|
_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());
|
result.push_back(child->getID());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,8 +31,7 @@ var DEFAULT_SCRIPTS_COMBINED = [
|
||||||
"system/firstPersonHMD.js",
|
"system/firstPersonHMD.js",
|
||||||
"system/tablet-ui/tabletUI.js",
|
"system/tablet-ui/tabletUI.js",
|
||||||
"system/emote.js",
|
"system/emote.js",
|
||||||
"system/createobject.js",
|
"system/createobject.js"
|
||||||
"system/deleteobject.js"
|
|
||||||
];
|
];
|
||||||
var DEFAULT_SCRIPTS_SEPARATE = [
|
var DEFAULT_SCRIPTS_SEPARATE = [
|
||||||
"system/controllers/controllerScripts.js"
|
"system/controllers/controllerScripts.js"
|
||||||
|
|
|
@ -3,34 +3,69 @@
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
|
||||||
function createEntity(description, position, parent) {
|
function createEntity(description, position, parent) {
|
||||||
var entity = Entities.addEntity({
|
var entity = Entities.addEntity({
|
||||||
type: "Sphere",
|
type: "Sphere",
|
||||||
position: position,
|
position: position,
|
||||||
dimensions: Vec3.HALF,
|
dimensions: Vec3.HALF,
|
||||||
dynamic: true,
|
dynamic: true,
|
||||||
collisionless: true,
|
collisionless: true,
|
||||||
parentID: parent,
|
parentID: parent,
|
||||||
lifetime: 300 // Delete after 5 minutes.
|
lifetime: 300 // Delete after 5 minutes.
|
||||||
});
|
});
|
||||||
print(description + ": " + entity);
|
//print(description + ": " + entity);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function createBabies() {
|
function createBabies() {
|
||||||
var position = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, {x: 0, y: 2, z: -5}));
|
var position = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, {x: 0, y: 2, z: -5}));
|
||||||
var root = createEntity("Root", position, Uuid.NULL);
|
//var root = createEntity("Root", position, Uuid.NULL);
|
||||||
var ctr;
|
var avatarChildren = [];
|
||||||
var avatarChildren = [];
|
var overlayChildren = [];
|
||||||
// make five children.
|
var entityChildren = [];
|
||||||
for(var ctr = 0; ctr < 5; ctr++) {
|
var avatar = MyAvatar.sessionUUID;
|
||||||
avatarChildren.append(CreateEntity("Child" + ctr, Vec3.sum(position, { x: ctr, y: -1, z: ctr }), root));
|
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({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/clap-i.svg",
|
icon: "icons/tablet-icons/clap-i.svg",
|
||||||
text: "Create OBJ",
|
text: "Create OBJ",
|
||||||
sortOrder: 1
|
sortOrder: 12
|
||||||
});
|
});
|
||||||
|
|
||||||
button.clicked.connect(createBabies);
|
button.clicked.connect(createBabies);
|
||||||
|
|
|
@ -3,21 +3,20 @@
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
|
||||||
function destroyBabies() {
|
function destroyBabies() {
|
||||||
var avatarEntityID =
|
// TODO: destroy babies
|
||||||
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({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/clap-i.svg",
|
icon: "icons/tablet-icons/clap-a.svg",
|
||||||
text: "Destroy OBJ",
|
text: "Destroy OBJ",
|
||||||
sortOrder: 1
|
sortOrder: 13
|
||||||
});
|
});
|
||||||
|
|
||||||
button.clicked.connect(createBabies);
|
button.clicked.connect(destroyBabies);
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
button.clicked.disconnect(createBabies);
|
button.clicked.disconnect(destroyBabies);
|
||||||
if (tablet) {
|
if (tablet) {
|
||||||
tablet.removeButton(button);
|
tablet.removeButton(button);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue