Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function (Scratch) {
- 'use strict';
- if (!Scratch.extensions.unsandboxed) {
- throw new Error('3D Sprite Control only works in unsandboxed mode.');
- }
- class Sprite3DReference {
- static references = new Map();
- static confirmMapped (target) {
- if(!(references.has(target)))
- references.set(target, {x: 0, y: 0, z: 0, pitch: 90, yaw: 0, roll: 0, fov: 120});
- }
- static get access (target) {
- return references.get(target);
- }
- static setPos (target, position) {
- references.set(target, position);
- }
- }
- class Meshes {
- static meshes = new Map();
- static getMeshes () {
- return meshes.values();
- }
- }
- class Sprite3DControl {
- getInfo() {
- return {
- id: '3dcontrol',
- name: '3D Sprite Control',
- color1: '#83f0ff',
- color2: '#48c7d8',
- color3: '#b3f6ff',
- blocks: [
- {
- opcode: 'goto3d',
- blockType: Scratch.BlockType.COMMAND,
- text: 'go to [X], [Y], [Z]',
- arguments: {
- X: {
- type: Scratch.ArgumentType.NUMBER,
- defaultValue: 0
- },
- Y: {
- type: Scratch.ArgumentType.NUMBER,
- defaultValue: 0
- },
- Z: {
- type: Scratch.ArgumentType.NUMBER,
- defaultValue: 0
- }
- },
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'getx3d',
- blockType: Scratch.BlockType.REPORTER,
- text: '3d x position',
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'gety3d',
- blockType: Scratch.BlockType.REPORTER,
- text: '3d y position',
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'getz3d',
- blockType: Scratch.BlockType.REPORTER,
- text: '3d z position',
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'face3d',
- blockType: Scratch.BlockType.COMMAND,
- text: 'face towards [PITCH], [YAW], [ROLL]',
- arguments: {
- PITCH: {
- type: Scratch.ArgumentType.ANGLE,
- defaultValue: 90
- },
- YAW: {
- type: Scratch.ArgumentType.ANGLE,
- defaultValue: 0
- },
- ROLL: {
- type: Scratch.ArgumentType.ANGLE,
- defaultValue: 0
- }
- },
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'getpitch3d',
- blockType: Scratch.BlockType.REPORTER,
- text: '3d pitch',
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'getyaw3d',
- blockType: Scratch.BlockType.REPORTER,
- text: '3d yaw',
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'getroll3d',
- blockType: Scratch.BlockType.REPORTER,
- text: '3d roll',
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'setfov3d',
- blockType: Scratch.BlockType.COMMAND,
- text: 'set field of view [FOV]',
- arguments: {
- FOV: {
- type: Scratch.ArgumentType.ANGLE,
- defaultValue: 120
- }
- },
- filter: [Scratch.TargetType.SPRITE]
- },
- {
- opcode: 'getfov3d',
- blockType: Scratch.BlockType.REPORTER,
- text: 'field of view',
- filter: [Scratch.TargetType.SPRITE]
- }
- ]
- };
- }
- goto3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const oldPos = Sprite3DReference.access(target);
- const pos = {x: args.X, y: args.Y, z: args.Z, pitch: oldPos.pitch, yaw: oldPos.yaw, roll: oldPos.roll, fov: oldPos.fov};
- Sprite3DReference.setPos(target, pos);
- }
- getx3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const pos = Sprite3DReference.access(target);
- return pos.x;
- }
- gety3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const pos = Sprite3DReference.access(target);
- return pos.y;
- }
- getz3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const pos = Sprite3DReference.access(target);
- return pos.z;
- }
- face3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const oldPos = Sprite3DReference.access(target);
- const pos = {x: oldPos.x, y: oldPos.y, z: oldPos.z, pitch: args.PITCH, yaw: args.YAW, roll: args.ROLL, fov: oldPos.fov};
- Sprite3DReference.setPos(target, pos);
- }
- getpitch3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const pos = Sprite3DReference.access(target);
- return pos.pitch;
- }
- getyaw3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const pos = Sprite3DReference.access(target);
- return pos.yaw;
- }
- getroll3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const pos = Sprite3DReference.access(target);
- return pos.roll;
- }
- setfov3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const oldPos = Sprite3DReference.access(target);
- const pos = {x: oldPos.x, y: oldPos.y, z: oldPos.z, pitch: oldPos.pitch, yaw: oldPos.yaw, roll: oldPos.roll, fov: args.FOV};
- Sprite3DReference.setPos(target, pos);
- }
- getfov3d(args, util) {
- const target = util.target;
- Sprite3DReference.confirmMapped(target);
- const pos = Sprite3DReference.access(target);
- return pos.fov;
- }
- render(args, util) {
- }
- }
- Scratch.extensions.register(new Sprite3DControl());
- })(Scratch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement