Advertisement
SforzandoCF

nt

Sep 4th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function (Scratch) {
  2.     'use strict';
  3.     if (!Scratch.extensions.unsandboxed) {
  4.         throw new Error('3D Sprite Control only works in unsandboxed mode.');
  5.     }
  6.    
  7.     class Sprite3DReference {
  8.         static references = new Map();
  9.        
  10.         static confirmMapped (target) {
  11.             if(!(references.has(target)))
  12.                 references.set(target, {x: 0, y: 0, z: 0, pitch: 90, yaw: 0, roll: 0, fov: 120});
  13.         }
  14.        
  15.         static get access (target) {
  16.             return references.get(target);
  17.         }
  18.        
  19.         static setPos (target, position) {
  20.             references.set(target, position);
  21.         }
  22.     }
  23.    
  24.     class Meshes {
  25.         static meshes = new Map();
  26.        
  27.         static getMeshes () {
  28.             return meshes.values();
  29.         }
  30.        
  31.        
  32.     }
  33.    
  34.     class Sprite3DControl {
  35.         getInfo() {
  36.             return {
  37.                 id: '3dcontrol',
  38.                 name: '3D Sprite Control',
  39.                 color1: '#83f0ff',
  40.                 color2: '#48c7d8',
  41.                 color3: '#b3f6ff',
  42.                 blocks: [
  43.                     {
  44.                         opcode: 'goto3d',
  45.                         blockType: Scratch.BlockType.COMMAND,
  46.                         text: 'go to [X], [Y], [Z]',
  47.                         arguments: {
  48.                             X: {
  49.                                 type: Scratch.ArgumentType.NUMBER,
  50.                                 defaultValue: 0
  51.                             },
  52.                             Y: {
  53.                                 type: Scratch.ArgumentType.NUMBER,
  54.                                 defaultValue: 0
  55.                             },
  56.                             Z: {
  57.                                 type: Scratch.ArgumentType.NUMBER,
  58.                                 defaultValue: 0
  59.                             }
  60.                         },
  61.                         filter: [Scratch.TargetType.SPRITE]
  62.                     },
  63.                     {
  64.                         opcode: 'getx3d',
  65.                         blockType: Scratch.BlockType.REPORTER,
  66.                         text: '3d x position',
  67.                         filter: [Scratch.TargetType.SPRITE]
  68.                     },
  69.                     {
  70.                         opcode: 'gety3d',
  71.                         blockType: Scratch.BlockType.REPORTER,
  72.                         text: '3d y position',
  73.                         filter: [Scratch.TargetType.SPRITE]
  74.                     },
  75.                     {
  76.                         opcode: 'getz3d',
  77.                         blockType: Scratch.BlockType.REPORTER,
  78.                         text: '3d z position',
  79.                         filter: [Scratch.TargetType.SPRITE]
  80.                     },
  81.                     {
  82.                         opcode: 'face3d',
  83.                         blockType: Scratch.BlockType.COMMAND,
  84.                         text: 'face towards [PITCH], [YAW], [ROLL]',
  85.                         arguments: {
  86.                             PITCH: {
  87.                                 type: Scratch.ArgumentType.ANGLE,
  88.                                 defaultValue: 90
  89.                             },
  90.                             YAW: {
  91.                                 type: Scratch.ArgumentType.ANGLE,
  92.                                 defaultValue: 0
  93.                             },
  94.                             ROLL: {
  95.                                 type: Scratch.ArgumentType.ANGLE,
  96.                                 defaultValue: 0
  97.                             }
  98.                         },
  99.                         filter: [Scratch.TargetType.SPRITE]
  100.                     },
  101.                     {
  102.                         opcode: 'getpitch3d',
  103.                         blockType: Scratch.BlockType.REPORTER,
  104.                         text: '3d pitch',
  105.                         filter: [Scratch.TargetType.SPRITE]
  106.                     },
  107.                     {
  108.                         opcode: 'getyaw3d',
  109.                         blockType: Scratch.BlockType.REPORTER,
  110.                         text: '3d yaw',
  111.                         filter: [Scratch.TargetType.SPRITE]
  112.                     },
  113.                     {
  114.                         opcode: 'getroll3d',
  115.                         blockType: Scratch.BlockType.REPORTER,
  116.                         text: '3d roll',
  117.                         filter: [Scratch.TargetType.SPRITE]
  118.                     },
  119.                     {
  120.                         opcode: 'setfov3d',
  121.                         blockType: Scratch.BlockType.COMMAND,
  122.                         text: 'set field of view [FOV]',
  123.                         arguments: {
  124.                             FOV: {
  125.                                 type: Scratch.ArgumentType.ANGLE,
  126.                                 defaultValue: 120
  127.                             }
  128.                         },
  129.                         filter: [Scratch.TargetType.SPRITE]
  130.                     },
  131.                     {
  132.                         opcode: 'getfov3d',
  133.                         blockType: Scratch.BlockType.REPORTER,
  134.                         text: 'field of view',
  135.                         filter: [Scratch.TargetType.SPRITE]
  136.                     }
  137.                 ]
  138.             };
  139.         }
  140.        
  141.         goto3d(args, util) {
  142.             const target = util.target;
  143.             Sprite3DReference.confirmMapped(target);
  144.             const oldPos = Sprite3DReference.access(target);
  145.             const pos = {x: args.X, y: args.Y, z: args.Z, pitch: oldPos.pitch, yaw: oldPos.yaw, roll: oldPos.roll, fov: oldPos.fov};
  146.             Sprite3DReference.setPos(target, pos);
  147.         }
  148.        
  149.         getx3d(args, util) {
  150.             const target = util.target;
  151.             Sprite3DReference.confirmMapped(target);
  152.             const pos = Sprite3DReference.access(target);
  153.             return pos.x;
  154.         }
  155.        
  156.         gety3d(args, util) {
  157.             const target = util.target;
  158.             Sprite3DReference.confirmMapped(target);
  159.             const pos = Sprite3DReference.access(target);
  160.             return pos.y;
  161.         }
  162.        
  163.         getz3d(args, util) {
  164.             const target = util.target;
  165.             Sprite3DReference.confirmMapped(target);
  166.             const pos = Sprite3DReference.access(target);
  167.             return pos.z;
  168.         }
  169.        
  170.         face3d(args, util) {
  171.             const target = util.target;
  172.             Sprite3DReference.confirmMapped(target);
  173.             const oldPos = Sprite3DReference.access(target);
  174.             const pos = {x: oldPos.x, y: oldPos.y, z: oldPos.z, pitch: args.PITCH, yaw: args.YAW, roll: args.ROLL, fov: oldPos.fov};
  175.             Sprite3DReference.setPos(target, pos);
  176.         }
  177.        
  178.         getpitch3d(args, util) {
  179.             const target = util.target;
  180.             Sprite3DReference.confirmMapped(target);
  181.             const pos = Sprite3DReference.access(target);
  182.             return pos.pitch;
  183.         }
  184.        
  185.         getyaw3d(args, util) {
  186.             const target = util.target;
  187.             Sprite3DReference.confirmMapped(target);
  188.             const pos = Sprite3DReference.access(target);
  189.             return pos.yaw;
  190.         }
  191.        
  192.         getroll3d(args, util) {
  193.             const target = util.target;
  194.             Sprite3DReference.confirmMapped(target);
  195.             const pos = Sprite3DReference.access(target);
  196.             return pos.roll;
  197.         }
  198.        
  199.         setfov3d(args, util) {
  200.             const target = util.target;
  201.             Sprite3DReference.confirmMapped(target);
  202.             const oldPos = Sprite3DReference.access(target);
  203.             const pos = {x: oldPos.x, y: oldPos.y, z: oldPos.z, pitch: oldPos.pitch, yaw: oldPos.yaw, roll: oldPos.roll, fov: args.FOV};
  204.             Sprite3DReference.setPos(target, pos);
  205.         }
  206.        
  207.         getfov3d(args, util) {
  208.             const target = util.target;
  209.             Sprite3DReference.confirmMapped(target);
  210.             const pos = Sprite3DReference.access(target);
  211.             return pos.fov;
  212.         }
  213.        
  214.         render(args, util) {
  215.         }
  216.     }
  217.     Scratch.extensions.register(new Sprite3DControl());
  218. })(Scratch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement