
Demo.prototype.sceneFanumTax = function () {
  this.setScene('fanumTax');

  this.loader.addAnimation({
    "light": {
        "type": "Ambient",
        "properties": { "intensity": 2.0 },
        "castShadow": false
    }
    ,"color": [{
        "r": 0.8, "g": 0.8, "b": 0.8
    }]
  });

    this.loader.addAnimation({
      "light": {
          "type": "Directional",
          "properties": { "intensity": 1.5 },
          "castShadow": false
      }
      ,position:[{x:-0.5,y:2,z:2}]
    });    

    this.loader.addAnimation({
      object:null,
    shape: {
      type: 'PLANE',
      width: 16,
      height: 9,
    },
      scale:[{uniform2d:10.0}],
      position:[{z:-20}],
      color:[{a:1.0,r:0.7,g:0.7,b:1.0}],
    });

    const maxWaves = 4;
    for(let i = 0; i < maxWaves; i++) {
      const randomAngle = Utils.random()*10-5;
      const randX = Utils.random()*5-2.5;
    this.loader.addAnimation({
      object:'sceneFanumTax/tex_waves.png',
    shape: {
      type: 'PLANE',
      width: 32,
      height: 4,
    },
      position:[{x:()=>Math.sin(getSceneTimeFromStart())*1+randX,y:-4-i*0.1,z:-8.0+i*0.05}],
      scale:[{x:1.5, y:1.0}],
      color:[{a:1.0,r:0.3,g:0.3,b:0.4+(i/maxWaves)*0.3}],
      angle:[{degreesZ:()=>Math.sin(getSceneTimeFromStart()+i*10)*5+randomAngle}]
    });
    }

    for(let i = 0; i < maxWaves; i++) {
      const randomAngle = Utils.random()*10-5;
      const randX = Utils.random()*5-2.5;
    this.loader.addAnimation({
      object:'sceneFanumTax/tex_waves.png',
    shape: {
      type: 'PLANE',
      width: 32,
      height: 4,
    },
      position:[{x:()=>Math.sin(getSceneTimeFromStart())*1+randX,y:-4-i*0.1,z:-4.5+i*0.05}],
      scale:[{x:1.0, y:1.0}],
      color:[{a:1.0,r:0.3,g:0.3,b:0.7+(i/maxWaves)*0.3}],
      angle:[{degreesZ:()=>Math.sin(getSceneTimeFromStart()+i*10)*5+randomAngle}]
    });
    }

    this.loader.addAnimation({
      object:null,
    shape: {
      type: 'SPHERE',
    },
      position:[{x:6,y:2.6,z:-4.5}],
      scale:[{uniform3d:2}],
      color:[{a:1.0,r:1,g:1,b:0}]
    });
    this.loader.addAnimation({
      object:null,
    shape: {
      type: 'SPHERE',
      },
      position:[{x:6.5,y:2.7,z:-4.9}],
      scale:[{uniform3d:2}],
      color:[{a:1.0,r:0,g:0,b:0}]
    });

  this.loader.addAnimation({
    start:10,
      object: 'obj/farjan.obj',
      id: 'ship2',
      position:[{x:15,y:-3.2,z:-6.0},{duration: 4, x:-25}],
      angle:[{degreesZ:()=>Math.sin(getSceneTimeFromStart()*2)*20,degreesY:90}],
  });
  const breadStack = [];
  for(let i = 0; i < 15; i++) {
    breadStack.push({
      x: Utils.random()*0.2-0.1,
      y: Utils.random()*0.1-0.05+(i>0?breadStack[i-1].y:0),
    });
  }
  this.loader.addAnimation({
    start:10,
    parent: 'ship2',
      object: 'obj/bread.obj',
      position: [{ x: 0, y: 1.6, z: 0 }],
      scale:[{"uniform3d":0.2}],
      angle:[{degreesZ:90, degreesX:90}],
      "instancer": {
        "count": breadStack.length,
        "runInstanceFunction": (properties) => {

          const i = properties.index;
          const count = properties.count;
          const time = properties.time;
          let object = properties.object;
          let color = properties.color;

          const scale = 1.0;

          const bread = breadStack[i];
          const startColumns = 15;

          object.position.x = bread.x + (i>0?Math.sin(time*3+i)*(0.3*Math.min(time/5,1.0)):0) + Math.min(time/30,1.0)*i/count*60;
          object.position.z = -i*3.0+bread.y;
          object.position.y = 0;

          object.scale.x = scale;
          object.scale.y = scale;
          object.scale.z = scale;
        }
      }
  });

  this.loader.addAnimation({
    duration: 12,
    object: 'sceneFanumTax/cargo-ship.obj',
    id: 'ship',
    angle:[{degreesX:()=>Math.sin(getSceneTimeFromStart()*1)*10,degreesY:()=>Math.sin(getSceneTimeFromStart()*1)*2}],
    position:[{x:-10,y:-3.2,z:-6.0},{duration: 10, x:20}],
    scale:[{uniform3d:1.2}]
  });

  this.loader.addAnimation({
    duration: 12,
    parent: 'ship',
      object: 'obj/bread.obj',
      position: [{ x: -3, y: 0.6, z: 0 }],
      scale:[{"uniform3d":0.2}],
      angle:[{degreesX:90}],
      "instancer": {
        "count": 50,
        "runInstanceFunction": (properties) => {

          const i = properties.index;
          const count = properties.count;
          const time = properties.time;
          let object = properties.object;
          let color = properties.color;

          const scale = 1.0;

          const startColumns = 15;

          object.position.x = (i%startColumns)*2.8;
          object.position.z = -Math.floor(i/startColumns)*3.0;
          object.position.y = 0;

          object.scale.x = scale;
          object.scale.y = scale;
          object.scale.z = scale;
        }
      }
  });

    const particleCount = 500;
    const particles = new Array(particleCount);
    for (let i = 0; i < particleCount; i++) {
      particles[i] = {
        scale: Utils.random() * 0.5 + 0.5,
        x: Utils.random() * 10 - 5,
        y: Utils.random() * 10 - 5,
        z: -2,
      };
    }


  this.textWriter("POV: Total NPC bro blinks once and  we fanum \n tax whole grain", {
      fontId: 0,
      y: .4,
      x: -.0,
      fontScale: 0.3,
      bgScaleY: .15,
      bgY: .02
  });

  const emojiWrite = ['💀','🍞','🤣','🤣','🤣'];
  emojiWrite.forEach((emojiChar, index) => {
    this.addAnimationToMainScene({
        image: emojiChar,  // The emoji character itself
        perspective: '2d',
        position: [{ x: -0.09 + index * 0.04, y: .405, z: 0 }],
        scale: [{ uniform2d: 0.23 }],
    });
  });
};
