Facebook
From Bitty Teal, 1 Year ago, written in JavaScript.
This paste is a reply to IleSelector from Marcos Pimienta - view diff
Embed
Download Paste or View Raw
Hits: 96
  1. import { HighlightLayer, StandardMaterial, SceneLoader, Vector3, Color3, Space, GizmoManager, UtilityLayerRenderer, type Scene, MeshBuilder, CreatePlane, RotationGizmo, InstancedMesh, Mesh } from "@babylonjs/core";
  2. import { objectToString } from "@vue/shared";
  3.  
  4. interface Ile {
  5.   id: number | string;
  6.   object?: Mesh;
  7. }
  8.  
  9. const iles: Ile[] = [];
  10.  
  11. function ileLoad( position: Vector3, rotation: number, scene: Scene){
  12.   const highlightLayer = new HighlightLayer("highlight", scene);
  13.   const plane: any = MeshBuilder.CreatePlane('select',{size: 1, width: 0.5, height: 2.5, sideOrientation: 2});
  14.   highlightLayer.addMesh(plane, Color3.Green());
  15.   let mat1 = new StandardMaterial("mat1", scene);
  16.   mat1.alpha = 0;
  17.   plane.material = mat1;
  18.   plane.rotation.x = Math.PI/2;
  19.   plane.rotate(new Vector3(1, 1, 1), rotation * Math.PI, Space.WORLD);
  20.   plane.translate(position, 1, Space.WORLD);
  21.  
  22.  
  23.   iles.push(
  24.       { id: 1,
  25.         object: plane.createInstance(`plane${1}`),
  26.       },
  27.       { id: 2,
  28.         object: plane.createInstance(`plane${2}`),
  29.       },
  30.       { id: 3,
  31.         object: plane.createInstance(`plane${3}`),
  32.       },
  33.       { id: 4,
  34.         object: plane.createInstance(`plane${4}`),
  35.       },
  36.       { id: 5,
  37.         object: plane.createInstance(`plane${5}`),
  38.       },
  39.     )
  40.       iles[0].object?.translate(new Vector3(0.64, 0, 0), 1, Space.WORLD);
  41.       iles[1].object?.translate(new Vector3(1.28, 0, 0), 1, Space.WORLD);
  42.       iles[2].object?.translate(new Vector3(1.88, 0, 0), 1, Space.WORLD);
  43.       iles[3].object?.translate(new Vector3(2.5, 0, 0), 1, Space.WORLD);
  44.       iles[4].object?.translate(new Vector3(3.15, 0, 0), 1, Space.WORLD);
  45.       ileSelect(1, iles, scene);
  46.   return iles;
  47. }
  48.  
  49. function ileSelect( index: number, Selectors: Ile[], scene: Scene){
  50.   Selectors.forEach((Selector)=>{
  51.     Selector.object?.setEnabled(false);
  52.   })
  53.   Selectors[index].object?.setEnabled(true);
  54. }
  55.  
  56. export { ileSelect, ileLoad };