diff --git a/civero/three2.js b/civero/three2.js index 4f2985f..8c5dcaf 100644 --- a/civero/three2.js +++ b/civero/three2.js @@ -22,16 +22,16 @@ const renderer = vm.renderer; const runtime = vm.runtime; - const extensionID = "threejsextensionciveroversion"; + const extensionID = "civeroThreeJS"; let width, height; let lastCanvas; const THREE = await import("https://esm.sh/three@0.182.0"); - const {TextGeometry} = await import ("https://esm.sh/three@0.182.0/addons/geometries/TextGeometry.js"); - const {OrbitControls} = await import("https://esm.sh/three@0.182.0/examples/jsm/controls/OrbitControls.js"); - const {GLTFLoader} = await import("https://esm.sh/three@0.182.0/addons/loaders/GLTFLoader.js"); - const {FontLoader} = await import ("https://esm.sh/three@0.182.0/addons/loaders/FontLoader.js"); + const { TextGeometry } = await import("https://esm.sh/three@0.182.0/addons/geometries/TextGeometry.js"); + const { OrbitControls } = await import("https://esm.sh/three@0.182.0/examples/jsm/controls/OrbitControls.js"); + const { GLTFLoader } = await import("https://esm.sh/three@0.182.0/addons/loaders/GLTFLoader.js"); + const { FontLoader } = await import("https://esm.sh/three@0.182.0/addons/loaders/FontLoader.js"); let opentype; let three, loopId, clock, defaultGeo, defaultMat, storedFog, storedRaycast; @@ -63,8 +63,8 @@ const MathUtils = THREE.MathUtils; const AudioListener = new THREE.AudioListener(); const AudioLoader = new THREE.AudioLoader(); - - const {RectAreaLightUniformsLib} = await import("https://esm.sh/three@0.182.0/addons/lights/RectAreaLightUniformsLib.js"); + + const { RectAreaLightUniformsLib } = await import("https://esm.sh/three@0.182.0/addons/lights/RectAreaLightUniformsLib.js"); RectAreaLightUniformsLib.init(); return { renderer, context, TextureLoader, ModelLoader, MathUtils, TextLoader, AudioListener, AudioLoader }; @@ -174,7 +174,7 @@ get size() { return this._nativeSize; } - + dispose() { if (this._texture) { this._renderer.gl.deleteTexture(this._texture); @@ -189,7 +189,7 @@ const threeDrawableId = renderer.createDrawable("pen"); renderer.updateDrawableSkinId(threeDrawableId, three.skin.id); renderer._allDrawables[threeDrawableId].customDrawableName = "Three Layer"; - renderer._allDrawables[threeDrawableId].updateScale([100,-100]); //Y flip + renderer._allDrawables[threeDrawableId].updateScale([100, -100]); //Y flip }; async function init() { @@ -197,7 +197,7 @@ setupSkin(); scene = new THREE.Scene(); - camera = new THREE.PerspectiveCamera(90, width/height); + camera = new THREE.PerspectiveCamera(90, width / height); camera.name = "camera"; camera.add(three.AudioListener); camera.position.z = 2; @@ -248,7 +248,7 @@ }); const originalHQP = Scratch.vm.renderer.setUseHighQualityRender; - Scratch.vm.renderer.setUseHighQualityRender = function(state) { + Scratch.vm.renderer.setUseHighQualityRender = function (state) { originalHQP.call(Scratch.vm.renderer, state); }; } @@ -289,14 +289,14 @@ async function requestFile(format) { const file = await new Promise((resolve) => { const input = document.createElement("input"); - input.type = "file"; - input.accept = format; - input.multiple = false; - input.onchange = () => { - resolve(input.files); - input.remove(); - }; - input.click(); + input.type = "file"; + input.accept = format; + input.multiple = false; + input.onchange = () => { + resolve(input.files); + input.remove(); + }; + input.click(); }); const url = await new Promise((resolve) => { @@ -305,7 +305,7 @@ fr.readAsDataURL(file[0]); }); - return {name: file[0].name, url: url}; + return { name: file[0].name, url: url }; } Promise.resolve(init()) @@ -322,13 +322,11 @@ menuIconURI: "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIyMTQiIGhlaWdodD0iMjE0IiB2aWV3Qm94PSIwLDAsMjE0LDIxNCI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTEzMywtNzMpIj48ZyBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiPjxwYXRoIGQ9Ik0xMzMsMTgwYzAsLTU5LjA5NDQ3IDQ3LjkwNTUzLC0xMDcgMTA3LC0xMDdjNTkuMDk0NDcsMCAxMDcsNDcuOTA1NTMgMTA3LDEwN2MwLDU5LjA5NDQ3IC00Ny45MDU1MywxMDcgLTEwNywxMDdjLTU5LjA5NDQ3LDAgLTEwNywtNDcuOTA1NTMgLTEwNywtMTA3eiIgZmlsbD0iIzE5MTkxOSIgZmlsbC1ydWxlPSJub256ZXJvIiBzdHJva2U9IiM1Y2Q0OTgiIHN0cm9rZS13aWR0aD0iMCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIvPjxnIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3Ryb2tlPSIjZmZmZmZmIiBzdHJva2Utd2lkdGg9IjQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxwYXRoIGQ9Ik0yMTEuNTk4LDI4MC40N2wtNDMuMjEzLC0xNzQuOTRsMTczLjIzLDQ5Ljg3NHoiLz48cGF0aCBkPSJNMjU0Ljk2OCwxMzAuNDcybDIxLjU5MSw4Ny40OTZsLTg2LjU2NywtMjQuOTQ1eiIvPjxwYXRoIGQ9Ik0yMzMuNDg4LDIwNC44OWwtMTAuNzI0LC00My40NjVsNDMuMDA4LDEyLjM0NnoiLz48cGF0aCBkPSJNMjEyLjAzNiwxMTguMDEzbDEwLjcyNCw0My40NjVsLTQzLjAwOCwtMTIuMzQ2eiIvPjxwYXRoIGQ9Ik0yOTguMDQ4LDE0Mi43OWwxMC43MjQsNDMuNDY1bC00My4wMDgsLTEyLjM0NnoiLz48cGF0aCBkPSJNMjMzLjQ5MywyMDQuOTJsMTAuNzI0LDQzLjQ2NWwtNDMuMDA4LC0xMi4zNDZ6Ii8+PC9nPjwvZz48L2c+PC9zdmc+", docsURI: "https://civ3ro.github.io", blocks: [ - { blockType: "button", text: Scratch.translate("Open Three.js Documentation"), - func: "openExtra" + func: "openExtra" }, - { opcode: "reset", blockType: Scratch.BlockType.COMMAND, @@ -350,6 +348,7 @@ }, "---", + { opcode: "deleteAsset", blockType: Scratch.BlockType.COMMAND, @@ -380,7 +379,6 @@ PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "rendererGetProperties" }, }, }, - { opcode: "rendererClear", blockType: Scratch.BlockType.COMMAND, @@ -394,7 +392,6 @@ blockType: "command", text: "render", }, - { opcode: "rendererShadow", blockType: Scratch.BlockType.COMMAND, @@ -423,7 +420,9 @@ PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "sceneProperties" }, }, }, + "---", + { opcode: "color", blockType: Scratch.BlockType.REPORTER, @@ -453,8 +452,11 @@ }, "---", - {blockType: "label", - text: Scratch.translate("Objects")}, + + { + blockType: "label", + text: Scratch.translate("Objects") + }, { opcode: "addObject", @@ -473,7 +475,7 @@ text: "object [NAME] exists?", color1: "#5FAD56", arguments: { - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "object"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "object" }, } }, { @@ -531,12 +533,12 @@ arguments: { NAME: { type: "string", defaultValue: "forest" }, INDEX: { type: "number", defaultValue: 1 }, - PROPERTY: { type: "string", menu: "instanceItems"}, + PROPERTY: { type: "string", menu: "instanceItems" }, MATRIX: { type: "string", defaultValue: "[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]" }, }, }, - //BatchedMesh maybe? Reporters for all values! + //* BatchedMesh maybe? Reporters for all values! "---", @@ -558,7 +560,7 @@ color1: "#5C80BC", arguments: { OBJECT: { type: Scratch.ArgumentType.STRING, defaultValue: "object" }, - ORDER: { type: "string", menu: "XYZorder"} + ORDER: { type: "string", menu: "XYZorder" } }, }, { @@ -567,7 +569,7 @@ text: "for object [OBJECT] [ACTION] [XYZ] [TRANSFORM] to [VALUE]", color1: "#5C80BC", arguments: { - ACTION: { type: "string", menu: "actionModifier"}, + ACTION: { type: "string", menu: "actionModifier" }, XYZ: { type: Scratch.ArgumentType.STRING, menu: "XYZ" }, TRANSFORM: { type: Scratch.ArgumentType.STRING, menu: "transformType" }, OBJECT: { type: Scratch.ArgumentType.STRING, defaultValue: "object" }, @@ -587,8 +589,10 @@ "---", - {blockType: "label", - text: Scratch.translate("Vectors")}, + { + blockType: "label", + text: Scratch.translate("Vectors") + }, { opcode: "vector2", @@ -685,8 +689,10 @@ }, }, - {blockType: "label", - text: Scratch.translate("Matrix")}, + { + blockType: "label", + text: Scratch.translate("Matrix") + }, { opcode: "doMatrix", @@ -711,14 +717,16 @@ }, "---", - - {blockType: "label", - text: Scratch.translate("Models")}, + + { + blockType: "label", + text: Scratch.translate("Models") + }, { blockType: "button", text: Scratch.translate("Import model"), - func: "loadModel" + func: "loadModel" }, { opcode: "addModel", @@ -743,8 +751,10 @@ "---", - {blockType: "label", - text: Scratch.translate("Geometries")}, + { + blockType: "label", + text: Scratch.translate("Geometries") + }, { opcode: "createGeometry", @@ -762,8 +772,8 @@ text: "set geometry [NAME] [PROPERTY] to [DATA]", color1: "#7c4d5e", arguments: { - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "geometryProperties"}, - DATA: { type: Scratch.ArgumentType.STRING, defaultValue: "[-0.5,0.5,0,0.5,0.5,0,-0.5,-0.5,0,0.5,-0.5,0]"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "geometryProperties" }, + DATA: { type: Scratch.ArgumentType.STRING, defaultValue: "[-0.5,0.5,0,0.5,0.5,0,-0.5,-0.5,0,0.5,-0.5,0]" }, NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "cube" }, }, }, @@ -773,15 +783,15 @@ text: "get geometry [NAME] [PROPERTY]", color1: "#7c4d5e", arguments: { - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "geometryProperties"}, - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "cube"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "geometryProperties" }, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "cube" }, }, }, "---", { blockType: "button", text: Scratch.translate("Import font"), - func: "loadFont" + func: "loadFont" }, { opcode: "createTextGeometry", @@ -792,7 +802,7 @@ FILE: { type: "string", menu: "loadedFonts" }, NAME: { type: "string", defaultValue: "text" }, TEXT: { type: "string", defaultValue: "Cool 3D text!" }, - DEPTH: {type: "number", defaultValue: "1"} + DEPTH: { type: "number", defaultValue: "1" } }, }, { @@ -807,8 +817,10 @@ "---", - {blockType: "label", - text: Scratch.translate("Materials")}, + { + blockType: "label", + text: Scratch.translate("Materials") + }, { opcode: "createMaterial", @@ -826,8 +838,8 @@ text: "set material [NAME] [PROPERTY] to [DATA]", color1: "#694D7C", arguments: { - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "materialColorProperties"}, - DATA: { type: Scratch.ArgumentType.COLOR, defaultValue: "#ff0000"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "materialColorProperties" }, + DATA: { type: Scratch.ArgumentType.COLOR, defaultValue: "#ff0000" }, NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "red" }, }, }, @@ -837,8 +849,8 @@ text: "set material [NAME] [PROPERTY] to [DATA]", color1: "#694D7C", arguments: { - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "materialMapProperties"}, - DATA: { type: Scratch.ArgumentType.STRING, defaultValue: "sky"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "materialMapProperties" }, + DATA: { type: Scratch.ArgumentType.STRING, defaultValue: "sky" }, NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "red" }, }, }, @@ -848,8 +860,8 @@ text: "set material [NAME] [PROPERTY] to [DATA]", color1: "#694D7C", arguments: { - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "materialNumeralProperties"}, - DATA: { type: Scratch.ArgumentType.NUMBER, defaultValue: "1"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "materialNumeralProperties" }, + DATA: { type: Scratch.ArgumentType.NUMBER, defaultValue: "1" }, NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "red" }, }, }, @@ -859,8 +871,8 @@ text: "set material [NAME] [PROPERTY] to [DATA]", color1: "#694D7C", arguments: { - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "materialBooleanProperties"}, - DATA: { type: Scratch.ArgumentType.STRING, menu: "boolean"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "materialBooleanProperties" }, + DATA: { type: Scratch.ArgumentType.STRING, menu: "boolean" }, NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "red" }, }, }, @@ -870,7 +882,7 @@ text: "set material [NAME] to [DATA] side rendering", color1: "#694D7C", arguments: { - DATA: { type: Scratch.ArgumentType.STRING, menu: "materialSides"}, + DATA: { type: Scratch.ArgumentType.STRING, menu: "materialSides" }, NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "red" }, }, }, @@ -889,11 +901,11 @@ blockType: Scratch.BlockType.REPORTER, text: "join [MATERIAL] with [MATERIAL2]", arguments: { - MATERIAL: { type: Scratch.ArgumentType.STRING, defaultValue: "red"}, + MATERIAL: { type: Scratch.ArgumentType.STRING, defaultValue: "red" }, MATERIAL2: { type: Scratch.ArgumentType.STRING, defaultValue: "blue" }, }, }, - + "---", @@ -904,8 +916,8 @@ text: "load Texture from [COSTUME] as [NAME]", color1: "#694D7C", arguments: { - COSTUME: { type: Scratch.ArgumentType.COSTUME}, - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "sky"}, + COSTUME: { type: Scratch.ArgumentType.COSTUME }, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "sky" }, }, }, @@ -915,9 +927,9 @@ text: "set texture [NAME] [PROPERTY] to [VALUE]", color1: "#694D7C", arguments: { - NAME: { type: "string", defaultValue: "sky"}, - PROPERTY: { type: "string", menu: "textureProperties"}, - VALUE: { type: "string", defaultValue: "[1,1]"}, + NAME: { type: "string", defaultValue: "sky" }, + PROPERTY: { type: "string", menu: "textureProperties" }, + VALUE: { type: "string", defaultValue: "[1,1]" }, } }, { @@ -926,9 +938,9 @@ text: "set texture [NAME] wrap U [U] V [V]", color1: "#694D7C", arguments: { - NAME: { type: "string", defaultValue: "sky"}, - U: { type: "string", menu: "textureWarp"}, - V: { type: "string", menu: "textureWarp"}, + NAME: { type: "string", defaultValue: "sky" }, + U: { type: "string", menu: "textureWarp" }, + V: { type: "string", menu: "textureWarp" }, } }, { @@ -937,9 +949,9 @@ text: "set texture [NAME] filter mag [MAG] min [MIN]", color1: "#694D7C", arguments: { - NAME: { type: "string", defaultValue: "sky"}, - MAG: { type: "string", menu: "magFilter"}, - MIN: { type: "string", menu: "minFilter"}, + NAME: { type: "string", defaultValue: "sky" }, + MAG: { type: "string", menu: "magFilter" }, + MIN: { type: "string", menu: "minFilter" }, } }, { @@ -948,15 +960,17 @@ text: "set texture [NAME] mapping to [VALUE]", color1: "#694D7C", arguments: { - NAME: { type: "string", defaultValue: "sky"}, - VALUE: { type: "string", menu: "textureMapping"}, + NAME: { type: "string", defaultValue: "sky" }, + VALUE: { type: "string", menu: "textureMapping" }, } }, "---", - {blockType: "label", - text: Scratch.translate("Camera")}, + { + blockType: "label", + text: Scratch.translate("Camera") + }, { opcode: "camera", @@ -972,8 +986,8 @@ color1: "#5FAD56", arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "camera" }, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "cameraProperties"}, - VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "90"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "cameraProperties" }, + VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "90" }, } }, { @@ -983,7 +997,7 @@ color1: "#5FAD56", arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "camera" }, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "cameraProperties"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "cameraProperties" }, } }, @@ -999,8 +1013,10 @@ "---", - {blockType: "label", - text: Scratch.translate("Lights")}, + { + blockType: "label", + text: Scratch.translate("Lights") + }, { opcode: "setLight", @@ -1009,8 +1025,8 @@ color1: "#5FAD56", arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "light" }, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "light"}, - VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "1"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "light" }, + VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "1" }, } }, { @@ -1020,8 +1036,8 @@ color1: "#5FAD56", arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "light" }, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "lightColors"}, - VALUE: { type: Scratch.ArgumentType.COLOR}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "lightColors" }, + VALUE: { type: Scratch.ArgumentType.COLOR }, } }, { @@ -1031,8 +1047,8 @@ color1: "#5FAD56", arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "light" }, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "lightStrings"}, - VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "batsignal"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "lightStrings" }, + VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "batsignal" }, } }, { @@ -1042,7 +1058,7 @@ color1: "#5FAD56", arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "light" }, - VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "[0,0,0]"}, + VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "[0,0,0]" }, } }, { @@ -1052,7 +1068,7 @@ color1: "#5FAD56", arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "light" }, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "lightGetter"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "lightGetter" }, } }, { @@ -1062,30 +1078,34 @@ color1: "#5FAD56", arguments: { NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "light" }, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "lightShadow"}, - VALUE: { type: Scratch.ArgumentType.NUMBER, defaultValue: "10"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "lightShadow" }, + VALUE: { type: Scratch.ArgumentType.NUMBER, defaultValue: "10" }, } }, "---", - {blockType: "label", - text: Scratch.translate("Sensing")}, - //is there a way to subdivide the bounding box into multiple ones for more precicion? + { + blockType: "label", + text: Scratch.translate("Sensing") + }, + //is there a way to subdivide the bounding box into multiple ones for more precicion? { opcode: "touching", blockType: Scratch.BlockType.BOOLEAN, text: "is [A] touching [B]?", arguments: { A: { type: Scratch.ArgumentType.STRING, defaultValue: "object" }, - B: { type: Scratch.ArgumentType.STRING, defaultValue: "ground"} + B: { type: Scratch.ArgumentType.STRING, defaultValue: "ground" } } }, "---", - - {blockType: "label", - text: Scratch.translate("Audio")}, + + { + blockType: "label", + text: Scratch.translate("Audio") + }, { opcode: "loadAudio", blockType: Scratch.BlockType.COMMAND, @@ -1093,17 +1113,17 @@ color1: "#5FAD56", arguments: { FILE: { type: Scratch.ArgumentType.SOUND }, - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz" }, } }, { opcode: "addAudio", blockType: Scratch.BlockType.COMMAND, - text: "add audio [NAME] to [PARENT]", + text: "add audio [NAME] to [PARENT]", color1: "#5FAD56", arguments: { - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz"}, - PARENT: { type: Scratch.ArgumentType.STRING, defaultValue: "bird"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz" }, + PARENT: { type: Scratch.ArgumentType.STRING, defaultValue: "bird" }, } }, { @@ -1112,8 +1132,8 @@ text: "for audio [NAME] [PROPERTY]", color1: "#5FAD56", arguments: { - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz"}, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "audioPlayback"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz" }, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "audioPlayback" }, } }, { @@ -1122,8 +1142,8 @@ text: "set audio [NAME] [PROPERTY] to [DATA]", color1: "#5FAD56", arguments: { - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz"}, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "audioNumeral"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz" }, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "audioNumeral" }, DATA: { type: Scratch.ArgumentType.NUMBER, defaultValue: "1" } } }, @@ -1133,8 +1153,8 @@ text: "set audio [NAME] [PROPERTY] [DATA]", color1: "#5FAD56", arguments: { - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz"}, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "audioBoolean"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz" }, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "audioBoolean" }, DATA: { type: Scratch.ArgumentType.NUMBER, menu: "boolean" } } }, @@ -1144,8 +1164,8 @@ text: "get audio [NAME] [PROPERTY]", color1: "#5FAD56", arguments: { - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz"}, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "audioGetter"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz" }, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "audioGetter" }, } }, { @@ -1154,30 +1174,32 @@ text: "is audio [NAME] [PROPERTY]", color1: "#5FAD56", arguments: { - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz"}, - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "isAudio"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "Whiz" }, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "isAudio" }, } }, { opcode: "stopAllAudios", blockType: "command", text: "stop all 3D audios", - color1: "#C84630", + color1: "#C84630", }, "---", - {blockType: "label", - text: Scratch.translate("Raycast")}, + { + blockType: "label", + text: Scratch.translate("Raycast") + }, { opcode: "raycast", blockType: Scratch.BlockType.COMMAND, text: "raycast from [V] in direction [D] [ORDER]", arguments: { - V: { type: Scratch.ArgumentType.STRING, defaultValue: "[0,0,0]"}, - D: { type: Scratch.ArgumentType.STRING, defaultValue: "[0,0,0]"}, - ORDER: { type: Scratch.ArgumentType.STRING, menu: "XYZorder"}, + V: { type: Scratch.ArgumentType.STRING, defaultValue: "[0,0,0]" }, + D: { type: Scratch.ArgumentType.STRING, defaultValue: "[0,0,0]" }, + ORDER: { type: Scratch.ArgumentType.STRING, menu: "XYZorder" }, } }, { @@ -1185,7 +1207,7 @@ blockType: Scratch.BlockType.COMMAND, text: "raycast from camera, mouse position [XY]", arguments: { - XY: { type: Scratch.ArgumentType.NUMBER, defaultValue: "[0,0]"}, + XY: { type: Scratch.ArgumentType.NUMBER, defaultValue: "[0,0]" }, } }, { @@ -1193,7 +1215,7 @@ blockType: Scratch.BlockType.REPORTER, text: "get raycast [PROPERTY]", arguments: { - PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "raycast"}, + PROPERTY: { type: Scratch.ArgumentType.STRING, menu: "raycast" }, } }, { @@ -1201,419 +1223,505 @@ blockType: Scratch.BlockType.BOOLEAN, text: "is raycast touching [NAME]", arguments: { - NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "object"}, + NAME: { type: Scratch.ArgumentType.STRING, defaultValue: "object" }, } }, "---", - {blockType: "label", - text: Scratch.translate("Addons")}, + { + blockType: "label", + text: Scratch.translate("Addons") + }, { opcode: "orbitControls", blockType: Scratch.BlockType.COMMAND, text: "OrbitControls [MODE]", arguments: { - MODE: { type: Scratch.ArgumentType.STRING, menu: "boolean"}, + MODE: { type: Scratch.ArgumentType.STRING, menu: "boolean" }, } }, - + "---", - {blockType: "label", - text: Scratch.translate(`Physics, VR, Sky & Water, Postprocesing, +Addons (separate future extensions)`)}, + { + blockType: "label", + text: Scratch.translate(`Physics, VR, Sky & Water, Postprocesing, +Addons (separate future extensions)`) + }, "---", ], menus: { - + XYZ: { items: ["x", "y", "z"] }, XYZorder: { acceptReporters: true, items: ["XYZ", "YXZ", "XZY", "ZYX", "YZX", "ZXY"] }, - actionModifier: { items: [ - {text: Scratch.translate("set"), value: "set"}, - {text: Scratch.translate("change"), value: "change"}, - ]}, - boolean: { acceptReporters: true, items: ["true", "false"]}, - vectorOperations: { items: [ - { text: Scratch.translate("Floor"), value: "floor" }, - { text: Scratch.translate("Ceiling"), value: "ceil" }, - { text: Scratch.translate("Round"), value: "round" }, - { text: Scratch.translate("Round To Zero"), value: "roundToZero" }, - { text: Scratch.translate("Negate"), value: "negate" }, - { text: Scratch.translate("Length Sq"), value: "lengthSq" }, - { text: Scratch.translate("Length"), value: "length" }, - { text: Scratch.translate("Manhattan Length"), value: "manhattanLength" }, - { text: Scratch.translate("Normalize"), value: "normalize" }, - { text: Scratch.translate("Random"), value: "randomDirection" }, - ]}, - vector2Operations: { items: [ - { text: Scratch.translate("+"), value: "add" }, - { text: Scratch.translate("+ Scalar"), value: "addScalar" }, - { text: Scratch.translate("-"), value: "sub" }, - { text: Scratch.translate("- Scalar"), value: "subScalar" }, - { text: Scratch.translate("*"), value: "multiply" }, - { text: Scratch.translate("* Scalar"), value: "multiplyScalar" }, - { text: Scratch.translate("/"), value: "divide" }, - { text: Scratch.translate("/ Scalar"), value: "divideScalar" }, - { text: Scratch.translate("="), value: "equals" }, - { text: Scratch.translate("Distance To"), value: "distanceTo" }, - { text: Scratch.translate("Distance To Squared"), value: "distanceToSquared" }, - { text: Scratch.translate("Manhattan Distance To"), value: "manhattanDistanceTo" }, - { text: Scratch.translate("Angle To"), value: "angleTo" }, - { text: Scratch.translate("Cross"), value: "cross" }, - { text: Scratch.translate("Apply Euler"), value: "applyEuler" }, - { text: Scratch.translate("Dot"), value: "dot" }, - { text: Scratch.translate("Min"), value: "min" }, - { text: Scratch.translate("Max"), value: "max" }, - { text: Scratch.translate("Project On Vector"), value: "projectOnVector" }, - { text: Scratch.translate("Project On Plane"), value: "projectOnPlane" }, - { text: Scratch.translate("Reflect"), value: "reflect" } - ]}, - assetType: { items: [ - {text: Scratch.translate("object"), value: "objects"}, - {text: Scratch.translate("geometry"), value: "geometries"}, - {text: Scratch.translate("material"), value: "materials"}, - {text: Scratch.translate("texture"), value: "textures"}, - {text: Scratch.translate("audios"), value: "audios"}, - ]}, + actionModifier: { + items: [ + { text: Scratch.translate("set"), value: "set" }, + { text: Scratch.translate("change"), value: "change" }, + ] + }, + boolean: { acceptReporters: true, items: ["true", "false"] }, + vectorOperations: { + items: [ + { text: Scratch.translate("Floor"), value: "floor" }, + { text: Scratch.translate("Ceiling"), value: "ceil" }, + { text: Scratch.translate("Round"), value: "round" }, + { text: Scratch.translate("Round To Zero"), value: "roundToZero" }, + { text: Scratch.translate("Negate"), value: "negate" }, + { text: Scratch.translate("Length Sq"), value: "lengthSq" }, + { text: Scratch.translate("Length"), value: "length" }, + { text: Scratch.translate("Manhattan Length"), value: "manhattanLength" }, + { text: Scratch.translate("Normalize"), value: "normalize" }, + { text: Scratch.translate("Random"), value: "randomDirection" }, + ] + }, + vector2Operations: { + items: [ + { text: Scratch.translate("+"), value: "add" }, + { text: Scratch.translate("+ Scalar"), value: "addScalar" }, + { text: Scratch.translate("-"), value: "sub" }, + { text: Scratch.translate("- Scalar"), value: "subScalar" }, + { text: Scratch.translate("*"), value: "multiply" }, + { text: Scratch.translate("* Scalar"), value: "multiplyScalar" }, + { text: Scratch.translate("/"), value: "divide" }, + { text: Scratch.translate("/ Scalar"), value: "divideScalar" }, + { text: Scratch.translate("="), value: "equals" }, + { text: Scratch.translate("Distance To"), value: "distanceTo" }, + { text: Scratch.translate("Distance To Squared"), value: "distanceToSquared" }, + { text: Scratch.translate("Manhattan Distance To"), value: "manhattanDistanceTo" }, + { text: Scratch.translate("Angle To"), value: "angleTo" }, + { text: Scratch.translate("Cross"), value: "cross" }, + { text: Scratch.translate("Apply Euler"), value: "applyEuler" }, + { text: Scratch.translate("Dot"), value: "dot" }, + { text: Scratch.translate("Min"), value: "min" }, + { text: Scratch.translate("Max"), value: "max" }, + { text: Scratch.translate("Project On Vector"), value: "projectOnVector" }, + { text: Scratch.translate("Project On Plane"), value: "projectOnPlane" }, + { text: Scratch.translate("Reflect"), value: "reflect" } + ] + }, + assetType: { + items: [ + { text: Scratch.translate("object"), value: "objects" }, + { text: Scratch.translate("geometry"), value: "geometries" }, + { text: Scratch.translate("material"), value: "materials" }, + { text: Scratch.translate("texture"), value: "textures" }, + { text: Scratch.translate("audios"), value: "audios" }, + ] + }, transformType: { items: [ - {text: Scratch.translate("position"), value: "position"}, - {text: Scratch.translate("rotation"), value: "rotation"}, - {text: Scratch.translate("scale"), value: "scale"}, + { text: Scratch.translate("position"), value: "position" }, + { text: Scratch.translate("rotation"), value: "rotation" }, + { text: Scratch.translate("scale"), value: "scale" }, ] }, gettransformType: { items: [ - {text: Scratch.translate("position"), value: "position"}, - {text: Scratch.translate("rotation"), value: "rotation"}, - {text: Scratch.translate("scale"), value: "scale"}, - {text: Scratch.translate("World position"), value: "getWorldPosition"}, - {text: Scratch.translate("World rotation"), value: "getWorldDirection"}, - {text: Scratch.translate("World matrix"), value: "matrixWorld"}, - {text: Scratch.translate("Local matrix"), value: "matrix"}, + { text: Scratch.translate("position"), value: "position" }, + { text: Scratch.translate("rotation"), value: "rotation" }, + { text: Scratch.translate("scale"), value: "scale" }, + { text: Scratch.translate("World position"), value: "getWorldPosition" }, + { text: Scratch.translate("World rotation"), value: "getWorldDirection" }, + { text: Scratch.translate("World matrix"), value: "matrixWorld" }, + { text: Scratch.translate("Local matrix"), value: "matrix" }, ] }, objectType: { items: [ - {text: Scratch.translate("Mesh"), value: "Mesh"}, - {text: Scratch.translate("Instanced Mesh"), value: "InstancedMesh"}, - {text: Scratch.translate("Group"), value: "Group"}, - {text: Scratch.translate("Sprite"), value: "Sprite"}, - - {text: Scratch.translate("Points"), value: "Points"}, - - {text: Scratch.translate("Line"), value: "Line"}, - {text: Scratch.translate("Line Loop"), value: "LineLoop"}, - {text: Scratch.translate("Line Segments"), value: "LineSegments"}, - - {text: Scratch.translate("Ambient Light"), value: "AmbientLight"}, - {text: Scratch.translate("Point Light"), value: "PointLight"}, - {text: Scratch.translate("Directional Light"), value: "DirectionalLight"}, - {text: Scratch.translate("Hemisphere Light"), value: "HemisphereLight"}, - {text: Scratch.translate("Spot Light"), value: "SpotLight"}, - {text: Scratch.translate("Rectangular Area Light"), value: "RectAreaLight"}, - - {text: Scratch.translate("Perspective Camera"), value: "PerspectiveCamera"}, - {text: Scratch.translate("Orthographic Camera"), value: "OrthographicCamera"}, + { text: Scratch.translate("Mesh"), value: "Mesh" }, + { text: Scratch.translate("Instanced Mesh"), value: "InstancedMesh" }, + { text: Scratch.translate("Group"), value: "Group" }, + { text: Scratch.translate("Sprite"), value: "Sprite" }, + + { text: Scratch.translate("Points"), value: "Points" }, + + { text: Scratch.translate("Line"), value: "Line" }, + { text: Scratch.translate("Line Loop"), value: "LineLoop" }, + { text: Scratch.translate("Line Segments"), value: "LineSegments" }, + + { text: Scratch.translate("Ambient Light"), value: "AmbientLight" }, + { text: Scratch.translate("Point Light"), value: "PointLight" }, + { text: Scratch.translate("Directional Light"), value: "DirectionalLight" }, + { text: Scratch.translate("Hemisphere Light"), value: "HemisphereLight" }, + { text: Scratch.translate("Spot Light"), value: "SpotLight" }, + { text: Scratch.translate("Rectangular Area Light"), value: "RectAreaLight" }, + + { text: Scratch.translate("Perspective Camera"), value: "PerspectiveCamera" }, + { text: Scratch.translate("Orthographic Camera"), value: "OrthographicCamera" }, //{text: Scratch.translate("Cube Camera"), value: "CubeCamera"}, ] }, - meshProperties: { items: [ - { text: Scratch.translate("Geometry"), value: "geometry" }, - { text: Scratch.translate("Material"), value: "material" }, - ]}, - meshBoolProperties: {items: [ - { text: Scratch.translate("Cast Shadow"), value: "castShadow" }, - { text: Scratch.translate("Receive Shadow"), value: "receiveShadow" }, - { text: Scratch.translate("Visible"), value: "visible" }, - ]}, - cameraProperties: { items: [ - { text: Scratch.translate("Fov"), value: "fov" }, - { text: Scratch.translate("Near"), value: "near" }, - { text: Scratch.translate("Far"), value: "far" }, - { text: Scratch.translate("Zoom"), value: "zoom" } - ]}, - geometryType: { items: [ - { text: Scratch.translate("Empty"), value: "BufferGeometry" }, - { text: Scratch.translate("Cube"), value: "BoxGeometry" }, - { text: Scratch.translate("Capsule"), value: "CapsuleGeometry" }, - { text: Scratch.translate("Circle"), value: "CircleGeometry" }, - { text: Scratch.translate("Cone"), value: "ConeGeometry" }, - { text: Scratch.translate("Cylinder"), value: "CylinderGeometry" }, - { text: Scratch.translate("Dodecahedron"), value: "DodecahedronGeometry" }, - { text: Scratch.translate("Icosahedron"), value: "IcosahedronGeometry" }, - { text: Scratch.translate("Octahedron"), value: "OctahedronGeometry" }, - { text: Scratch.translate("Plane"), value: "PlaneGeometry" }, - { text: Scratch.translate("Sphere"), value: "SphereGeometry" }, - { text: Scratch.translate("Tetrahedron"), value: "TetrahedronGeometry" }, - { text: Scratch.translate("Torus"), value: "TorusGeometry" }, - { text: Scratch.translate("Torus Knot"), value: "TorusKnotGeometry" } - ]}, - geometryProperties: { items: [ - { text: Scratch.translate("Vertex Points [XYZ]"), value: "position" }, - { text: Scratch.translate("Texture Points [UV]"), value: "uv" }, - { text: Scratch.translate("Face Points (Normals) [XYZ]"), value: "normal" } - ]}, - materialType: { items: [ - {text: Scratch.translate("Mesh Basic"), value: "MeshBasicMaterial"}, - {text: Scratch.translate("Mesh Standard"), value: "MeshStandardMaterial"}, - {text: Scratch.translate("Mesh Normal"), value: "MeshNormalMaterial"}, - {text: Scratch.translate("Mesh Toon"), value: "MeshToonMaterial"}, - {text: Scratch.translate("Mesh Depth"), value: "MeshDepthMaterial"}, - {text: Scratch.translate("Mesh Physical"), value: "MeshPhysicalMaterial"}, - {text: Scratch.translate("Mesh Phong"), value: "MeshPhongMaterial"}, - {text: Scratch.translate("Mesh Lambert"), value: "MeshLambertMaterial"}, - {text: Scratch.translate("Mesh Matcap"), value: "MeshMatcapMaterial"}, - - {text: Scratch.translate("Line Basic"), value: "LineBasicMaterial"}, - {text: Scratch.translate("Line Dashed"), value: "LineDashedMaterial"}, - - {text: Scratch.translate("Points"), value: "PointsMaterial"}, - - {text: Scratch.translate("Sprite"), value: "SpriteMaterial"}, - - {text: Scratch.translate("Shadow"), value: "ShadowMaterial"}, - ]}, - materialNumeralProperties: { items: [ - { text: Scratch.translate("Opacity"), value: "opacity" }, - { text: Scratch.translate("Alpha Test"), value: "alphaTest" }, - { text: Scratch.translate("Roughness"), value: "roughness" }, - { text: Scratch.translate("Metalness"), value: "metalness" }, - { text: Scratch.translate("Emissive Intensity"), value: "emissiveIntensity" }, - { text: Scratch.translate("Reflectivity"), value: "reflectivity" }, - { text: Scratch.translate("Shininess"), value: "shininess" }, - { text: Scratch.translate("Transmission"), value: "transmission" }, - { text: Scratch.translate("Thickness"), value: "thickness" }, - { text: Scratch.translate("Refraction Ratio"), value: "refractionRatio" }, - { text: Scratch.translate("Polygon Offset Factor"), value: "polygonOffsetFactor" }, - { text: Scratch.translate("Polygon Offset Units"), value: "polygonOffsetUnits" }, - { text: Scratch.translate("Wireframe width"), value: "wireframeLinewidth" }, - { text: Scratch.translate("Points: Size"), value: "wireframeLinewidth" }, - ]}, - materialBooleanProperties: { items: [ - { text: Scratch.translate("Visible"), value: "visible" }, - { text: Scratch.translate("Transparent"), value: "transparent" }, - { text: Scratch.translate("Wireframe"), value: "wireframe" }, - { text: Scratch.translate("Fog"), value: "fog" }, - { text: Scratch.translate("Allow Override Material"), value: "allowOverride" }, - { text: Scratch.translate("Depth Test"), value: "depthTest" }, - { text: Scratch.translate("Depth Write"), value: "depthWrite" }, - { text: Scratch.translate("Color Write"), value: "colorWrite" }, - { text: Scratch.translate("Flat Shading"), value: "flatShading" }, - { text: Scratch.translate("Vertex Colors"), value: "vertexColors" }, - { text: Scratch.translate("Tone Mapped"), value: "toneMapped" }, - { text: Scratch.translate("Alpha Hash"), value: "alphaHash" }, - { text: Scratch.translate("Dithering"), value: "dithering" }, - { text: Scratch.translate("Polygon Offset"), value: "polygonOffset" } - ]}, - materialColorProperties: { items: [ - { text: Scratch.translate("Color"), value: "color" }, - { text: Scratch.translate("Emissive"), value: "emissive" }, - { text: Scratch.translate("Specular"), value: "specular" }, - { text: Scratch.translate("Sheen"), value: "sheen" } - ]}, - materialMapProperties: { items: [ - { text: Scratch.translate("Texture"), value: "map" }, - { text: Scratch.translate("Alpha Texture"), value: "alphaMap" }, - { text: Scratch.translate("Normal Texture"), value: "normalMap" }, - { text: Scratch.translate("Roughness Texture"), value: "roughnessMap" }, - { text: Scratch.translate("Metalness Texture"), value: "metalnessMap" }, - { text: Scratch.translate("Emissive Texture"), value: "emissiveMap" }, - { text: Scratch.translate("Environment Texture"), value: "envMap" }, - { text: Scratch.translate("Ambient Occlusion Texture"), value: "aoMap" }, - { text: Scratch.translate("Bump Texture"), value: "bumpMap" }, - { text: Scratch.translate("Displacement Texture"), value: "displacementMap" } - ]}, - materialSides: { items: [ - { text: Scratch.translate("Front"), value: "0" }, - { text: Scratch.translate("Back"), value: "1" }, - { text: Scratch.translate("Double"), value: "2" }, - ]}, - textureProperties: { items: [ - { text: Scratch.translate("Repeat (V2)"), value: "repeat" }, - { text: Scratch.translate("Center (V2)"), value: "center" }, - { text: Scratch.translate("Offset (V2)"), value: "offset" }, - { text: Scratch.translate("Anisotropy (Number)"), value: "anisotropy" }, - { text: Scratch.translate("Rotation (Number)"), value: "rotation" }, - { text: Scratch.translate("Premultiply Alpha (Boolean)"), value: "premultiplyAlpha" }, - ]}, - textureWarp: { items: [ - { text: Scratch.translate("Repeat Wrapping"), value: "1000" }, - { text: Scratch.translate("Clamp To Edge Wrapping"), value: "1001" }, - { text: Scratch.translate("Mirrored Repeat Wrapping"), value: "1002" }, - ]}, - textureMapping: { items: [ - { text: Scratch.translate("UV (Standard)"), value: "300" }, - //{ text: Scratch.translate("Cube Reflection (6 images?)"), value: "301" }, - //{ text: Scratch.translate("Cube Refraction (6 images?)"), value: "302" }, - //{ text: Scratch.translate("Equirectangular Reflection (no diference)"), value: "303" }, - { text: Scratch.translate("Equirectangular"), value: "304" }, - //{ text: Scratch.translate("Cube UV Reflection (errors)"), value: "306" } - ]}, - magFilter: { items: [ - { text: Scratch.translate("Linear Filter (Blurred)"), value: "LinearFilter" }, - { text: Scratch.translate("Nearest Filter (Pixelated)"), value: "NearestFilter" } - ]}, - minFilter: { items: [ - { text: Scratch.translate("Linear Filter"), value: "LinearFilter" }, - { text: Scratch.translate("Linear Mipmap Linear Filter"), value: "LinearMipmapLinearFilter" }, - { text: Scratch.translate("Linear Mipmap Nearest Filter"), value: "LinearMipmapNearestFilter" }, - { text: Scratch.translate("Nearest Filter"), value: "NearestFilter" }, - { text: Scratch.translate("Nearest Mipmap Linear Filter"), value: "NearestMipmapLinearFilter" }, - { text: Scratch.translate("Nearest Mipmap Nearest Filter"), value: "NearestMipmapNearestFilter" } - ]}, - rendererProperties: { items: [ - { text: Scratch.translate("Render Scene Automatically"), value: "autoRender" }, - { text: Scratch.translate("Clear All Automatically"), value: "autoClear" }, - { text: Scratch.translate("Clear Color Automatically"), value: "autoClearColor" }, - { text: Scratch.translate("Clear Depth Automatically"), value: "autoClearDepth" }, - { text: Scratch.translate("Shadows enabled"), value: "shadowMap.enabled" }, - ] }, - rendererGetProperties: {items: [ - { text: Scratch.translate("Render Scene Automatically"), value: "autoRender" }, - { text: Scratch.translate("Clear All Automatically"), value: "autoClear" }, - { text: Scratch.translate("Clear Color Automatically"), value: "autoClearColor" }, - { text: Scratch.translate("Clear Depth Automatically"), value: "autoClearDepth" }, - { text: Scratch.translate("Shadows enabled"), value: "shadowMap.enabled" }, - ]}, - shadowMapTypes: {items: [ - { text: Scratch.translate("Basic (Fastest)"), value: "0" }, - { text: Scratch.translate("Smooth (Default)"), value: "1" }, - { text: Scratch.translate("Expensive"), value: "2" }, - { text: Scratch.translate("Fabulous (Slowest)"), value: "3" }, - ]}, - clearBuffers: { items: [ - { text: Scratch.translate("All"), value: "clear" }, - { text: Scratch.translate("Color"), value: "clearColor" }, - { text: Scratch.translate("Depth"), value: "clearDepth" } - ]}, - sceneProperties: {items: [ - { text: Scratch.translate("Background"), value: "background" }, - { text: Scratch.translate("Background Blurriness"), value: "backgroundBlurriness" }, - { text: Scratch.translate("Background Intensity"), value: "backgroundIntensity" }, - { text: Scratch.translate("Background Rotation"), value: "backgroundRotation" }, - - { text: Scratch.translate("Environment"), value: "environment" }, - { text: Scratch.translate("Environment Intensity"), value: "environmentIntensity" }, - { text: Scratch.translate("Environment Rotation"), value: "environmentRotation" }, - - { text: Scratch.translate("Fog"), value: "fog" }, - - { text: Scratch.translate("Override Material"), value: "overrideMaterial" } - ]}, - light: { items: [ - { text: Scratch.translate("Intensity"), value: "intensity" }, - { text: Scratch.translate("Point, Spot: Distance"), value: "distance" }, - { text: Scratch.translate("Point, Spot: Decay"), value: "decay" }, - { text: Scratch.translate("Point, Spot, Rectangular: Power"), value: "power" }, - { text: Scratch.translate("Spot: Angle"), value: "angle" }, - { text: Scratch.translate("Spot: Penumbra"), value: "penumbra" }, - { text: Scratch.translate("Rectangular: Width"), value: "width" }, - { text: Scratch.translate("Rectangular: Height"), value: "height" }, - ]}, - lightColors: {items: [ - { text: Scratch.translate("Color"), value: "color" }, - { text: Scratch.translate("Hemisphere: Sky Color"), value: "skyColor" }, - { text: Scratch.translate("Hemisphere: Ground Color"), value: "groundColor" }, - ]}, - lightStrings: {items: [ - { text: Scratch.translate("Spot: Texture"), value: "map" }, - ]}, - lightGetter: {items: [ - { text: Scratch.translate("Intensity"), value: "intensity" }, - { text: Scratch.translate("Color"), value: "color" }, - { text: Scratch.translate("Distance"), value: "distance" }, - { text: Scratch.translate("Decay"), value: "decay" }, - { text: Scratch.translate("Angle"), value: "angle" }, - { text: Scratch.translate("Penumbra"), value: "penumbra" }, - { text: Scratch.translate("Power"), value: "power" }, - { text: Scratch.translate("width"), value: "width" }, - { text: Scratch.translate("height"), value: "height" } - ]}, - lightShadow: {items: [ - { text: Scratch.translate("Scale"), value: "scale" }, - { text: Scratch.translate("Blur"), value: "radius" }, - { text: Scratch.translate("Instensity"), value: "intensity" } - ]}, - instanceItems: { items: [ - { text: Scratch.translate("matrix"), value: "matrix" }, - { text: Scratch.translate("color"), value: "color" }, - ]}, - reset: {items: [ - {text: Scratch.translate("everything"), value: "everything"}, - {text: Scratch.translate("objects"), value: "objects"}, - {text: Scratch.translate("geometries"), value: "geometries"}, - {text: Scratch.translate("materials"), value: "materials"}, - {text: Scratch.translate("textures"), value: "textures"}, - {text: Scratch.translate("audios"), value: "audios"}, - ]}, - stats: {items: [ - {text: Scratch.translate("memory"), value: "memory"}, - {text: Scratch.translate("render"), value: "render"}, - ]}, - audioNumeral: {items: [ - { text: Scratch.translate("Volume"), value: "setVolume" }, - { text: Scratch.translate("Speed"), value: "setPlaybackRate" }, - { text: Scratch.translate("Detune"), value: "setDetune" }, - { text: Scratch.translate("Volume Drop Distance (0.01-x)"), value: "setRefDistance" }, - { text: Scratch.translate("Max Distance"), value: "setMaxDistance" }, - { text: Scratch.translate("Fade Factor"), value: "setRolloffFactor" }, - //{ text: Scratch.translate("Loop start (seconds)"), value: "setLoopStart" }, - //{ text: Scratch.translate("Loop end (seconds)"), value: "setLoopEnd" }, - { text: Scratch.translate("Offset"), value: "offset" }, - ]}, - audioBoolean: {items: [ - //{ text: Scratch.translate("Autoplay"), value: "autoplay" }, - { text: Scratch.translate("Loop"), value: "setLoop" }, - ]}, - audioPlayback: {items: [ - { text: Scratch.translate("Play/Resume"), value: "play" }, - { text: Scratch.translate("Stop"), value: "stop" }, - { text: Scratch.translate("Pause"), value: "pause" }, - ]}, - isAudio: {items: [ - { text: Scratch.translate("playing"), value: "isPlaying" }, - { text: Scratch.translate("looping"), value: "loop" }, - ]}, - audioGetter: {items: [ - { text: Scratch.translate("Volume"), value: "getVolume" }, - { text: Scratch.translate("Detune"), value: "getDetune" }, - { text: Scratch.translate("Speed"), value: "getPlaybackRate" }, - { text: Scratch.translate("Max Distance"), value: "getMaxDistance" }, - { text: Scratch.translate("Volume Drop Distance"), value: "getRefDistance" }, - { text: Scratch.translate("Fade Factor"), value: "getRolloffFactor" }, - ]}, - raycast: {items: [ - { text: Scratch.translate("Distance"), value: "distance" }, - { text: Scratch.translate("Object"), value: "object" }, - { text: Scratch.translate("Point world coordinates"), value: "point" }, - { text: Scratch.translate("Normal"), value: "normal" }, - { text: Scratch.translate("InstancedMesh: Instance Id"), value: "instanceId" }, - ]}, - loadedModels: {items: () => { - const s = runtime.extensionStorage[extensionID] || null; - if (!s) {initStorage(); return [["waiting to load..."]];} - const m = s.models; - if (!m) {s.models = {}; m = {};} - if (Object.keys(m).length == 0) return [["Load a model!"]]; - return [Object.keys(m)]; - }}, - loadedFonts: {items: () => { - const s = runtime.extensionStorage[extensionID] || null; - if (!s) {initStorage(); return [["waiting to load..."]];} - const m = s.fonts; - if (!m) {s.fonts = {}; m = {};} - if (Object.keys(m).length == 0) return [["Load a font!"]]; - return [Object.keys(m)]; - }}, + meshProperties: { + items: [ + { text: Scratch.translate("Geometry"), value: "geometry" }, + { text: Scratch.translate("Material"), value: "material" }, + ] + }, + meshBoolProperties: { + items: [ + { text: Scratch.translate("Cast Shadow"), value: "castShadow" }, + { text: Scratch.translate("Receive Shadow"), value: "receiveShadow" }, + { text: Scratch.translate("Visible"), value: "visible" }, + ] + }, + cameraProperties: { + items: [ + { text: Scratch.translate("Fov"), value: "fov" }, + { text: Scratch.translate("Near"), value: "near" }, + { text: Scratch.translate("Far"), value: "far" }, + { text: Scratch.translate("Zoom"), value: "zoom" } + ] + }, + geometryType: { + items: [ + { text: Scratch.translate("Empty"), value: "BufferGeometry" }, + { text: Scratch.translate("Cube"), value: "BoxGeometry" }, + { text: Scratch.translate("Capsule"), value: "CapsuleGeometry" }, + { text: Scratch.translate("Circle"), value: "CircleGeometry" }, + { text: Scratch.translate("Cone"), value: "ConeGeometry" }, + { text: Scratch.translate("Cylinder"), value: "CylinderGeometry" }, + { text: Scratch.translate("Dodecahedron"), value: "DodecahedronGeometry" }, + { text: Scratch.translate("Icosahedron"), value: "IcosahedronGeometry" }, + { text: Scratch.translate("Octahedron"), value: "OctahedronGeometry" }, + { text: Scratch.translate("Plane"), value: "PlaneGeometry" }, + { text: Scratch.translate("Sphere"), value: "SphereGeometry" }, + { text: Scratch.translate("Tetrahedron"), value: "TetrahedronGeometry" }, + { text: Scratch.translate("Torus"), value: "TorusGeometry" }, + { text: Scratch.translate("Torus Knot"), value: "TorusKnotGeometry" } + ] + }, + geometryProperties: { + items: [ + { text: Scratch.translate("Vertex Points [XYZ]"), value: "position" }, + { text: Scratch.translate("Texture Points [UV]"), value: "uv" }, + { text: Scratch.translate("Face Points (Normals) [XYZ]"), value: "normal" } + ] + }, + materialType: { + items: [ + { text: Scratch.translate("Mesh Basic"), value: "MeshBasicMaterial" }, + { text: Scratch.translate("Mesh Standard"), value: "MeshStandardMaterial" }, + { text: Scratch.translate("Mesh Normal"), value: "MeshNormalMaterial" }, + { text: Scratch.translate("Mesh Toon"), value: "MeshToonMaterial" }, + { text: Scratch.translate("Mesh Depth"), value: "MeshDepthMaterial" }, + { text: Scratch.translate("Mesh Physical"), value: "MeshPhysicalMaterial" }, + { text: Scratch.translate("Mesh Phong"), value: "MeshPhongMaterial" }, + { text: Scratch.translate("Mesh Lambert"), value: "MeshLambertMaterial" }, + { text: Scratch.translate("Mesh Matcap"), value: "MeshMatcapMaterial" }, + + { text: Scratch.translate("Line Basic"), value: "LineBasicMaterial" }, + { text: Scratch.translate("Line Dashed"), value: "LineDashedMaterial" }, + + { text: Scratch.translate("Points"), value: "PointsMaterial" }, + + { text: Scratch.translate("Sprite"), value: "SpriteMaterial" }, + + { text: Scratch.translate("Shadow"), value: "ShadowMaterial" }, + ] + }, + materialNumeralProperties: { + items: [ + { text: Scratch.translate("Opacity"), value: "opacity" }, + { text: Scratch.translate("Alpha Test"), value: "alphaTest" }, + { text: Scratch.translate("Roughness"), value: "roughness" }, + { text: Scratch.translate("Metalness"), value: "metalness" }, + { text: Scratch.translate("Emissive Intensity"), value: "emissiveIntensity" }, + { text: Scratch.translate("Reflectivity"), value: "reflectivity" }, + { text: Scratch.translate("Shininess"), value: "shininess" }, + { text: Scratch.translate("Transmission"), value: "transmission" }, + { text: Scratch.translate("Thickness"), value: "thickness" }, + { text: Scratch.translate("Refraction Ratio"), value: "refractionRatio" }, + { text: Scratch.translate("Polygon Offset Factor"), value: "polygonOffsetFactor" }, + { text: Scratch.translate("Polygon Offset Units"), value: "polygonOffsetUnits" }, + { text: Scratch.translate("Wireframe width"), value: "wireframeLinewidth" }, + { text: Scratch.translate("Points: Size"), value: "wireframeLinewidth" }, + ] + }, + materialBooleanProperties: { + items: [ + { text: Scratch.translate("Visible"), value: "visible" }, + { text: Scratch.translate("Transparent"), value: "transparent" }, + { text: Scratch.translate("Wireframe"), value: "wireframe" }, + { text: Scratch.translate("Fog"), value: "fog" }, + { text: Scratch.translate("Allow Override Material"), value: "allowOverride" }, + { text: Scratch.translate("Depth Test"), value: "depthTest" }, + { text: Scratch.translate("Depth Write"), value: "depthWrite" }, + { text: Scratch.translate("Color Write"), value: "colorWrite" }, + { text: Scratch.translate("Flat Shading"), value: "flatShading" }, + { text: Scratch.translate("Vertex Colors"), value: "vertexColors" }, + { text: Scratch.translate("Tone Mapped"), value: "toneMapped" }, + { text: Scratch.translate("Alpha Hash"), value: "alphaHash" }, + { text: Scratch.translate("Dithering"), value: "dithering" }, + { text: Scratch.translate("Polygon Offset"), value: "polygonOffset" } + ] + }, + materialColorProperties: { + items: [ + { text: Scratch.translate("Color"), value: "color" }, + { text: Scratch.translate("Emissive"), value: "emissive" }, + { text: Scratch.translate("Specular"), value: "specular" }, + { text: Scratch.translate("Sheen"), value: "sheen" } + ] + }, + materialMapProperties: { + items: [ + { text: Scratch.translate("Texture"), value: "map" }, + { text: Scratch.translate("Alpha Texture"), value: "alphaMap" }, + { text: Scratch.translate("Normal Texture"), value: "normalMap" }, + { text: Scratch.translate("Roughness Texture"), value: "roughnessMap" }, + { text: Scratch.translate("Metalness Texture"), value: "metalnessMap" }, + { text: Scratch.translate("Emissive Texture"), value: "emissiveMap" }, + { text: Scratch.translate("Environment Texture"), value: "envMap" }, + { text: Scratch.translate("Ambient Occlusion Texture"), value: "aoMap" }, + { text: Scratch.translate("Bump Texture"), value: "bumpMap" }, + { text: Scratch.translate("Displacement Texture"), value: "displacementMap" } + ] + }, + materialSides: { + items: [ + { text: Scratch.translate("Front"), value: "0" }, + { text: Scratch.translate("Back"), value: "1" }, + { text: Scratch.translate("Double"), value: "2" }, + ] + }, + textureProperties: { + items: [ + { text: Scratch.translate("Repeat (V2)"), value: "repeat" }, + { text: Scratch.translate("Center (V2)"), value: "center" }, + { text: Scratch.translate("Offset (V2)"), value: "offset" }, + { text: Scratch.translate("Anisotropy (Number)"), value: "anisotropy" }, + { text: Scratch.translate("Rotation (Number)"), value: "rotation" }, + { text: Scratch.translate("Premultiply Alpha (Boolean)"), value: "premultiplyAlpha" }, + ] + }, + textureWarp: { + items: [ + { text: Scratch.translate("Repeat Wrapping"), value: "1000" }, + { text: Scratch.translate("Clamp To Edge Wrapping"), value: "1001" }, + { text: Scratch.translate("Mirrored Repeat Wrapping"), value: "1002" }, + ] + }, + textureMapping: { + items: [ + { text: Scratch.translate("UV (Standard)"), value: "300" }, + //{ text: Scratch.translate("Cube Reflection (6 images?)"), value: "301" }, + //{ text: Scratch.translate("Cube Refraction (6 images?)"), value: "302" }, + //{ text: Scratch.translate("Equirectangular Reflection (no diference)"), value: "303" }, + { text: Scratch.translate("Equirectangular"), value: "304" }, + //{ text: Scratch.translate("Cube UV Reflection (errors)"), value: "306" } + ] + }, + magFilter: { + items: [ + { text: Scratch.translate("Linear Filter (Blurred)"), value: "LinearFilter" }, + { text: Scratch.translate("Nearest Filter (Pixelated)"), value: "NearestFilter" } + ] + }, + minFilter: { + items: [ + { text: Scratch.translate("Linear Filter"), value: "LinearFilter" }, + { text: Scratch.translate("Linear Mipmap Linear Filter"), value: "LinearMipmapLinearFilter" }, + { text: Scratch.translate("Linear Mipmap Nearest Filter"), value: "LinearMipmapNearestFilter" }, + { text: Scratch.translate("Nearest Filter"), value: "NearestFilter" }, + { text: Scratch.translate("Nearest Mipmap Linear Filter"), value: "NearestMipmapLinearFilter" }, + { text: Scratch.translate("Nearest Mipmap Nearest Filter"), value: "NearestMipmapNearestFilter" } + ] + }, + rendererProperties: { + items: [ + { text: Scratch.translate("Render Scene Automatically"), value: "autoRender" }, + { text: Scratch.translate("Clear All Automatically"), value: "autoClear" }, + { text: Scratch.translate("Clear Color Automatically"), value: "autoClearColor" }, + { text: Scratch.translate("Clear Depth Automatically"), value: "autoClearDepth" }, + { text: Scratch.translate("Shadows enabled"), value: "shadowMap.enabled" }, + ] + }, + rendererGetProperties: { + items: [ + { text: Scratch.translate("Render Scene Automatically"), value: "autoRender" }, + { text: Scratch.translate("Clear All Automatically"), value: "autoClear" }, + { text: Scratch.translate("Clear Color Automatically"), value: "autoClearColor" }, + { text: Scratch.translate("Clear Depth Automatically"), value: "autoClearDepth" }, + { text: Scratch.translate("Shadows enabled"), value: "shadowMap.enabled" }, + ] + }, + shadowMapTypes: { + items: [ + { text: Scratch.translate("Basic (Fastest)"), value: "0" }, + { text: Scratch.translate("Smooth (Default)"), value: "1" }, + { text: Scratch.translate("Expensive"), value: "2" }, + { text: Scratch.translate("Fabulous (Slowest)"), value: "3" }, + ] + }, + clearBuffers: { + items: [ + { text: Scratch.translate("All"), value: "clear" }, + { text: Scratch.translate("Color"), value: "clearColor" }, + { text: Scratch.translate("Depth"), value: "clearDepth" } + ] + }, + sceneProperties: { + items: [ + { text: Scratch.translate("Background"), value: "background" }, + { text: Scratch.translate("Background Blurriness"), value: "backgroundBlurriness" }, + { text: Scratch.translate("Background Intensity"), value: "backgroundIntensity" }, + { text: Scratch.translate("Background Rotation"), value: "backgroundRotation" }, + + { text: Scratch.translate("Environment"), value: "environment" }, + { text: Scratch.translate("Environment Intensity"), value: "environmentIntensity" }, + { text: Scratch.translate("Environment Rotation"), value: "environmentRotation" }, + + { text: Scratch.translate("Fog"), value: "fog" }, + + { text: Scratch.translate("Override Material"), value: "overrideMaterial" } + ] + }, + light: { + items: [ + { text: Scratch.translate("Intensity"), value: "intensity" }, + { text: Scratch.translate("Point, Spot: Distance"), value: "distance" }, + { text: Scratch.translate("Point, Spot: Decay"), value: "decay" }, + { text: Scratch.translate("Point, Spot, Rectangular: Power"), value: "power" }, + { text: Scratch.translate("Spot: Angle"), value: "angle" }, + { text: Scratch.translate("Spot: Penumbra"), value: "penumbra" }, + { text: Scratch.translate("Rectangular: Width"), value: "width" }, + { text: Scratch.translate("Rectangular: Height"), value: "height" }, + ] + }, + lightColors: { + items: [ + { text: Scratch.translate("Color"), value: "color" }, + { text: Scratch.translate("Hemisphere: Sky Color"), value: "skyColor" }, + { text: Scratch.translate("Hemisphere: Ground Color"), value: "groundColor" }, + ] + }, + lightStrings: { + items: [ + { text: Scratch.translate("Spot: Texture"), value: "map" }, + ] + }, + lightGetter: { + items: [ + { text: Scratch.translate("Intensity"), value: "intensity" }, + { text: Scratch.translate("Color"), value: "color" }, + { text: Scratch.translate("Distance"), value: "distance" }, + { text: Scratch.translate("Decay"), value: "decay" }, + { text: Scratch.translate("Angle"), value: "angle" }, + { text: Scratch.translate("Penumbra"), value: "penumbra" }, + { text: Scratch.translate("Power"), value: "power" }, + { text: Scratch.translate("width"), value: "width" }, + { text: Scratch.translate("height"), value: "height" } + ] + }, + lightShadow: { + items: [ + { text: Scratch.translate("Scale"), value: "scale" }, + { text: Scratch.translate("Blur"), value: "radius" }, + { text: Scratch.translate("Instensity"), value: "intensity" } + ] + }, + instanceItems: { + items: [ + { text: Scratch.translate("matrix"), value: "matrix" }, + { text: Scratch.translate("color"), value: "color" }, + ] + }, + reset: { + items: [ + { text: Scratch.translate("everything"), value: "everything" }, + { text: Scratch.translate("objects"), value: "objects" }, + { text: Scratch.translate("geometries"), value: "geometries" }, + { text: Scratch.translate("materials"), value: "materials" }, + { text: Scratch.translate("textures"), value: "textures" }, + { text: Scratch.translate("audios"), value: "audios" }, + ] + }, + stats: { + items: [ + { text: Scratch.translate("memory"), value: "memory" }, + { text: Scratch.translate("render"), value: "render" }, + ] + }, + audioNumeral: { + items: [ + { text: Scratch.translate("Volume"), value: "setVolume" }, + { text: Scratch.translate("Speed"), value: "setPlaybackRate" }, + { text: Scratch.translate("Detune"), value: "setDetune" }, + { text: Scratch.translate("Volume Drop Distance (0.01-x)"), value: "setRefDistance" }, + { text: Scratch.translate("Max Distance"), value: "setMaxDistance" }, + { text: Scratch.translate("Fade Factor"), value: "setRolloffFactor" }, + //{ text: Scratch.translate("Loop start (seconds)"), value: "setLoopStart" }, + //{ text: Scratch.translate("Loop end (seconds)"), value: "setLoopEnd" }, + { text: Scratch.translate("Offset"), value: "offset" }, + ] + }, + audioBoolean: { + items: [ + //{ text: Scratch.translate("Autoplay"), value: "autoplay" }, + { text: Scratch.translate("Loop"), value: "setLoop" }, + ] + }, + audioPlayback: { + items: [ + { text: Scratch.translate("Play/Resume"), value: "play" }, + { text: Scratch.translate("Stop"), value: "stop" }, + { text: Scratch.translate("Pause"), value: "pause" }, + ] + }, + isAudio: { + items: [ + { text: Scratch.translate("playing"), value: "isPlaying" }, + { text: Scratch.translate("looping"), value: "loop" }, + ] + }, + audioGetter: { + items: [ + { text: Scratch.translate("Volume"), value: "getVolume" }, + { text: Scratch.translate("Detune"), value: "getDetune" }, + { text: Scratch.translate("Speed"), value: "getPlaybackRate" }, + { text: Scratch.translate("Max Distance"), value: "getMaxDistance" }, + { text: Scratch.translate("Volume Drop Distance"), value: "getRefDistance" }, + { text: Scratch.translate("Fade Factor"), value: "getRolloffFactor" }, + ] + }, + raycast: { + items: [ + { text: Scratch.translate("Distance"), value: "distance" }, + { text: Scratch.translate("Object"), value: "object" }, + { text: Scratch.translate("Point world coordinates"), value: "point" }, + { text: Scratch.translate("Normal"), value: "normal" }, + { text: Scratch.translate("InstancedMesh: Instance Id"), value: "instanceId" }, + ] + }, + loadedModels: { + items: () => { + const s = runtime.extensionStorage[extensionID] || null; + if (!s) { initStorage(); return [["waiting to load..."]]; } + const m = s.models; + if (!m) { s.models = {}; m = {}; } + if (Object.keys(m).length == 0) return [["Load a model!"]]; + return [Object.keys(m)]; + } + }, + loadedFonts: { + items: () => { + const s = runtime.extensionStorage[extensionID] || null; + if (!s) { initStorage(); return [["waiting to load..."]]; } + const m = s.fonts; + if (!m) { s.fonts = {}; m = {}; } + if (Object.keys(m).length == 0) return [["Load a font!"]]; + return [Object.keys(m)]; + } + }, }, }; } - openExtra() {open("https://threejs.org/docs");} + openExtra() { open("https://threejs.org/docs"); } reset(args) { switch (args.VALUE) { @@ -1646,13 +1754,13 @@ scene.clear(); scene.fog = null; scene.overrideMaterial = null; - camera = new THREE.PerspectiveCamera(90, width/height); + camera = new THREE.PerspectiveCamera(90, width / height); camera.add(three.AudioListener); camera.position.z = 2; assets.objects.set("camera", camera); break; case "objects": - assets.objects.forEach( o => o.removeFromParent() ); + assets.objects.forEach(o => o.removeFromParent()); assets.objects.clear(); break; case "geometries": @@ -1685,31 +1793,34 @@ return three.renderer.info[args.VALUE]; } - vector2(args) {return `[${args.X}, ${args.Y}]`;} - vector3(args) {return `[${args.X}, ${args.Y}, ${args.Z}]`;} + vector2(args) { return `[${args.X}, ${args.Y}]`; } + vector3(args) { return `[${args.X}, ${args.Y}, ${args.Z}]`; } renderer(args) { const keys = args.PROPERTY.split("."); let current = three.renderer; - for (let i = 0; i < keys.length - 1; i++) { current = current[keys[i]]; - if (!current) return;} + for (let i = 0; i < keys.length - 1; i++) { + current = current[keys[i]]; + if (!current) return; + } - if (args.PROPERTY == "autoRender") - { + if (args.PROPERTY == "autoRender") { if (JSON.parse(args.VALUE)) loopId = requestAnimationFrame(loop); else { - cancelAnimationFrame(loopId); + cancelAnimationFrame(loopId); loopId = null; } - } + } else current[keys[keys.length - 1]] = JSON.parse(args.VALUE); } + rendererClear(args) { three.renderer[args.B](); render(); } + rendererRender(args) { - render(); //future physics, should change this to a step() method instead? or will it work like this?ยบ + render(); //future physics, should change this to a step() method instead? or will it work like this? } rendererShadow(args) { three.renderer.shadowMap.type = JSON.parse(args.PROPERTY); @@ -1717,12 +1828,17 @@ getRenderer(args) { const keys = args.PROPERTY.split("."); let current = three.renderer; - for (let i = 0; i < keys.length - 1; i++) { current = current[keys[i]]; - if (!current) return;} + for (let i = 0; i < keys.length - 1; i++) { + current = current[keys[i]]; + if (!current) return; + } return current[keys[keys.length - 1]]; } - color(args) {return args.COLOR;} + + color(args) { + return args.COLOR; + } scene(args) { let value; @@ -1731,25 +1847,25 @@ if (args.VALUE == "null" || args.VALUE == "") { material = null; } else { - material = assets.materials.get(args.VALUE); - if (!material) {console.warn(`No material named ${args.VALUE}`); return;} + material = assets.materials.get(args.VALUE); + if (!material) { console.warn(`No material named ${args.VALUE}`); return; } } scene.overrideMaterial = material; } else if (args.PROPERTY == "fog") { args.VALUE == "[fog]" ? - scene.fog = storedFog - : scene.fog = null; + scene.fog = storedFog + : scene.fog = null; } else { try { value = JSON.parse(args.VALUE); } catch { if (args.VALUE.at(0) == "#") value = new THREE.Color(args.VALUE); - else value = assets.textures.get(args.VALUE); + else value = assets.textures.get(args.VALUE); } scene[args.PROPERTY] = value; } - + } getScene(args) { let value = scene[args.PROPERTY]; @@ -1769,19 +1885,23 @@ deleteAsset(args) { const asset = assets[args.TYPE].get(args.NAME); - if (!asset) {console.warn(`No asset named ${args.NAME}`); return;} + if (!asset) { console.warn(`No asset named ${args.NAME}`); return; } switch (args.TYPE) { case "objects": asset.removeFromParent(); break; - default: asset.dispose(); + default: asset.dispose(); } - assets[args.TYPE].delete(args.NAME); + assets[args.TYPE].delete(args.NAME); } /*async*/ setTransform(args) { const obj = assets.objects.get(args.OBJECT); - if (!obj) {console.warn(`No object named ${args.OBJECT}`); return;} + + if (!obj) { + console.warn(`No object named ${args.OBJECT}`); + return; + } let values = JSON.parse(args.VALUE); args.TRANSFORM == "rotation" ? values = values.map(a => THREE.MathUtils.degToRad(a)) : null; @@ -1794,7 +1914,7 @@ getTransform(args) { const obj = assets.objects.get(args.OBJECT); - if (!obj) {console.warn(`No object named ${args.OBJECT}`); return;} + if (!obj) { console.warn(`No object named ${args.OBJECT}`); return; } obj.updateMatrix(); let v3; @@ -1802,14 +1922,14 @@ v3 = obj[args.TRANSFORM](new THREE.Vector3); v3.toArray(); } else v3 = obj[args.TRANSFORM].toArray(); - args.TRANSFORM == "rotation" || args.TRANSFORM == "getWorldDirection" ? v3 = v3.slice(0,3).map(r=> THREE.MathUtils.radToDeg(r)) : null; + args.TRANSFORM == "rotation" || args.TRANSFORM == "getWorldDirection" ? v3 = v3.slice(0, 3).map(r => THREE.MathUtils.radToDeg(r)) : null; return JSON.stringify(v3); } /*async*/ transformTransform(args) { const obj = assets.objects.get(args.OBJECT); - if (!obj) {console.warn(`No object named ${args.OBJECT}`); return;} + if (!obj) { console.warn(`No object named ${args.OBJECT}`); return; } let v = args.VALUE; args.TRANSFORM == "rotation" ? v = THREE.MathUtils.degToRad(v) : null; /*await*/ args.ACTION == "set" ? obj[args.TRANSFORM][args.XYZ] = v : obj[args.TRANSFORM][args.XYZ] += v; @@ -1817,18 +1937,18 @@ setRotation(args) { const obj = assets.objects.get(args.OBJECT); - if (!obj) {console.warn(`No object named ${args.OBJECT}`); return;} + if (!obj) { console.warn(`No object named ${args.OBJECT}`); return; } obj.rotation.order = args.ORDER; } getAxis(args) { - return JSON.parse(args.V3)[{"x":0, "y":1, "z": 2}[args.XYZ]]; + return JSON.parse(args.V3)[{ "x": 0, "y": 1, "z": 2 }[args.XYZ]]; } operateVector(args) { const v = new THREE.Vector3().fromArray(JSON.parse(args.V)); let r = v[args.OPERATION](); - typeof(r) == "object" ? r = r.toArray() : null; + typeof (r) == "object" ? r = r.toArray() : null; return JSON.stringify(r); } @@ -1836,20 +1956,20 @@ const v1 = new THREE.Vector3().fromArray(JSON.parse(args.V1)); let v2 = JSON.parse(args.V2); if (args.OPERATION == "applyEuler") v2 = new THREE.Euler().fromArray(v2); - else typeof(v2) == "number" ? null : v2 = new THREE.Vector3().fromArray(v2); + else typeof (v2) == "number" ? null : v2 = new THREE.Vector3().fromArray(v2); let r = v1[args.OPERATION](v2); - typeof(r) == "object" ? r = r.toArray() : null; + typeof (r) == "object" ? r = r.toArray() : null; return JSON.stringify(r); } moveVector(args) { let v3 = new THREE.Vector3().fromArray(JSON.parse(args.V)); - const [x,y,z] = JSON.parse(args.D); + const [x, y, z] = JSON.parse(args.D); const euler = new THREE.Euler( - THREE.MathUtils.degToRad(x), - THREE.MathUtils.degToRad(y), - THREE.MathUtils.degToRad(z), + THREE.MathUtils.degToRad(x), + THREE.MathUtils.degToRad(y), + THREE.MathUtils.degToRad(z), args.ORDER ); const direction = new THREE.Vector3(0, 0, -1).applyEuler(euler).normalize(); @@ -1861,8 +1981,8 @@ getVectorProjected(args) { const v3 = new THREE.Vector3().fromArray(JSON.parse(args.V)); v3.project(camera); - const v2 = new THREE.Vector2(...three.skin.size.map(m=>m/2)); - const r = [v3.x*v2.x, v3.y*v2.y]; + const v2 = new THREE.Vector2(...three.skin.size.map(m => m / 2)); + const r = [v3.x * v2.x, v3.y * v2.y]; return JSON.stringify(r); } @@ -1871,33 +1991,33 @@ const v2 = new THREE.Vector3().fromArray(JSON.parse(args.V2)); const direction = v1.sub(v2).normalize(); - const pitch = THREE.MathUtils.radToDeg( Math.atan2(-direction.y, Math.sqrt(direction.x*direction.x + direction.z*direction.z)) ); - const yaw = THREE.MathUtils.radToDeg( Math.atan2(direction.x, direction.z) ); + const pitch = THREE.MathUtils.radToDeg(Math.atan2(-direction.y, Math.sqrt(direction.x * direction.x + direction.z * direction.z))); + const yaw = THREE.MathUtils.radToDeg(Math.atan2(direction.x, direction.z)); - return JSON.stringify([pitch,yaw,0]); + return JSON.stringify([pitch, yaw, 0]); } interpolateVectors(args) { const v1 = new THREE.Vector3().fromArray(JSON.parse(args.V1)); const v2 = new THREE.Vector3().fromArray(JSON.parse(args.V2)); - const r = v1.lerp(v2, args.A/100); + const r = v1.lerp(v2, args.A / 100); return JSON.stringify(r.toArray()); } addObject(args) { - if (this.objectExists({NAME: args.NAME})) { + if (this.objectExists({ NAME: args.NAME })) { console.warn(`Already existing object named ${args.NAME}. Will replace!`); const obj = assets.objects.get(args.NAME); obj.removeFromParent(); } const obj = new THREE[args.TYPE](); - if (args.NAME == "scene") {console.warn(`Don't name objects "scene"!`); return;} + if (args.NAME == "scene") { console.warn(`Don't name objects "scene"!`); return; } assets.objects.set(args.NAME, obj); switch (args.TYPE) { - case "PerspectiveCamera": + case "PerspectiveCamera": obj.aspect = width / height; obj.updateProjectionMatrix(); break; @@ -1933,32 +2053,32 @@ } obj.name = args.NAME; - + const parent = assets.objects.get(args.PARENT); if (!parent) scene.add(obj); else parent.add(obj); } - objectExists(args){ - if(assets.objects.get(args.NAME)) return true; + objectExists(args) { + if (assets.objects.get(args.NAME)) return true; else return false; } - setRenderingCamera(args){ + setRenderingCamera(args) { const selected = assets.objects.get(args.NAME); - if (!selected) {console.warn(`No object named "${args.NAME}"`); return;} + if (!selected) { console.warn(`No object named "${args.NAME}"`); return; } three.AudioListener.removeFromParent(); selected.add(three.AudioListener); camera = selected; } - camera() {return [...assets.objects.entries()].find(([key, value]) => value === camera)?.[0];} + camera() { return [...assets.objects.entries()].find(([key, value]) => value === camera)?.[0]; } setObject(args) { let data; const obj = assets.objects.get(args.NAME); - if (!obj) {console.warn(`No object named ${args.NAME}`); return;} + if (!obj) { console.warn(`No object named ${args.NAME}`); return; } switch (args.PROPERTY) { case "geometry": @@ -1968,9 +2088,11 @@ case "material": let material = args.DATA; data = []; - try { material = JSON.parse(material); - material.forEach(m=>data.push(assets.materials.get(m) || defaultMat));} - catch {data = assets.materials.get(material) || defaultMat;} + try { + material = JSON.parse(material); + material.forEach(m => data.push(assets.materials.get(m) || defaultMat)); + } + catch { data = assets.materials.get(material) || defaultMat; } obj.material = data; break; default: obj[args.PROPERTY] = JSON.parse(args.DATA); @@ -1978,14 +2100,14 @@ } setObjectBool(args) { const obj = assets.objects.get(args.NAME); - if (!obj) {console.warn(`No object named ${args.NAME}`); return;} + if (!obj) { console.warn(`No object named ${args.NAME}`); return; } - obj.traverse(o=>{o[args.PROPERTY] = JSON.parse(args.DATA);}); + obj.traverse(o => { o[args.PROPERTY] = JSON.parse(args.DATA); }); obj[args.PROPERTY] = JSON.parse(args.DATA); } getObjectBool(args) { const obj = assets.objects.get(args.NAME); - if (!obj) {console.warn(`No object named ${args.NAME}`); return;} + if (!obj) { console.warn(`No object named ${args.NAME}`); return; } return JSON.stringify(obj[args.PROPERTY]); } @@ -2002,7 +2124,7 @@ setGeometry(args) { const geometry = assets.geometries.get(args.NAME); - if (!geometry) {console.warn(`No geometry named ${args.NAME}`); return;} + if (!geometry) { console.warn(`No geometry named ${args.NAME}`); return; } let data, dataLength; data = JSON.parse(args.DATA); //.split(" ").map(p=>JSON.parse(p)).flat(); //from [0,0,0] [0,0,1] to 0,0,0,0,0,1 @@ -2020,7 +2142,7 @@ } getGeometry(args) { const geometry = assets.geometries.get(args.NAME); - if (!geometry) {console.warn(`No geometry named ${args.NAME}`); return;} + if (!geometry) { console.warn(`No geometry named ${args.NAME}`); return; } const a = geometry.getAttribute(args.PROPERTY).array; /* for custom output [0,0,0] [0,0,1] [1,0,1] @@ -2031,7 +2153,7 @@ return JSON.stringify(result).replaceAll("],", "] ").slice(1,-1); */ - return JSON.stringify(Object.values(a)); + return JSON.stringify(Object.values(a)); } createMaterial(args) { @@ -2046,7 +2168,7 @@ setMaterial(args) { const material = assets.materials.get(args.NAME); - if (!material) {console.warn(`No material named ${args.NAME}`); return;} + if (!material) { console.warn(`No material named ${args.NAME}`); return; } material[args.PROPERTY] = args.DATA; material.needsUpdate = true; } @@ -2060,7 +2182,7 @@ } setMapMaterial(args) { args.DATA = assets.textures.get(args.DATA); - if (!args.DATA) {console.warn(`No texture named ${args.DATA}`); return;} + if (!args.DATA) { console.warn(`No texture named ${args.DATA}`); return; } this.setMaterial(args); } setMaterialSide(args) { @@ -2071,21 +2193,23 @@ setMaterialClipping(args) { args.PROPERTY = "side"; - let material = args.DATA; - args.DATA = []; - try { material = JSON.parse(material); - material.forEach(m=>args.DATA.push(assets.objects.get(m) || null));} - catch {args.DATA = assets.objects.get(material) || null;} - + let material = args.DATA; + args.DATA = []; + try { + material = JSON.parse(material); + material.forEach(m => args.DATA.push(assets.objects.get(m) || null)); + } + catch { args.DATA = assets.objects.get(material) || null; } + this.setMaterial(args); } joinMaterial(args) { let m1 = args.MATERIAL; let m2 = args.MATERIAL2; - try { m1 = JSON.parse(m1);} - catch {m1 = [m1];} - try { m2 = JSON.parse(m2);} - catch {m2 = [m2];} + try { m1 = JSON.parse(m1); } + catch { m1 = [m1]; } + try { m2 = JSON.parse(m2); } + catch { m2 = [m2]; } m1.push(...m2); return JSON.stringify(m1); } @@ -2099,7 +2223,7 @@ setTextureWrap(args) { const texture = assets.textures.get(args.NAME); - if (!texture) {console.warn(`No texture named ${args.NAME}`); return;} + if (!texture) { console.warn(`No texture named ${args.NAME}`); return; } texture.wrapS = args.U; texture.wrapT = args.V; texture.needsUpdate = true; @@ -2107,7 +2231,7 @@ setTextureFilter(args) { const texture = assets.textures.get(args.NAME); - if (!texture) {console.warn(`No texture named ${args.NAME}`); return;} + if (!texture) { console.warn(`No texture named ${args.NAME}`); return; } texture.magFilter = THREE[args.MAG]; texture.minFilter = THREE[args.MIN]; @@ -2116,16 +2240,16 @@ setTexture(args) { const texture = assets.textures.get(args.NAME); - if (!texture) {console.warn(`No texture named ${args.NAME}`); return;} + if (!texture) { console.warn(`No texture named ${args.NAME}`); return; } let r = JSON.parse(args.VALUE); - typeof(r) == "object" ? r = new THREE.Vector2().fromArray(r) : null; + typeof (r) == "object" ? r = new THREE.Vector2().fromArray(r) : null; texture[args.PROPERTY] = r; texture.needsUpdate = true; } setTextureMapping(args) { const texture = assets.textures.get(args.NAME); - if (!texture) {console.warn(`No texture named ${args.NAME}`); return;} + if (!texture) { console.warn(`No texture named ${args.NAME}`); return; } texture.mapping = JSON.parse(args.VALUE); texture.needsUpdate = true; @@ -2133,7 +2257,7 @@ setCamera(args) { const cam = assets.objects.get(args.NAME); - if (!cam) {console.warn(`No camera named ${args.NAME}`); return;} + if (!cam) { console.warn(`No camera named ${args.NAME}`); return; } if (cam.isCamera) { cam[args.PROPERTY] = JSON.parse(args.VALUE); @@ -2142,64 +2266,64 @@ } getCamera(args) { const cam = assets.objects.get(args.NAME); - if (!cam) {console.warn(`No camera named ${args.NAME}`); return;} + if (!cam) { console.warn(`No camera named ${args.NAME}`); return; } return JSON.stringify(cam[args.PROPERTY]); } setLight(args) { const light = assets.objects.get(args.NAME); - if (!light) {console.warn(`No light named ${args.NAME}`); return;} + if (!light) { console.warn(`No light named ${args.NAME}`); return; } let r = args.VALUE; if (light.isLight) { if (args.PROPERTY == "skyColor") { //hemisphere light needs reinit to set skycolor - const light = assets.objects.get(args.NAME); - if (!light) {console.warn(`No light named ${args.NAME}`); return;} + const light = assets.objects.get(args.NAME); + if (!light) { console.warn(`No light named ${args.NAME}`); return; } - assets.objects.delete(args.NAME); - light.removeFromParent(); + assets.objects.delete(args.NAME); + light.removeFromParent(); - const r = new THREE.HemisphereLight(args.VALUE, "#"+light.groundColor.getHexString(), light.intensity); - light.dispose(); + const r = new THREE.HemisphereLight(args.VALUE, "#" + light.groundColor.getHexString(), light.intensity); + light.dispose(); - assets.objects.set(args.NAME, r); - r.name = args.NAME; - scene.add(r); - } else { - //texture? color? - args.PROPERTY == "map" ? r = assets.textures.get(args.VALUE) : typeof(r) == "string" && r.at(0) == "#" ? r = new THREE.Color(r) : r = JSON.parse(r); - light[args.PROPERTY] = r; - } + assets.objects.set(args.NAME, r); + r.name = args.NAME; + scene.add(r); + } else { + //texture? color? + args.PROPERTY == "map" ? r = assets.textures.get(args.VALUE) : typeof (r) == "string" && r.at(0) == "#" ? r = new THREE.Color(r) : r = JSON.parse(r); + light[args.PROPERTY] = r; + } } else console.error(`${args.NAME} is not a light!`); } - setLightColor(args) {this.setLight(args);} - setLightMap(args) {this.setLight(args);} + setLightColor(args) { this.setLight(args); } + setLightMap(args) { this.setLight(args); } setTargetLight(args) { const light = assets.objects.get(args.NAME); - if (!light) {console.warn(`No light named ${args.NAME}`); return;} + if (!light) { console.warn(`No light named ${args.NAME}`); return; } - if (light.isSpotLight || light.isDirectionalLight ) { + if (light.isSpotLight || light.isDirectionalLight) { light.target.position.set(...JSON.parse(args.VALUE)); light.target.updateMatrixWorld(); } else console.error(`${args.NAME} is not a light or it's an invalid type!`); } getLight(args) { const light = assets.objects.get(args.NAME); - if (!light) {console.warn(`No light named ${args.NAME}`); return;} + if (!light) { console.warn(`No light named ${args.NAME}`); return; } if (args.PROPERTY == "color") return "#" + light.color.getHexString(); return JSON.stringify(light[args.PROPERTY]); } setLightShadow(args) { const light = assets.objects.get(args.NAME); - if (!light || !light.shadow) {console.warn(`No light named ${args.NAME}, or it doesn't support shadows!`); return;} + if (!light || !light.shadow) { console.warn(`No light named ${args.NAME}, or it doesn't support shadows!`); return; } const v = JSON.parse(args.VALUE); if (args.PROPERTY == "scale") { - light.shadow.mapSize.width = 2**v; - light.shadow.mapSize.height = 2**v; + light.shadow.mapSize.width = 2 ** v; + light.shadow.mapSize.height = 2 ** v; if (light.shadow.map) { light.shadow.map.dispose(); light.shadow.map = null; @@ -2210,11 +2334,11 @@ touching(args) { const oa = assets.objects.get(args.A); - if (!oa) {console.warn(`No object named ${args.A}`); return;} + if (!oa) { console.warn(`No object named ${args.A}`); return; } const ob = assets.objects.get(args.B); - if (!ob) {console.warn(`No object named ${args.B}`); return;} - let a = new THREE.Box3().setFromObject( oa ); - let b = new THREE.Box3().setFromObject( ob ); + if (!ob) { console.warn(`No object named ${args.B}`); return; } + let a = new THREE.Box3().setFromObject(oa); + let b = new THREE.Box3().setFromObject(ob); return a.intersectsBox(b); } @@ -2232,10 +2356,10 @@ vm.extensionManager.refreshBlocks(); } async addModel(args) { - if (args.NAME == "scene") {console.warn(`Don't name objects "scene"!`); return;} + if (args.NAME == "scene") { console.warn(`Don't name objects "scene"!`); return; } const url = runtime.extensionStorage[extensionID].models[args.FILE]; - if (!url) {console.warn(`No model named ${args.FILE}`); return;} + if (!url) { console.warn(`No model named ${args.FILE}`); return; } const response = await fetch(url); const file = await response.arrayBuffer(); @@ -2249,7 +2373,7 @@ const model = glb.scene; console.log(glb); group.add(model); - group.traverse(o=>{o.castShadow = true; o.receiveShadow = true;}); + group.traverse(o => { o.castShadow = true; o.receiveShadow = true; }); }); } removeModel(args) { @@ -2258,18 +2382,20 @@ } createInstance(args) { - if (args.NAME == "scene") {console.warn(`Don't name objects "scene"!`); return;} + if (args.NAME == "scene") { console.warn(`Don't name objects "scene"!`); return; } const g = assets.geometries.get(args.GEOMETRY) || defaultGeo; let material = args.MATERIAL; let mat = []; - try { material = JSON.parse(material); - material.forEach(m=>mat.push(assets.materials.get(m) || defaultMat));} - catch {mat = assets.materials.get(material) || defaultMat;} + try { + material = JSON.parse(material); + material.forEach(m => mat.push(assets.materials.get(m) || defaultMat)); + } + catch { mat = assets.materials.get(material) || defaultMat; } - const i = new THREE.InstancedMesh(g,mat,args.COUNT); - i.instanceMatrix.setUsage( THREE.DynamicDrawUsage ); //should add a block to change this?? is it any harm leaving it like this? + const i = new THREE.InstancedMesh(g, mat, args.COUNT); + i.instanceMatrix.setUsage(THREE.DynamicDrawUsage); //should add a block to change this?? is it any harm leaving it like this? assets.objects.set(args.NAME, i); i.name = args.NAME; scene.add(i); @@ -2277,13 +2403,13 @@ setInstance(args) { const i = assets.objects.get(args.NAME); - if (!i) {console.warn(`No instance named ${args.NAME}`); return;} + if (!i) { console.warn(`No instance named ${args.NAME}`); return; } if (args.PROPERTY == "matrix") { const m = new THREE.Matrix4().fromArray(JSON.parse(args.MATRIX)); - i.setMatrixAt(args.INDEX-1, m); + i.setMatrixAt(args.INDEX - 1, m); i.instanceMatrix.needsUpdate = true; } else { - i.setColorAt(args.INDEX-1, new THREE.Color(args.MATRIX)); + i.setColorAt(args.INDEX - 1, new THREE.Color(args.MATRIX)); i.instanceColor.needsUpdate = true; } } @@ -2298,13 +2424,13 @@ m.decompose(position, quaternion, scale); const decomposed = { - "position": position, - "rotation": quaternion, - "scale": scale + "position": position, + "rotation": quaternion, + "scale": scale }; let v3 = decomposed[args.TRANSFORM].toArray(); - args.TRANSFORM == "rotation" ? v3 = new THREE.Euler().setFromQuaternion(quaternion).toArray().slice(0,3).map(r => THREE.MathUtils.radToDeg(r)) : null; - return JSON.stringify(v3); + args.TRANSFORM == "rotation" ? v3 = new THREE.Euler().setFromQuaternion(quaternion).toArray().slice(0, 3).map(r => THREE.MathUtils.radToDeg(r)) : null; + return JSON.stringify(v3); } doMatrix(args) { @@ -2321,7 +2447,7 @@ async loadFont() { //get ttf file const file = await new Promise((resolve) => { - const input = document.createElement("input"); + const input = document.createElement("input"); input.type = "file"; input.accept = ".ttf"; input.multiple = false; @@ -2344,119 +2470,119 @@ }); //convert to json function convertToFaceType(font) { -/* -https://github.com/gero3/facetype.js -//Modified by Civero to match current compatibillity - -The MIT License (MIT) - -Copyright (c) 2016 gero3 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - var scale = (1000 * 100) / ( (font.unitsPerEm || 2048) *72); - var result = {}; - result.glyphs = {}; - - for (let i = 0; i < font.glyphs.length; i++) { - const glyph = font.glyphs.get(i); - const unicodes = []; - if (glyph.unicode !== undefined) { - unicodes.push(glyph.unicode); - } - if (glyph.unicodes.length) { - glyph.unicodes.forEach(function(unicode){ - if (unicodes.indexOf (unicode) == -1) { - unicodes.push(unicode); - } - }); - } - - unicodes.forEach(function(unicode){ - var glyphCharacter = String.fromCharCode (unicode); - var needToExport = true; - /*if (restriction.range !== null) { - needToExport = (unicode >= restriction.range[0] && unicode <= restriction.range[1]); - } else if (restriction.set !== null) { - needToExport = (restrictCharacterSetInput.value.indexOf (glyphCharacter) != -1); - }*/ - if (needToExport) { - - var token = {}; - token.ha = Math.round(glyph.advanceWidth * scale); - token.x_min = Math.round(glyph.xMin * scale); - token.x_max = Math.round(glyph.xMax * scale); - token.o = ""; - //if (reverseTypeface.checked) {glyph.path.commands = reverseCommands(glyph.path.commands);} - glyph.path.commands.forEach(function(command,i){ - if (command.type.toLowerCase() === "c") {command.type = "b";} - token.o += command.type.toLowerCase(); - token.o += " "; - if (command.x !== undefined && command.y !== undefined){ - token.o += Math.round(command.x * scale); - token.o += " "; - token.o += Math.round(command.y * scale); - token.o += " "; - } - if (command.x1 !== undefined && command.y1 !== undefined){ - token.o += Math.round(command.x1 * scale); - token.o += " "; - token.o += Math.round(command.y1 * scale); - token.o += " "; - } - if (command.x2 !== undefined && command.y2 !== undefined){ - token.o += Math.round(command.x2 * scale); - token.o += " "; - token.o += Math.round(command.y2 * scale); - token.o += " "; - } - }); - result.glyphs[String.fromCharCode(unicode)] = token; - } - }); - } - result.familyName = font.familyName; - result.ascender = Math.round(font.ascender * scale); - result.descender = Math.round(font.descender * scale); - result.underlinePosition = Math.round(font.tables.post.underlinePosition * scale); - result.underlineThickness = Math.round(font.tables.post.underlineThickness * scale); - result.boundingBox = { - "yMin": Math.round(font.tables.head.yMin * scale), - "xMin": Math.round(font.tables.head.xMin * scale), - "yMax": Math.round(font.tables.head.yMax * scale), - "xMax": Math.round(font.tables.head.xMax * scale) - }; - result.resolution = 1000; - result.original_font_information = font.tables.name; - if (font.names.fontSubfamily.en.toLowerCase().indexOf("bold") > -1){ - result.cssFontWeight = "bold"; - } else { - result.cssFontWeight = "normal"; - } - - if (font.names.fontSubfamily.en.toLowerCase().indexOf("italic") > -1){ - result.cssFontStyle = "italic"; - } else { - result.cssFontStyle = "normal"; - } - - return JSON.stringify(result); + /* + https://github.com/gero3/facetype.js + //Modified by Civero to match current compatibillity + + The MIT License (MIT) + + Copyright (c) 2016 gero3 + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + var scale = (1000 * 100) / ((font.unitsPerEm || 2048) * 72); + var result = {}; + result.glyphs = {}; + + for (let i = 0; i < font.glyphs.length; i++) { + const glyph = font.glyphs.get(i); + const unicodes = []; + if (glyph.unicode !== undefined) { + unicodes.push(glyph.unicode); + } + if (glyph.unicodes.length) { + glyph.unicodes.forEach(function (unicode) { + if (unicodes.indexOf(unicode) == -1) { + unicodes.push(unicode); + } + }); + } + + unicodes.forEach(function (unicode) { + var glyphCharacter = String.fromCharCode(unicode); + var needToExport = true; + /*if (restriction.range !== null) { + needToExport = (unicode >= restriction.range[0] && unicode <= restriction.range[1]); + } else if (restriction.set !== null) { + needToExport = (restrictCharacterSetInput.value.indexOf (glyphCharacter) != -1); + }*/ + if (needToExport) { + + var token = {}; + token.ha = Math.round(glyph.advanceWidth * scale); + token.x_min = Math.round(glyph.xMin * scale); + token.x_max = Math.round(glyph.xMax * scale); + token.o = ""; + //if (reverseTypeface.checked) {glyph.path.commands = reverseCommands(glyph.path.commands);} + glyph.path.commands.forEach(function (command, i) { + if (command.type.toLowerCase() === "c") { command.type = "b"; } + token.o += command.type.toLowerCase(); + token.o += " "; + if (command.x !== undefined && command.y !== undefined) { + token.o += Math.round(command.x * scale); + token.o += " "; + token.o += Math.round(command.y * scale); + token.o += " "; + } + if (command.x1 !== undefined && command.y1 !== undefined) { + token.o += Math.round(command.x1 * scale); + token.o += " "; + token.o += Math.round(command.y1 * scale); + token.o += " "; + } + if (command.x2 !== undefined && command.y2 !== undefined) { + token.o += Math.round(command.x2 * scale); + token.o += " "; + token.o += Math.round(command.y2 * scale); + token.o += " "; + } + }); + result.glyphs[String.fromCharCode(unicode)] = token; + } + }); + } + result.familyName = font.familyName; + result.ascender = Math.round(font.ascender * scale); + result.descender = Math.round(font.descender * scale); + result.underlinePosition = Math.round(font.tables.post.underlinePosition * scale); + result.underlineThickness = Math.round(font.tables.post.underlineThickness * scale); + result.boundingBox = { + "yMin": Math.round(font.tables.head.yMin * scale), + "xMin": Math.round(font.tables.head.xMin * scale), + "yMax": Math.round(font.tables.head.yMax * scale), + "xMax": Math.round(font.tables.head.xMax * scale) + }; + result.resolution = 1000; + result.original_font_information = font.tables.name; + if (font.names.fontSubfamily.en.toLowerCase().indexOf("bold") > -1) { + result.cssFontWeight = "bold"; + } else { + result.cssFontWeight = "normal"; + } + + if (font.names.fontSubfamily.en.toLowerCase().indexOf("italic") > -1) { + result.cssFontStyle = "italic"; + } else { + result.cssFontStyle = "normal"; + } + + return JSON.stringify(result); } runtime.extensionStorage[extensionID].fonts[file[0].name] = url; @@ -2464,7 +2590,7 @@ SOFTWARE. } createTextGeometry(args) { const file = JSON.parse(runtime.extensionStorage[extensionID].fonts[args.FILE]); - if (!file) {console.warn(`No font named ${args.FILE}`); return;} + if (!file) { console.warn(`No font named ${args.FILE}`); return; } const font = three.TextLoader.parse(file); const geometry = new TextGeometry(args.TEXT, { font: font, @@ -2480,7 +2606,7 @@ SOFTWARE. async loadAudio(args) { const sounds = vm.editingTarget.getSounds(); - const file = sounds[sounds.findIndex(a=>a.name==args.FILE)].asset.data.buffer; + const file = sounds[sounds.findIndex(a => a.name == args.FILE)].asset.data.buffer; const audioContext = THREE.AudioContext.getContext(); const buffer = await audioContext.decodeAudioData(file.slice(0)); @@ -2489,14 +2615,14 @@ SOFTWARE. } addAudio(args) { - if (args.NAME == "scene") {console.warn(`Don't name objects "scene"!`); return;} + if (args.NAME == "scene") { console.warn(`Don't name objects "scene"!`); return; } const buffer = assets.audios.get(args.NAME); const sound = new THREE.PositionalAudio(three.AudioListener); sound.setBuffer(buffer); - if (this.objectExists({NAME: args.NAME})) { + if (this.objectExists({ NAME: args.NAME })) { console.warn(`Already existing object named ${args.NAME}. Will replace!`); const obj = assets.objects.get(args.NAME); obj.removeFromParent(); @@ -2510,34 +2636,35 @@ SOFTWARE. setAudio(args) { const sound = assets.objects.get(args.NAME); - if (!sound) {console.warn(`No sound named ${args.NAME}`); return;} + if (!sound) { console.warn(`No sound named ${args.NAME}`); return; } - if (args.DATA == "offset") { sound.offset = JSON.parse(args.DATA); return;} + if (args.DATA == "offset") { sound.offset = JSON.parse(args.DATA); return; } args.DATA ? sound[args.PROPERTY](JSON.parse(args.DATA)) : sound[args.PROPERTY](); } - doAudio(args) {this.setAudio(args);} - setAudioBoolean(args) {this.setAudio(args);} + doAudio(args) { this.setAudio(args); } + setAudioBoolean(args) { this.setAudio(args); } isAudio(args) { const sound = assets.objects.get(args.NAME); - if (!sound) {console.warn(`No sound named ${args.NAME}`); return;} + if (!sound) { console.warn(`No sound named ${args.NAME}`); return; } return sound[args.PROPERTY]; } getAudio(args) { const sound = assets.objects.get(args.NAME); - if (!sound) {console.warn(`No sound named ${args.NAME}`); return;} + if (!sound) { console.warn(`No sound named ${args.NAME}`); return; } - return JSON.stringify(sound[args.PROPERTY]());} + return JSON.stringify(sound[args.PROPERTY]()); + } stopAllAudios() { assets.objects.forEach( - a => {if (a.type == "Audio") {a.setLoopEnd(0); a.stop();}} + a => { if (a.type == "Audio") { a.setLoopEnd(0); a.stop(); } } ); } raycast(args) { const v3 = new THREE.Vector3().fromArray(JSON.parse(args.V)); - const d3 = new THREE.Vector3(0,0,-1); + const d3 = new THREE.Vector3(0, 0, -1); const e = new THREE.Euler().fromArray(JSON.parse(args.D)); e.order = args.ORDER; d3.applyEuler(e); @@ -2549,22 +2676,24 @@ SOFTWARE. raycastCamera(args) { const v2 = new THREE.Vector2().fromArray(JSON.parse(args.XY)); storedRaycast = new THREE.Raycaster(); - storedRaycast.setFromCamera(v2, camera ); + storedRaycast.setFromCamera(v2, camera); } + getRaycast(args) { - const r = storedRaycast.intersectObject( scene ); + const r = storedRaycast.intersectObject(scene); if (args.PROPERTY == "object") return JSON.stringify(r.map(i => i[args.PROPERTY].name)); else if (args.PROPERTY == "point" || args.PROPERTY == "normal") return JSON.stringify(r.map(i => i[args.PROPERTY].toArray())); else return JSON.stringify(r.map(i => i[args.PROPERTY])); } + isRaycast(args) { const obj = assets.objects.get(args.NAME); - if (!obj) {console.warn(`No object named ${args.NAME}`); return;} + if (!obj) { console.warn(`No object named ${args.NAME}`); return; } - const r = storedRaycast.intersectObject( obj ); + const r = storedRaycast.intersectObject(obj); return r.length ? true : false; } - + } Scratch.extensions.register(new ThreeJS()); @@ -2586,5 +2715,5 @@ SOFTWARE. .catch((err) => { console.error("Extension failed to load: ", err.message); }); - + })(Scratch);