MikaFil commited on
Commit
b11ee70
·
verified ·
1 Parent(s): cdb2214

Update deplacement_dans_env/viewer_pr_env.js

Browse files
Files changed (1) hide show
  1. deplacement_dans_env/viewer_pr_env.js +15 -23
deplacement_dans_env/viewer_pr_env.js CHANGED
@@ -1,11 +1,9 @@
1
  // viewer_pr_env.js
2
  // ==============================
3
- // Version 2.1 : Utilisation du MOTEUR PHYSIQUE de PlayCanvas
4
- // - CORRIGÉ : Inclut le chargement du moteur physique (Ammo.js) pour fixer l'écran noir.
5
- // - Utilise RigidBody (dynamique) pour le joueur (capsule)
6
- // - Utilise RigidBody (statique) pour l'environnement (mesh)
7
- // - Gère la gravité, le "vrai" mesh des portes, etc.
8
- // - L'ancien fichier camera.js (ou 'registerFreeCamScripts') n'est plus utilisé.
9
 
10
  /* -------------------------------------------
11
     Utils communs (Inchangés)
@@ -134,7 +132,7 @@ function registerFirstPersonScripts() {
134
      this.yaw -= e.dx * this.lookSpeed;
135
      this.pitch -= e.dy * this.lookSpeed;
136
      this.pitch = pc.math.clamp(this.pitch, this.pitchAngleMin, this.pitchAngleMax);
137
- t };
138
 
139
    FirstPersonCamera.prototype.update = function (dt) {
140
      // --- 1. Rotation (Look) ---
@@ -179,8 +177,7 @@ t };
179
        if (this.force.length() > 1) {
180
          this.force.normalize();
181
        }
182
-     }
183
-
184
      // --- 3. Appliquer au Moteur Physique ---
185
      if (this.entity.rigidbody) {
186
        // Récupère la vélocité actuelle (pour la gravité)
@@ -365,10 +362,10 @@ export async function initializeViewer(config, instanceId) {
365
    const opts = new pc.AppOptions();
366
   
367
    // ++++++++++ CORRECTIF ÉCRAN NOIR (DÉBUT) ++++++++++
368
-   // Indique à l'application trouver les fichiers du moteur physique (Ammo.js)
369
-   const ammoUrl = "https://playcanvas.vercel.app/static/lib/ammo/ammo.js";
370
-   const ammoWasmUrl = "https://playcanvas.vercel.app/static/lib/ammo/ammo.wasm.js";
371
-   const ammoWasmBinaryUrl = "https://playcanvas.vercel.app/static/lib/ammo/ammo.wasm.wasm";
372
 
373
    opts.physics = {
374
      url: ammoUrl,
@@ -430,7 +427,6 @@ export async function initializeViewer(config, instanceId) {
430
    });
431
 
432
    // --- Chargement des assets (Inchangé) ---
433
- section
434
    const sogAsset = new pc.Asset("gsplat", "gsplat", { url: sogUrl });
435
    const glbAsset = new pc.Asset("glb", "container", { url: glbUrl });
436
    app.assets.add(sogAsset);
@@ -464,14 +460,13 @@ section
464
      envEntity.name = "ENV_GLTF";
465
      app.root.addChild(envEntity);
466
 
467
-     let meshCount = 0;
468
      // Parcours le GLB et ajoute des colliders PHYSIQUES à chaque mesh
469
      traverse(envEntity, (node) => {
470
        // Si le nœud est un mesh visible (a un 'render')
471
        if (node.render) {
472
          meshCount++;
473
          // 1. Le rend statique (il ne bouge pas)
474
- content
475
          node.addComponent('rigidbody', {
476
            type: pc.BODYTYPE_STATIC,
477
            restitution: 0.0
@@ -480,7 +475,7 @@ content
480
          node.addComponent('collision', {
481
            type: 'mesh',
482
            asset: node.render.asset // Utilise l'asset du mesh pour la collision
483
-         });
484
        }
485
      });
486
      console.log("[VIEWER] Environnement GLB (physique) prêt. Meshs collidables:", meshCount);
@@ -491,7 +486,7 @@ content
491
    // --- *** NOUVEAU : Configuration du Joueur (Physique) *** ---
492
   
493
    // 1. L'entité "Player" (le corps physique, la capsule)
494
-   playerEntity = new pc.Entity("Player");
495
    playerEntity.setPosition(chosenCameraX, chosenCameraY, chosenCameraZ);
496
   
497
    // Ajoute un corps rigide DYNAMIQUE (il bouge et tombe)
@@ -516,7 +511,7 @@ content
516
      clearColor: new pc.Color(color_bg),
517
      nearClip: 0.02,
518
      farClip: 250
519
-   });
520
    // Positionne la caméra à hauteur des "yeux" dans la capsule
521
    // (Hauteur / 2) - Rayon = (1.7 / 2) - 0.35 = 0.85 - 0.35 = 0.5
522
    cameraEntity.setLocalPosition(0, 0.5, 0); // Hauteur des yeux
@@ -538,9 +533,6 @@ content
538
   
539
    // 5. Ajoute le joueur à la scène
540
    app.root.addChild(playerEntity);
541
-  
542
-   // Note: On n'ajoute plus les scripts 'InputMouse/Touch/Keyboard'
543
-   // car le nouveau script 'orbitCamera' (FPS) gère tout.
544
 
545
    // Taille initiale
546
    app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight);
@@ -554,7 +546,7 @@ content
554
      if (app.graphicsDevice.maxPixelRatio !== clamped) {
555
        app.graphicsDevice.maxPixelRatio = clamped;
556
        app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight);
557
-     }
558
    };
559
    const bumpInteraction = () => {
560
      setDpr(interactDpr);
 
1
  // viewer_pr_env.js
2
  // ==============================
3
+ // Version 2.3 : Utilisation du MOTEUR PHYSIQUE de PlayCanvas
4
+ // - CORRIGÉ (CORS) : Charge les fichiers de physique (Ammo) depuis les
5
+ // URL absolues du Space Hugging Face de l'utilisateur pour éviter
6
+ // tout blocage de sécurité.
 
 
7
 
8
  /* -------------------------------------------
9
     Utils communs (Inchangés)
 
132
      this.yaw -= e.dx * this.lookSpeed;
133
      this.pitch -= e.dy * this.lookSpeed;
134
      this.pitch = pc.math.clamp(this.pitch, this.pitchAngleMin, this.pitchAngleMax);
135
+   };
136
 
137
    FirstPersonCamera.prototype.update = function (dt) {
138
      // --- 1. Rotation (Look) ---
 
177
        if (this.force.length() > 1) {
178
          this.force.normalize();
179
        }
180
+ _
 
181
      // --- 3. Appliquer au Moteur Physique ---
182
      if (this.entity.rigidbody) {
183
        // Récupère la vélocité actuelle (pour la gravité)
 
362
    const opts = new pc.AppOptions();
363
   
364
    // ++++++++++ CORRECTIF ÉCRAN NOIR (DÉBUT) ++++++++++
365
+   // Charge les fichiers de physique depuis votre Space Hugging Face pour éviter les erreurs CORS
366
+   const ammoUrl = "https://huggingface.co/spaces/MikaFil/viewer_sgos/resolve/main/deplacement_dans_env/ammo.js";
367
+   const ammoWasmUrl = "https://huggingface.co/spaces/MikaFil/viewer_sgos/resolve/main/deplacement_dans_env/ammo.wasm.js";
368
+   const ammoWasmBinaryUrl = "https://huggingface.co/spaces/MikaFil/viewer_sgos/resolve/main/deplacement_dans_env/ammo.wasm.wasm";
369
 
370
    opts.physics = {
371
      url: ammoUrl,
 
427
    });
428
 
429
    // --- Chargement des assets (Inchangé) ---
 
430
    const sogAsset = new pc.Asset("gsplat", "gsplat", { url: sogUrl });
431
    const glbAsset = new pc.Asset("glb", "container", { url: glbUrl });
432
    app.assets.add(sogAsset);
 
460
      envEntity.name = "ENV_GLTF";
461
      app.root.addChild(envEntity);
462
 
463
+ tr     let meshCount = 0;
464
      // Parcours le GLB et ajoute des colliders PHYSIQUES à chaque mesh
465
      traverse(envEntity, (node) => {
466
        // Si le nœud est un mesh visible (a un 'render')
467
        if (node.render) {
468
          meshCount++;
469
          // 1. Le rend statique (il ne bouge pas)
 
470
          node.addComponent('rigidbody', {
471
            type: pc.BODYTYPE_STATIC,
472
            restitution: 0.0
 
475
          node.addComponent('collision', {
476
            type: 'mesh',
477
            asset: node.render.asset // Utilise l'asset du mesh pour la collision
478
+ img       });
479
        }
480
      });
481
      console.log("[VIEWER] Environnement GLB (physique) prêt. Meshs collidables:", meshCount);
 
486
    // --- *** NOUVEAU : Configuration du Joueur (Physique) *** ---
487
   
488
    // 1. L'entité "Player" (le corps physique, la capsule)
489
+ section   playerEntity = new pc.Entity("Player");
490
    playerEntity.setPosition(chosenCameraX, chosenCameraY, chosenCameraZ);
491
   
492
    // Ajoute un corps rigide DYNAMIQUE (il bouge et tombe)
 
511
      clearColor: new pc.Color(color_bg),
512
      nearClip: 0.02,
513
      farClip: 250
514
+ NT   });
515
    // Positionne la caméra à hauteur des "yeux" dans la capsule
516
    // (Hauteur / 2) - Rayon = (1.7 / 2) - 0.35 = 0.85 - 0.35 = 0.5
517
    cameraEntity.setLocalPosition(0, 0.5, 0); // Hauteur des yeux
 
533
   
534
    // 5. Ajoute le joueur à la scène
535
    app.root.addChild(playerEntity);
 
 
 
536
 
537
    // Taille initiale
538
    app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight);
 
546
      if (app.graphicsDevice.maxPixelRatio !== clamped) {
547
        app.graphicsDevice.maxPixelRatio = clamped;
548
        app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight);
549
+ ci   }
550
    };
551
    const bumpInteraction = () => {
552
      setDpr(interactDpr);