Spaces:
Running
Running
Update deplacement_dans_env/viewer_pr_env.js
Browse files
deplacement_dans_env/viewer_pr_env.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
//
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
/* -------------------------------------------
|
|
@@ -60,7 +60,7 @@ function traverse(entity, callback) {
|
|
| 60 |
}
|
| 61 |
|
| 62 |
/* -------------------------------------------
|
| 63 |
-
Chargement unique de
|
| 64 |
-------------------------------------------- */
|
| 65 |
|
| 66 |
async function ensureOrbitScriptsLoaded() {
|
|
@@ -72,6 +72,7 @@ async function ensureOrbitScriptsLoaded() {
|
|
| 72 |
|
| 73 |
window.__PLY_ORBIT_LOADING__ = new Promise((resolve, reject) => {
|
| 74 |
const s = document.createElement("script");
|
|
|
|
| 75 |
s.src = "https://mikafil-viewer-sgos.static.hf.space/deplacement_dans_env/ctrl_camera_pr_env.js";
|
| 76 |
s.async = true;
|
| 77 |
s.onload = () => {
|
|
@@ -79,7 +80,7 @@ async function ensureOrbitScriptsLoaded() {
|
|
| 79 |
resolve();
|
| 80 |
};
|
| 81 |
s.onerror = (e) => {
|
| 82 |
-
console.error("[viewer.js] Failed to load orbit-camera
|
| 83 |
reject(e);
|
| 84 |
};
|
| 85 |
document.head.appendChild(s);
|
|
@@ -101,7 +102,7 @@ let resizeObserver = null;
|
|
| 101 |
|
| 102 |
// paramètres courants de l'instance
|
| 103 |
let chosenCameraX, chosenCameraY, chosenCameraZ;
|
| 104 |
-
let
|
| 105 |
let modelX, modelY, modelZ, modelScale, modelRotationX, modelRotationY, modelRotationZ;
|
| 106 |
let presentoirScaleX, presentoirScaleY, presentoirScaleZ;
|
| 107 |
let sogsUrl, glbUrl, presentoirUrl;
|
|
@@ -121,10 +122,15 @@ export async function initializeViewer(config, instanceId) {
|
|
| 121 |
// --- Configuration ---
|
| 122 |
sogsUrl = config.sogs_json_url;
|
| 123 |
|
| 124 |
-
minZoom
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
minAzimuth = config.minAzimuth !== undefined ? parseFloat(config.minAzimuth) : -360;
|
| 129 |
maxAzimuth = config.maxAzimuth !== undefined ? parseFloat(config.maxAzimuth) : 360;
|
| 130 |
minY = config.minY !== undefined ? parseFloat(config.minY) : 0;
|
|
@@ -251,7 +257,7 @@ export async function initializeViewer(config, instanceId) {
|
|
| 251 |
// --- Charge PlayCanvas lib ESM (une par module/instance) ---
|
| 252 |
if (!pc) {
|
| 253 |
pc = await import("https://esm.run/playcanvas");
|
| 254 |
-
window.pc = pc; //
|
| 255 |
}
|
| 256 |
|
| 257 |
// --- Crée l'Application ---
|
|
@@ -320,7 +326,7 @@ export async function initializeViewer(config, instanceId) {
|
|
| 320 |
|
| 321 |
const loader = new pc.AssetListLoader(Object.values(assets), app.assets);
|
| 322 |
|
| 323 |
-
// Assure
|
| 324 |
await ensureOrbitScriptsLoaded();
|
| 325 |
|
| 326 |
loader.load(() => {
|
|
@@ -335,8 +341,7 @@ export async function initializeViewer(config, instanceId) {
|
|
| 335 |
modelEntity.setLocalScale(modelScale, modelScale, modelScale);
|
| 336 |
app.root.addChild(modelEntity);
|
| 337 |
|
| 338 |
-
|
| 339 |
-
// --- Caméra + scripts d’input (disponibles car orbit chargé globalement) ---
|
| 340 |
cameraEntity = new pc.Entity("camera");
|
| 341 |
cameraEntity.addComponent("camera", {
|
| 342 |
clearColor: new pc.Color(color_bg),
|
|
@@ -347,20 +352,36 @@ export async function initializeViewer(config, instanceId) {
|
|
| 347 |
cameraEntity.lookAt(modelEntity.getPosition());
|
| 348 |
cameraEntity.addComponent("script");
|
| 349 |
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
cameraEntity.script.create("orbitCameraInputMouse");
|
| 365 |
cameraEntity.script.create("orbitCameraInputTouch");
|
| 366 |
cameraEntity.script.create("orbitCameraInputKeyboard", {
|
|
@@ -423,8 +444,8 @@ export function resetViewerCamera() {
|
|
| 423 |
cameraEntity.lookAt(modelPos);
|
| 424 |
|
| 425 |
orbitCam.pivotPoint = modelPos.clone();
|
| 426 |
-
orbitCam._targetDistance = dist;
|
| 427 |
-
orbitCam._distance = dist;
|
| 428 |
|
| 429 |
const rot = tempEnt.getRotation();
|
| 430 |
const fwd = new pc.Vec3();
|
|
|
|
| 1 |
+
// viewer_pr_env.js
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
/* -------------------------------------------
|
|
|
|
| 60 |
}
|
| 61 |
|
| 62 |
/* -------------------------------------------
|
| 63 |
+
Chargement unique de ctrl_camera_pr_env.js
|
| 64 |
-------------------------------------------- */
|
| 65 |
|
| 66 |
async function ensureOrbitScriptsLoaded() {
|
|
|
|
| 72 |
|
| 73 |
window.__PLY_ORBIT_LOADING__ = new Promise((resolve, reject) => {
|
| 74 |
const s = document.createElement("script");
|
| 75 |
+
// même URL que précédemment ; le fichier a été mis à jour (bbox + no maxZoom)
|
| 76 |
s.src = "https://mikafil-viewer-sgos.static.hf.space/deplacement_dans_env/ctrl_camera_pr_env.js";
|
| 77 |
s.async = true;
|
| 78 |
s.onload = () => {
|
|
|
|
| 80 |
resolve();
|
| 81 |
};
|
| 82 |
s.onerror = (e) => {
|
| 83 |
+
console.error("[viewer.js] Failed to load orbit-camera script", e);
|
| 84 |
reject(e);
|
| 85 |
};
|
| 86 |
document.head.appendChild(s);
|
|
|
|
| 102 |
|
| 103 |
// paramètres courants de l'instance
|
| 104 |
let chosenCameraX, chosenCameraY, chosenCameraZ;
|
| 105 |
+
let distanceMin, minAngle, maxAngle, minAzimuth, maxAzimuth, minY;
|
| 106 |
let modelX, modelY, modelZ, modelScale, modelRotationX, modelRotationY, modelRotationZ;
|
| 107 |
let presentoirScaleX, presentoirScaleY, presentoirScaleZ;
|
| 108 |
let sogsUrl, glbUrl, presentoirUrl;
|
|
|
|
| 122 |
// --- Configuration ---
|
| 123 |
sogsUrl = config.sogs_json_url;
|
| 124 |
|
| 125 |
+
// plus de minZoom/maxZoom dans le JSON : on expose uniquement distanceMin (défaut 1)
|
| 126 |
+
distanceMin = config.minZoom !== undefined
|
| 127 |
+
? parseFloat(config.minZoom) // rétro-compat éventuelle
|
| 128 |
+
: (config.distanceMin !== undefined
|
| 129 |
+
? parseFloat(config.distanceMin) // si quelqu'un fournit distanceMin
|
| 130 |
+
: 1);
|
| 131 |
+
|
| 132 |
+
minAngle = parseFloat(config.minAngle ?? "-45");
|
| 133 |
+
maxAngle = parseFloat(config.maxAngle ?? "90");
|
| 134 |
minAzimuth = config.minAzimuth !== undefined ? parseFloat(config.minAzimuth) : -360;
|
| 135 |
maxAzimuth = config.maxAzimuth !== undefined ? parseFloat(config.maxAzimuth) : 360;
|
| 136 |
minY = config.minY !== undefined ? parseFloat(config.minY) : 0;
|
|
|
|
| 257 |
// --- Charge PlayCanvas lib ESM (une par module/instance) ---
|
| 258 |
if (!pc) {
|
| 259 |
pc = await import("https://esm.run/playcanvas");
|
| 260 |
+
window.pc = pc; // utile pour tooltips.js
|
| 261 |
}
|
| 262 |
|
| 263 |
// --- Crée l'Application ---
|
|
|
|
| 326 |
|
| 327 |
const loader = new pc.AssetListLoader(Object.values(assets), app.assets);
|
| 328 |
|
| 329 |
+
// Assure le chargement unique des scripts caméra
|
| 330 |
await ensureOrbitScriptsLoaded();
|
| 331 |
|
| 332 |
loader.load(() => {
|
|
|
|
| 341 |
modelEntity.setLocalScale(modelScale, modelScale, modelScale);
|
| 342 |
app.root.addChild(modelEntity);
|
| 343 |
|
| 344 |
+
// --- Caméra + scripts d’input ---
|
|
|
|
| 345 |
cameraEntity = new pc.Entity("camera");
|
| 346 |
cameraEntity.addComponent("camera", {
|
| 347 |
clearColor: new pc.Color(color_bg),
|
|
|
|
| 352 |
cameraEntity.lookAt(modelEntity.getPosition());
|
| 353 |
cameraEntity.addComponent("script");
|
| 354 |
|
| 355 |
+
// Attributs orbitCamera — sans distanceMax, avec bbox optionnelle
|
| 356 |
+
const orbitAttrs = {
|
| 357 |
+
focusEntity: modelEntity,
|
| 358 |
+
inertiaFactor: 0.2,
|
| 359 |
+
distanceMin: distanceMin,
|
| 360 |
+
pitchAngleMax: maxAngle,
|
| 361 |
+
pitchAngleMin: minAngle,
|
| 362 |
+
yawAngleMax: maxAzimuth,
|
| 363 |
+
yawAngleMin: minAzimuth,
|
| 364 |
+
minY: minY,
|
| 365 |
+
frameOnStart: false
|
| 366 |
+
};
|
| 367 |
+
|
| 368 |
+
// Injecte la BBox uniquement si présente dans le config (évite Infinity explicite)
|
| 369 |
+
const maybeNum = (v) => (v === undefined || v === null || v === "" ? undefined : parseFloat(v));
|
| 370 |
+
const Xmin = maybeNum(config.Xmin);
|
| 371 |
+
const Xmax = maybeNum(config.Xmax);
|
| 372 |
+
const Ymin = maybeNum(config.Ymin);
|
| 373 |
+
const Ymax = maybeNum(config.Ymax);
|
| 374 |
+
const Zmin = maybeNum(config.Zmin);
|
| 375 |
+
const Zmax = maybeNum(config.Zmax);
|
| 376 |
+
|
| 377 |
+
if (Xmin !== undefined) orbitAttrs.Xmin = Xmin;
|
| 378 |
+
if (Xmax !== undefined) orbitAttrs.Xmax = Xmax;
|
| 379 |
+
if (Ymin !== undefined) orbitAttrs.Ymin = Ymin;
|
| 380 |
+
if (Ymax !== undefined) orbitAttrs.Ymax = Ymax;
|
| 381 |
+
if (Zmin !== undefined) orbitAttrs.Zmin = Zmin;
|
| 382 |
+
if (Zmax !== undefined) orbitAttrs.Zmax = Zmax;
|
| 383 |
+
|
| 384 |
+
cameraEntity.script.create("orbitCamera", { attributes: orbitAttrs });
|
| 385 |
cameraEntity.script.create("orbitCameraInputMouse");
|
| 386 |
cameraEntity.script.create("orbitCameraInputTouch");
|
| 387 |
cameraEntity.script.create("orbitCameraInputKeyboard", {
|
|
|
|
| 444 |
cameraEntity.lookAt(modelPos);
|
| 445 |
|
| 446 |
orbitCam.pivotPoint = modelPos.clone();
|
| 447 |
+
orbitCam._targetDistance = Math.max(distanceMin, dist);
|
| 448 |
+
orbitCam._distance = Math.max(distanceMin, dist);
|
| 449 |
|
| 450 |
const rot = tempEnt.getRotation();
|
| 451 |
const fwd = new pc.Vec3();
|