Fix Box shape recall

This commit is contained in:
nak 2026-03-16 22:08:46 +00:00
parent 6c60821469
commit e136603d81
3 changed files with 56 additions and 21 deletions

View file

@ -45,7 +45,9 @@ function deleteClonesFor(username) {
if (!isReady) return; if (!isReady) return;
EntityViewer.queryOctree(); EntityViewer.queryOctree();
Script.setTimeout(function () { Script.setTimeout(function () {
var ids = Entities.findEntitiesByType("Shape", SCAN_CENTER, SCAN_RADIUS); // Use untyped findEntities to avoid type-specific visibility issues
// (Box entities are not always returned by findEntitiesByType)
var ids = Entities.findEntities(SCAN_CENTER, SCAN_RADIUS);
var deleted = 0; var deleted = 0;
ids.forEach(function (id) { ids.forEach(function (id) {
try { try {

View file

@ -14,7 +14,7 @@
var SHAPE_TYPE = { var SHAPE_TYPE = {
tetrahedron: "Tetrahedron", tetrahedron: "Tetrahedron",
hexahedron: "Cube", hexahedron: "Box",
octahedron: "Octahedron", octahedron: "Octahedron",
dodecahedron: "Dodecahedron", dodecahedron: "Dodecahedron",
icosahedron: "Icosahedron", icosahedron: "Icosahedron",
@ -92,7 +92,9 @@
} }
function countLiveClones(username, shapeId) { function countLiveClones(username, shapeId) {
var results = Entities.findEntitiesByType("Shape", MyAvatar.position, 100); // Scan both Shape and Box — hexahedron/cube uses the Box entity type
var results = Entities.findEntitiesByType("Shape", MyAvatar.position, 100)
.concat(Entities.findEntitiesByType("Box", MyAvatar.position, 100));
var count = 0; var count = 0;
results.forEach(function (id) { results.forEach(function (id) {
try { try {
@ -110,9 +112,11 @@
var spawnPos = Vec3.sum(shelfProps.position, var spawnPos = Vec3.sum(shelfProps.position,
Vec3.multiplyQbyV(shelfProps.rotation, SPAWN_OFFSET)); Vec3.multiplyQbyV(shelfProps.rotation, SPAWN_OFFSET));
var shapeType = SHAPE_TYPE[_shapeId] || "Sphere";
var entityType = (shapeType === "Box") ? "Box" : "Shape";
Entities.addEntity({ Entities.addEntity({
type: "Shape", type: entityType,
shape: SHAPE_TYPE[_shapeId] || "Sphere", shape: shapeType,
name: "manifold_" + _shapeId + "_" + _username, name: "manifold_" + _shapeId + "_" + _username,
position: spawnPos, position: spawnPos,
dimensions: { x: 0.25, y: 0.25, z: 0.25 }, dimensions: { x: 0.25, y: 0.25, z: 0.25 },
@ -177,7 +181,7 @@
// Mouse // Mouse
this.clickDownOnEntity = function () { onClickDown(); }; this.clickDownOnEntity = function () { onClickDown(); };
this.clickUpOnEntity = function () { _busy = false; }; this.clickReleaseOnEntity = function () { _busy = false; };
// Controller — near (<0.3m) and far (>0.3m) // Controller — near (<0.3m) and far (>0.3m)
// Requires "Triggerable" checkbox enabled on the entity. // Requires "Triggerable" checkbox enabled on the entity.

View file

@ -537,18 +537,34 @@
btn.disabled = true; btn.disabled = true;
btn.classList.add("loading"); btn.classList.add("loading");
fetch(API_BASE + "/purchase", { function doPurchase(token) {
method: "POST", return fetch(API_BASE + "/purchase", {
headers: { method: "POST",
"Content-Type": "application/json", headers: {
"Authorization": "Bearer " + state.token, "Content-Type": "application/json",
}, "Authorization": "Bearer " + token,
body: JSON.stringify({ shape: shapeId }), },
}) body: JSON.stringify({ shape: shapeId }),
});
}
doPurchase(state.token)
.then(function(r) { .then(function(r) {
if (r.status === 401) {
return refreshSession().then(function(newToken) {
return doPurchase(newToken);
});
}
if (!r.ok) return r.text().then(function(t) { throw new Error(t.trim()); }); if (!r.ok) return r.text().then(function(t) { throw new Error(t.trim()); });
return r.json(); return r.json();
}) })
.then(function(r) {
// after potential retry, r may still be a Response not yet parsed
if (r && typeof r.json === "function") {
return r.json();
}
return r;
})
.then(function(d) { .then(function(d) {
btn.classList.remove("loading"); btn.classList.remove("loading");
btn.classList.add("success"); btn.classList.add("success");
@ -583,13 +599,26 @@
btn.disabled = true; btn.disabled = true;
btn.textContent = "recalling..."; btn.textContent = "recalling...";
fetch(API_BASE + "/recall", { function doRecall(token) {
method: "POST", return fetch(API_BASE + "/recall", {
headers: { method: "POST",
"Content-Type": "application/json", headers: {
"Authorization": "Bearer " + state.token, "Content-Type": "application/json",
}, "Authorization": "Bearer " + token,
body: JSON.stringify({ username: state.username }), },
body: JSON.stringify({ username: state.username }),
});
}
doRecall(state.token)
.then(function(r) {
if (r.status === 401) {
// Token expired — refresh and retry once
return refreshSession().then(function(newToken) {
return doRecall(newToken);
});
}
return r;
}) })
.then(function(r) { .then(function(r) {
btn.classList.add("ok"); btn.classList.add("ok");