From 41c301083dcff1dce69a1b21a9d69b1d508df12a Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Tue, 9 Apr 2019 15:35:34 -0400 Subject: [PATCH 01/17] working on 2D extrusion --- .idea/CSnap.iml | 13 + .idea/encodings.xml | 4 + .idea/libraries/R_User_Library.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 2186 ++++++++++++++++++++++++++++ gui.js | 54 +- 8 files changed, 2274 insertions(+), 10 deletions(-) create mode 100644 .idea/CSnap.iml create mode 100644 .idea/encodings.xml create mode 100644 .idea/libraries/R_User_Library.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/CSnap.iml b/.idea/CSnap.iml new file mode 100644 index 0000000000..bf708e32be --- /dev/null +++ b/.idea/CSnap.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000..15a15b218a --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/R_User_Library.xml b/.idea/libraries/R_User_Library.xml new file mode 100644 index 0000000000..71f5ff7491 --- /dev/null +++ b/.idea/libraries/R_User_Library.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..865611434f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..55a74be658 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..94a25f7f4c --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000000..6122e0fe61 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,2186 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + icos + icosa + config.asset + objl + cloud + saveclou + saveproj + saveProjec + upload + upload_project + saveas + menu.add + 3d + save + sprite.costume.is3D + sprite.costume + menu.additem + init + + + $PROJECT_DIR$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1142,16 +1088,18 @@ + - - + + - + @@ -1164,8 +1112,8 @@ - - + + @@ -1207,10 +1155,30 @@ + + + + + + + + + + + + + + + + + + + + - - + + @@ -1221,8 +1189,6 @@ - - @@ -1783,8 +1749,6 @@ - - @@ -2151,34 +2115,17 @@ - - - - - - - - - - - + - - + + - - - - - - - - - + + diff --git a/gui.js b/gui.js index 16c2eab638..7ccfee1510 100644 --- a/gui.js +++ b/gui.js @@ -7071,9 +7071,43 @@ ProjectDialogMorph.prototype.fixClassRoomItemColors = function () { }); }; -function doActualExtrusionOfImage(pathToImgWeWantToExtrude) { + +function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { console.log("inside the extrusion function"); console.log(pathToImgWeWantToExtrude); + console.log("now let's log the height and width of the image"); + console.log(pathToImgWeWantToExtrude.width); + console.log(pathToImgWeWantToExtrude.height); + + // temporary canvas to hold the image and retrieve its data + let tempCanvasToGetImageData = document.createElement('canvas'); + let ctx = tempCanvasToGetImageData.getContext("2d"); + tempCanvasToGetImageData.width = pathToImgWeWantToExtrude.width; + tempCanvasToGetImageData.height = pathToImgWeWantToExtrude.height; + ctx.drawImage(pathToImgWeWantToExtrude, 0, 0); // this should draw the image with its intrinsic size + + let myImageData = ctx.getImageData(x, y, pathToImgWeWantToExtrude.width, pathToImgWeWantToExtrude.height); + console.log(myImageData); + + console.log("my image data data is: "); + console.log(myImageData.data); + console.log(myImageData.width); + console.log(myImageData.height); + + for (let i=0;i Date: Wed, 10 Apr 2019 18:01:32 -0400 Subject: [PATCH 03/17] download is not working yay! Now need to use heightmap to make it 3D --- .idea/workspace.xml | 47 ++++++++++++++++++++++++++++++--------------- gui.js | 8 ++++++++ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4eb2ec3f41..ae67262cf6 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,6 @@ - - - + + + + + + + - - + + diff --git a/gui.js b/gui.js index 7ccfee1510..36c0e09f52 100644 --- a/gui.js +++ b/gui.js @@ -7109,6 +7109,14 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { console.log(myNewImage.width); console.log(myNewImage.height); + let a = document.createElement('a'); + a.href = myNewImage.src; + a.download = "image.png"; + console.log(a); + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + } function extruding2D(myself) { From 712dded6f2c5fdff543afec191d6552be8dc7902 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Wed, 10 Apr 2019 18:06:17 -0400 Subject: [PATCH 04/17] added comment, grayscale download now works, just need to use heightmap --- gui.js | 1 + 1 file changed, 1 insertion(+) diff --git a/gui.js b/gui.js index 36c0e09f52..9b406734fd 100644 --- a/gui.js +++ b/gui.js @@ -7109,6 +7109,7 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { console.log(myNewImage.width); console.log(myNewImage.height); + // We are creating a temp a tag to hold the image above which we created from our temp canvas above let a = document.createElement('a'); a.href = myNewImage.src; a.download = "image.png"; From 99d8f4a190b887c3e38443c3cdd1285c9dffd806 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Thu, 11 Apr 2019 13:29:30 -0400 Subject: [PATCH 05/17] added closure function to get heightMap of given image --- .idea/workspace.xml | 37 +++++++++++++++++++++++- gui.js | 68 ++++++++++++++++++++++++++------------------- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ae67262cf6..4d50d107cf 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,7 @@ - + +<<<<<<< Updated upstream +<<<<<<< Updated upstream +======= + +>>>>>>> Stashed changes @@ -1120,8 +1141,13 @@ +<<<<<<< Updated upstream +======= + + +>>>>>>> Stashed changes @@ -2139,8 +2165,17 @@ +<<<<<<< Updated upstream +======= + + + + + + +>>>>>>> Stashed changes diff --git a/gui.js b/gui.js index 9b406734fd..4e95f9fb4d 100644 --- a/gui.js +++ b/gui.js @@ -7073,12 +7073,6 @@ ProjectDialogMorph.prototype.fixClassRoomItemColors = function () { function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { - console.log("inside the extrusion function"); - console.log(pathToImgWeWantToExtrude); - console.log("now let's log the height and width of the image"); - console.log(pathToImgWeWantToExtrude.width); - console.log(pathToImgWeWantToExtrude.height); - // temporary canvas to hold the image and retrieve its data let tempCanvasToGetImageData = document.createElement('canvas'); let ctx = tempCanvasToGetImageData.getContext("2d"); @@ -7087,12 +7081,6 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { ctx.drawImage(pathToImgWeWantToExtrude, 0, 0); // this should draw the image with its intrinsic size let myImageData = ctx.getImageData(x, y, pathToImgWeWantToExtrude.width, pathToImgWeWantToExtrude.height); - console.log(myImageData); - - console.log("my image data data is: "); - console.log(myImageData.data); - console.log(myImageData.width); - console.log(myImageData.height); for (let i=0;i Date: Thu, 11 Apr 2019 15:15:40 -0400 Subject: [PATCH 06/17] added option to export the 2d extrusion as stl, still testing --- gui.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/gui.js b/gui.js index 4e95f9fb4d..065ab26b80 100644 --- a/gui.js +++ b/gui.js @@ -7072,6 +7072,8 @@ ProjectDialogMorph.prototype.fixClassRoomItemColors = function () { }; +// Everything below will be moved to a different JS but for now, lets leave it here for debugging + function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { // temporary canvas to hold the image and retrieve its data let tempCanvasToGetImageData = document.createElement('canvas'); @@ -7099,7 +7101,7 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { let a = document.createElement('a'); a.href = myNewImage.src; a.download = "image.png"; - console.log(a); + // console.log(a); // Uncomment code below to allow for download of grayscaled image // document.body.appendChild(a); // a.click(); @@ -7136,6 +7138,36 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { let heightMapDataForMyImage = heightMap(pathToImgWeWantToExtrude); console.log("Data returned from inner function is: " + heightMapDataForMyImage); + function createPlaneWithHeightMapData(data) { + let geometry = new THREE.PlaneGeometry(10, 10, 9, 9); + console.log(pathToImgWeWantToExtrude.src); + let texture = new THREE.ImageUtils.loadTexture(pathToImgWeWantToExtrude.src); + let material = new THREE.MeshLambertMaterial( {map: texture} ); + let plane = new THREE.Mesh(geometry, material); + + for (let i = 0; i < plane.geometry.vertices.length; i++){ + plane.geometry.vertices[i].z = data[i]; + } + return plane; + } + // Code below will return a three js plane mesh object from our function above + let returnedPlaneFromOurFunction = createPlaneWithHeightMapData(heightMapDataForMyImage); + console.log(returnedPlaneFromOurFunction); + + //TODO Create a Scene and Add the plane to the scene and export the Scene as STL + try { + let scene = new THREE.Scene(); + scene.add(returnedPlaneFromOurFunction); // Adding our returned plane mesh the function above + + let exporter = new THREE.STLExporter(); + let str = exporter.parse(scene); + + let blobbb = new Blob([str], {type: 'text/plain'}); + saveAs(blobbb, '2D.stl'); + console.log("Exported scene successfully"); + } catch (e) { + console.log("Exception from trying to export the 2D.stl file was: " + e); + } } function extruding2D(myself) { From 8eec8ce73141cefd908b8c75def4dbd0e33c0ff2 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Mon, 15 Apr 2019 12:22:38 -0400 Subject: [PATCH 07/17] Added Submenu to menus and moved loading costumes into new submenu --- gui.js | 64 +++++++++++++++-------- morphic.js | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 21 deletions(-) diff --git a/gui.js b/gui.js index 065ab26b80..9e9f1c95a1 100644 --- a/gui.js +++ b/gui.js @@ -2681,14 +2681,14 @@ IDE_Morph.prototype.projectMenu = function () { // // - menu.addItem( - 'Export 2D as 3D STL', - function () { - console.log('Export 2D as STL menu option was clicked'); - let myselfToPassToOurFunction = myself; - extruding2D(myselfToPassToOurFunction); - } - ); + // menu.addItem( + // 'Export 2D as 3D STL', + // function () { + // console.log('Export 2D as STL menu option was clicked'); + // let myselfToPassToOurFunction = myself; + // extruding2D(myselfToPassToOurFunction); + // } + // ); menu.addLine(); @@ -2805,9 +2805,24 @@ IDE_Morph.prototype.projectMenu = function () { 'show different default scripts' ); + let submenu = new MenuMorph(myself); + + // submenu.addItem('Testing', + // function () { + // console.log("submenu worked"); + // }, + // 'testing submenu' + // ); + + menu.addHoverItem( + 'Load Costume... >', + submenu + ); + + if (this.currentSprite instanceof SpriteMorph) { // SpriteMorph - menu.addItem( + submenu.addItem( '2D ' + localize(graphicsName) + '...', function () { @@ -2851,7 +2866,7 @@ IDE_Morph.prototype.projectMenu = function () { 'Select a 2D costume from the media library' ); - menu.addItem( + submenu.addItem( '3D ' + localize(graphicsName) + '...', function () { var dir = config.asset_path + graphicsName + '3D', @@ -7072,7 +7087,7 @@ ProjectDialogMorph.prototype.fixClassRoomItemColors = function () { }; -// Everything below will be moved to a different JS but for now, lets leave it here for debugging +// Everything below will be moved to a different JS file but for now, lets leave it here for debugging function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { // temporary canvas to hold the image and retrieve its data @@ -7108,13 +7123,15 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { // document.body.removeChild(a); // Function below gets our heightMap for a specified image passed in as an argument - function heightMap(image) { + function heightMap(image, scale) { let tempCanvasB = document.createElement( "canvas" ); tempCanvasB.width = image.width; tempCanvasB.height = image.height; let contextB = tempCanvasB.getContext("2d"); let size = image.width * image.height; + console.log(size + " = width * height of given image"); + let data = new Float32Array( size ); contextB.drawImage(image,0,0); @@ -7127,16 +7144,17 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { let pix = imgdata.data; let j=0; - for (let i = 0, n = pix.length; i < n; i += (4)) { + for (let i = 0, n = pix.length; i < n; i += 4) { let all = pix[i]+pix[i+1]+pix[i+2]; - data[j++] = all/30; + data[j++] = all/(12 * scale); } return data; } + // Get heightMap for our image - let heightMapDataForMyImage = heightMap(pathToImgWeWantToExtrude); - console.log("Data returned from inner function is: " + heightMapDataForMyImage); + let heightMapDataForMyImage = heightMap(pathToImgWeWantToExtrude, 2); + // console.log("Data returned from inner function is: " + heightMapDataForMyImage); function createPlaneWithHeightMapData(data) { let geometry = new THREE.PlaneGeometry(10, 10, 9, 9); @@ -7147,6 +7165,7 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { for (let i = 0; i < plane.geometry.vertices.length; i++){ plane.geometry.vertices[i].z = data[i]; + console.log(data[i]); } return plane; } @@ -7159,12 +7178,15 @@ function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { let scene = new THREE.Scene(); scene.add(returnedPlaneFromOurFunction); // Adding our returned plane mesh the function above - let exporter = new THREE.STLExporter(); - let str = exporter.parse(scene); + // let exporter = new THREE.STLExporter(); + // let str = exporter.parse(scene); + // + // let blobbb = new Blob([str], {type: 'text/plain'}); + // saveAs(blobbb, '2D.stl'); + // console.log("Exported scene successfully"); - let blobbb = new Blob([str], {type: 'text/plain'}); - saveAs(blobbb, '2D.stl'); - console.log("Exported scene successfully"); + // console.log(returnedPlaneFromOurFunction.geometry.vertices); + console.log(scene.children); } catch (e) { console.log("Exception from trying to export the 2D.stl file was: " + e); } diff --git a/morphic.js b/morphic.js index a9e8ad5358..48970f4252 100644 --- a/morphic.js +++ b/morphic.js @@ -10869,3 +10869,150 @@ WorldMorph.prototype.togglePreferences = function () { MorphicPreferences = standardSettings; } }; + +// Adding hover item +MenuMorph.prototype.addHoverItem = function(labelString, action) { + this.items.push(new MenuHoverItemMorph(localize(labelString || 'close'), action, this)); +}; + +MenuMorph.prototype.drawNew = function () { + var myself = this, + item, + fb, + x, + y, + isLine = false; + + this.children.forEach(function (m) { + m.destroy(); + }); + this.children = []; + if (!this.isListContents) { + this.edge = MorphicPreferences.isFlat ? 0 : 5; + this.border = MorphicPreferences.isFlat ? 1 : 2; + } + this.color = new Color(255, 255, 255); + this.borderColor = new Color(60, 60, 60); + this.silentSetExtent(new Point(0, 0)); + + y = 2; + x = this.left() + 4; + if (!this.isListContents) { + if (this.title) { + this.createLabel(); + this.label.setPosition(this.bounds.origin.add(4)); + this.add(this.label); + y = this.label.bottom(); + } else { + y = this.top() + 4; + } + } + y += 1; + this.items.forEach(function (tuple) { + isLine = false; + if (tuple instanceof StringFieldMorph || + tuple instanceof ColorPickerMorph || + tuple instanceof SliderMorph || + tuple instanceof MenuHoverItemMorph) { // added + item = tuple; + } else if (tuple[0] === 0) { + isLine = true; + item = new Morph(); + item.color = myself.borderColor; + item.setHeight(tuple[1]); + } else { + item = new MenuItemMorph( + myself.target, + tuple[1], + tuple[0], + myself.fontSize || MorphicPreferences.menuFontSize, + MorphicPreferences.menuFontName, + myself.environment, + tuple[2], // bubble help hint + tuple[3], // color + tuple[4], // bold + tuple[5], // italic + tuple[6] // doubleclick action + ); + } + if (isLine) { + y += 1; + } + item.setPosition(new Point(x, y)); + myself.add(item); + y = y + item.height(); + if (isLine) { + y += 1; + } + }); + + fb = this.fullBounds(); + this.silentSetExtent(fb.extent().add(4)); + this.adjustWidths(); + MenuMorph.uber.drawNew.call(this); +}; + +var MenuHoverItemMorph; +MenuHoverItemMorph.prototype = new MenuItemMorph(); +MenuHoverItemMorph.prototype.constructor = MenuHoverItemMorph; +MenuHoverItemMorph.uber = MenuItemMorph.prototype; + +function MenuHoverItemMorph(labelString, submenu, parentMenu) { + var myself = this; + + this.submenu = submenu; + this.parentMenu = parentMenu; + + this.init( + parentMenu.target, + myself.revealSubmenu, + labelString, + parentMenu.fontSize, + MorphicPreferences.menuFontName, + parentMenu.environment, + null, + null, + false, + false, + null + ); +}; + +MenuHoverItemMorph.prototype.revealSubmenu = function() { + var myself = this; + + this.image = this.highlightImage; + this.submenu.drawNew(); + this.submenu.setPosition(this.topRight()); + this.submenu.addShadow(new Point(2, 2), 80); + this.submenu.keepWithin(world); + if (this.submenu.items.length < 1 && !this.submenu.title) { // don't show empty menus + return; + } + world.add(this.submenu); + world.activeMenu = this.submenu; + this.submenu.world = world; // optionally enable keyboard support + this.submenu.fullChanged(); + this.changed(); + + this.submenu.mouseLeave = function() { + this.destroy(); + if (!myself.boundingBox().containsPoint(world.hand.position())) { + myself.image = myself.normalImage; + myself.changed(); + } + world.activeMenu = myself.parentMenu; + } +}; + +MenuHoverItemMorph.prototype.mouseEnter = MenuHoverItemMorph.prototype.revealSubmenu; +MenuHoverItemMorph.prototype.mouseClickLeft = MenuHoverItemMorph.prototype.revealSubmenu; + +MenuHoverItemMorph.prototype.mouseLeave = function() { + if (!this.submenu.boundingBox().containsPoint(world.hand.position())) { + this.submenu.destroy(); + this.image = this.normalImage; + this.changed(); + world.activeMenu = this.parentMenu; + } +}; From 136221549841ed0e3ca5329c2a9a2df7cc0f38c7 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Fri, 19 Apr 2019 15:10:59 -0400 Subject: [PATCH 08/17] working to add custom polygon block --- Chinedu_Changes_To_IDE_Morph.js | 10 ++++++++++ gui.js | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 Chinedu_Changes_To_IDE_Morph.js diff --git a/Chinedu_Changes_To_IDE_Morph.js b/Chinedu_Changes_To_IDE_Morph.js new file mode 100644 index 0000000000..d2cc1d5710 --- /dev/null +++ b/Chinedu_Changes_To_IDE_Morph.js @@ -0,0 +1,10 @@ +IDE_Morph.prototype.addCustom3DPolygonBlock = function (){ + //TODO Add function to add Generic Polygon Block as Costume + // There are TWO ways I could do this: + // One way is to create the polygon mesh from this function and add it to the stage as a costume but I will + // need to figure out how any GUI blocks I create will interact with this polygon + // Another way is to import an exported threejs/editor geometry/shape as an obj or via json + + console.log("We will add a custom polygon block to the sprite from this function"); + +}; \ No newline at end of file diff --git a/gui.js b/gui.js index 9e9f1c95a1..9cbb5061b3 100644 --- a/gui.js +++ b/gui.js @@ -2819,6 +2819,10 @@ IDE_Morph.prototype.projectMenu = function () { submenu ); + submenu.addItem('Custom 3D Block Shape', + this.addCustom3DPolygonBlock() + ); + if (this.currentSprite instanceof SpriteMorph) { // SpriteMorph From 86bc345821d527e56abb7c7e56f7c016f95e8920 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Sat, 20 Apr 2019 17:25:22 -0400 Subject: [PATCH 09/17] still working --- Chinedu_Changes_To_IDE_Morph.js | 1 + Costumes3D/list.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Chinedu_Changes_To_IDE_Morph.js b/Chinedu_Changes_To_IDE_Morph.js index d2cc1d5710..af19e27f87 100644 --- a/Chinedu_Changes_To_IDE_Morph.js +++ b/Chinedu_Changes_To_IDE_Morph.js @@ -4,6 +4,7 @@ IDE_Morph.prototype.addCustom3DPolygonBlock = function (){ // One way is to create the polygon mesh from this function and add it to the stage as a costume but I will // need to figure out how any GUI blocks I create will interact with this polygon // Another way is to import an exported threejs/editor geometry/shape as an obj or via json + // https://threejs.org/docs/#api/en/geometries/IcosahedronGeometry console.log("We will add a custom polygon block to the sprite from this function"); diff --git a/Costumes3D/list.html b/Costumes3D/list.html index 87676ee949..5e7285215f 100644 --- a/Costumes3D/list.html +++ b/Costumes3D/list.html @@ -19,7 +19,7 @@

Index of /~moorthy/Snap--Build-Your-Own-Blocks-real-3d/Costumes3D

[   ]stork.js2014-10-21 11:26 74K  [   ]torus.js2014-10-21 11:26 41K  - +[   ]prism.js2019-03-25 14:58  
From 53ad795f87a9d250a70248c92af83234be985ad4 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Mon, 22 Apr 2019 10:28:26 -0400 Subject: [PATCH 10/17] added function to add polygon (icosahedron) but code throws exception inside wearCostume function in objects.js --- Chinedu_Changes_To_IDE_Morph.js | 56 +++++-- Costumes3D/list.html | 3 +- Costumes3D/prism.js | 0 gui.js | 259 +++++++++++++++++++------------- objects.js | 2 +- 5 files changed, 200 insertions(+), 120 deletions(-) delete mode 100644 Costumes3D/prism.js diff --git a/Chinedu_Changes_To_IDE_Morph.js b/Chinedu_Changes_To_IDE_Morph.js index af19e27f87..cbba80bf31 100644 --- a/Chinedu_Changes_To_IDE_Morph.js +++ b/Chinedu_Changes_To_IDE_Morph.js @@ -1,11 +1,45 @@ -IDE_Morph.prototype.addCustom3DPolygonBlock = function (){ - //TODO Add function to add Generic Polygon Block as Costume - // There are TWO ways I could do this: - // One way is to create the polygon mesh from this function and add it to the stage as a costume but I will - // need to figure out how any GUI blocks I create will interact with this polygon - // Another way is to import an exported threejs/editor geometry/shape as an obj or via json - // https://threejs.org/docs/#api/en/geometries/IcosahedronGeometry - - console.log("We will add a custom polygon block to the sprite from this function"); - -}; \ No newline at end of file +// /** +// * function below allows for adding icosahedron shape to scene +// * @param myself CSnap world +// * @param radius default is set to 5 +// * @param detail default is set to 1, changing this will effectively make this a sphere so be careful with this +// * @param colorParam default is set to blue but we can pass in any color we like +// * for reference see https://threejs.org/docs/#api/en/geometries/IcosahedronGeometry +// */ +// IDE_Morph.prototype.addCustom3DPolygonIcosahedron = function (myself, radius, detail, colorParam){ +// +// let icosahedron = function () { +// if (radius === undefined || detail === undefined){ +// radius = 5; +// detail = 0; +// } +// +// let enteredColorToLowerCase = colorParam.toLowerCase(); +// let color = ""; +// let emissive = ""; +// +// if (enteredColorToLowerCase !== undefined){ +// color = new THREE.Color(enteredColorToLowerCase); +// emissive = color; +// } else { +// color = new THREE.Color( 'blue' ); +// emissive = color; +// } +// +// console.log(color); +// console.log(emissive); +// +// +// let geometry = new THREE.IcosahedronGeometry(radius, detail); +// let material = new THREE.MeshLambertMaterial({ emissive: emissive, color: color }); +// return new THREE.Mesh(geometry, material); +// }; +// +// //TODO Add icosahedron as a costume to CSnap's stage. +// // Unsure about below, let's see if it works +// +// this.currentSprite.addCostume(icosahedron()); +// this.currentSprite.wearCostume(icosahedron()); +// this.spriteBar.tabBar.tabTo('costumes'); +// this.hasChangedMedia = true; +// }; \ No newline at end of file diff --git a/Costumes3D/list.html b/Costumes3D/list.html index 5e7285215f..dfe8ea0703 100644 --- a/Costumes3D/list.html +++ b/Costumes3D/list.html @@ -18,8 +18,7 @@

Index of /~moorthy/Snap--Build-Your-Own-Blocks-real-3d/Costumes3D

[   ]sphere.js2014-10-21 11:26 160K  [   ]stork.js2014-10-21 11:26 74K  [   ]torus.js2014-10-21 11:26 41K  - -[   ]prism.js2019-03-25 14:58   + 
diff --git a/Costumes3D/prism.js b/Costumes3D/prism.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/gui.js b/gui.js index 9cbb5061b3..72bfcc9a49 100644 --- a/gui.js +++ b/gui.js @@ -2819,8 +2819,9 @@ IDE_Morph.prototype.projectMenu = function () { submenu ); - submenu.addItem('Custom 3D Block Shape', - this.addCustom3DPolygonBlock() + // this will be changed to a block but just adding this here for now + submenu.addItem('Custom 3D Polygon Shapes', + myself.dropped3dObject(myself.addCustom3DPolygonIcosahedron(myself, 5, 0, "red")) ); @@ -7091,116 +7092,162 @@ ProjectDialogMorph.prototype.fixClassRoomItemColors = function () { }; -// Everything below will be moved to a different JS file but for now, lets leave it here for debugging - -function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { - // temporary canvas to hold the image and retrieve its data - let tempCanvasToGetImageData = document.createElement('canvas'); - let ctx = tempCanvasToGetImageData.getContext("2d"); - tempCanvasToGetImageData.width = pathToImgWeWantToExtrude.width; - tempCanvasToGetImageData.height = pathToImgWeWantToExtrude.height; - ctx.drawImage(pathToImgWeWantToExtrude, 0, 0); // this should draw the image with its intrinsic size - - let myImageData = ctx.getImageData(x, y, pathToImgWeWantToExtrude.width, pathToImgWeWantToExtrude.height); - - for (let i=0;i Date: Mon, 22 Apr 2019 10:57:03 -0400 Subject: [PATCH 11/17] renamed submenu --- gui.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui.js b/gui.js index 72bfcc9a49..f11ad6fcb6 100644 --- a/gui.js +++ b/gui.js @@ -2820,7 +2820,7 @@ IDE_Morph.prototype.projectMenu = function () { ); // this will be changed to a block but just adding this here for now - submenu.addItem('Custom 3D Polygon Shapes', + submenu.addItem('Custom 3D Polygon Shape', myself.dropped3dObject(myself.addCustom3DPolygonIcosahedron(myself, 5, 0, "red")) ); From 1a13a496e9f61e8f2a5c13b4612a065807f197ce Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Mon, 22 Apr 2019 12:43:06 -0400 Subject: [PATCH 12/17] still debugging --- gui.js | 863 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 438 insertions(+), 425 deletions(-) diff --git a/gui.js b/gui.js index f11ad6fcb6..79748adf64 100644 --- a/gui.js +++ b/gui.js @@ -233,8 +233,8 @@ IDE_Morph.prototype.init = function (isAutoFill) { // override inherited properites: this.color = this.backgroundColor; - this.corralBarOldX = ""; - this.corralBarOldY = ""; + this.corralBarOldX = ""; + this.corralBarOldY = ""; }; IDE_Morph.prototype.openIn = function (world) { @@ -314,7 +314,7 @@ IDE_Morph.prototype.openIn = function (world) { function(response) { myself.source = 'cloud'; myself.droppedText(response); - }, myself.cloudError()); + }, myself.cloudError()); } if(config.demo !== undefined) { @@ -344,17 +344,17 @@ IDE_Morph.prototype.openIn = function (world) { if (location.hash.substr(0, 6) === '#open:') { hash = location.hash.substr(6); if (hash.charAt(0) === '%' - || hash.search(/\%(?:[0-9a-f]{2})/i) > -1) { + || hash.search(/\%(?:[0-9a-f]{2})/i) > -1) { hash = decodeURIComponent(hash); } if (contains( - ['project', 'blocks', 'sprites', 'snapdata'].map( - function (each) { - return hash.substr(0, 8).indexOf(each); - } - ), - 1 - )) { + ['project', 'blocks', 'sprites', 'snapdata'].map( + function (each) { + return hash.substr(0, 8).indexOf(each); + } + ), + 1 + )) { this.droppedText(hash); } else { this.droppedText(getURL(hash)); @@ -362,7 +362,7 @@ IDE_Morph.prototype.openIn = function (world) { } else if (location.hash.substr(0, 5) === '#run:') { hash = location.hash.substr(5); if (hash.charAt(0) === '%' - || hash.search(/\%(?:[0-9a-f]{2})/i) > -1) { + || hash.search(/\%(?:[0-9a-f]{2})/i) > -1) { hash = decodeURIComponent(hash); } if (hash.substr(0, 8) === '') { @@ -483,7 +483,7 @@ IDE_Morph.prototype.createLogo = function () { gradient.addColorStop(0, 'black'); gradient.addColorStop(0.5, myself.frameColor.toString()); context.fillStyle = MorphicPreferences.isFlat ? - myself.frameColor.toString() : gradient; + myself.frameColor.toString() : gradient; context.fillRect(0, 0, this.width(), this.height()); if (this.texture) { this.drawTexture(this.texture); @@ -777,29 +777,29 @@ IDE_Morph.prototype.createControlBar = function () { this.controlBar.add(settingsButton); this.controlBar.settingsButton = settingsButton; // for menu positioning - // goalImagesButton + // goalImagesButton var goals = this.precacheGoals(); if(goals) { - button = new PushButtonMorph( - this, - 'goalImagesMenu', ' Goals ' - ); - button.corner = 12; - button.color = colors[0]; - button.highlightColor = colors[1]; - button.pressColor = colors[2]; - button.labelMinExtent = new Point(36, 18); - button.padding = 0; - button.labelShadowOffset = new Point(-1, -1); - button.labelShadowColor = colors[1]; - button.labelColor = this.buttonLabelColor; - button.contrast = this.buttonContrast; - button.drawNew(); - button.fixLayout(); - goalImagesButton = button; - this.controlBar.add(goalImagesButton); - this.controlBar.goalImagesButton = goalImagesButton; // for menu positioning + button = new PushButtonMorph( + this, + 'goalImagesMenu', ' Goals ' + ); + button.corner = 12; + button.color = colors[0]; + button.highlightColor = colors[1]; + button.pressColor = colors[2]; + button.labelMinExtent = new Point(36, 18); + button.padding = 0; + button.labelShadowOffset = new Point(-1, -1); + button.labelShadowColor = colors[1]; + button.labelColor = this.buttonLabelColor; + button.contrast = this.buttonContrast; + button.drawNew(); + button.fixLayout(); + goalImagesButton = button; + this.controlBar.add(goalImagesButton); + this.controlBar.goalImagesButton = goalImagesButton; // for menu positioning } // goalImagesButton @@ -870,16 +870,16 @@ IDE_Morph.prototype.createControlBar = function () { ); if(goals) { - goalImagesButton.setCenter(myself.controlBar.center()); - goalImagesButton.setLeft(this.left()); + goalImagesButton.setCenter(myself.controlBar.center()); + goalImagesButton.setLeft(this.left()); - settingsButton.setCenter(myself.controlBar.center()); - settingsButton.setLeft(goalImagesButton.left() - padding - 40); + settingsButton.setCenter(myself.controlBar.center()); + settingsButton.setLeft(goalImagesButton.left() - padding - 40); } else { - settingsButton.setCenter(myself.controlBar.center()); - settingsButton.setLeft(this.left() - 40); + settingsButton.setCenter(myself.controlBar.center()); + settingsButton.setLeft(this.left() - 40); } goalImagesButton.setCenter(myself.controlBar.center()); @@ -898,7 +898,7 @@ IDE_Morph.prototype.createControlBar = function () { this.controlBar.updateLabel = function () { var suffix = myself.world().isDevMode ? - ' - ' + localize('development mode') : ''; + ' - ' + localize('development mode') : ''; if (this.label) { this.label.destroy(); @@ -922,7 +922,7 @@ IDE_Morph.prototype.createControlBar = function () { this.add(this.label); this.label.setCenter(this.center()); //if(goals) { - this.label.setLeft(this.goalImagesButton.right() + padding); + this.label.setLeft(this.goalImagesButton.right() + padding); //} //else { // this.label.setLeft(this.settingsButton.right() + padding); @@ -1009,8 +1009,8 @@ IDE_Morph.prototype.createCategories = function () { myself.categories.setHeight( (rows + 1) * yPadding - + rows * buttonHeight - + 2 * border + + rows * buttonHeight + + 2 * border ); } @@ -1143,7 +1143,7 @@ IDE_Morph.prototype.createSpriteBar = function () { button.setPosition(myself.spriteBar.position().add(2)); button.setTop(button.top() + ((rotationStyleButtons.length - 1) * (button.height() + 2)) - ); + ); myself.spriteBar.add(button); if (myself.currentSprite instanceof StageMorph) { button.hide(); @@ -1222,7 +1222,7 @@ IDE_Morph.prototype.createSpriteBar = function () { checkbox.pressColor = tabColors[1]; checkbox.tick.shadowOffset = MorphicPreferences.isFlat ? - new Point() : new Point(-1, -1); + new Point() : new Point(-1, -1); checkbox.tick.shadowColor = new Color(); // black checkbox.tick.color = this.buttonLabelColor; checkbox.tick.isBold = false; @@ -1482,15 +1482,15 @@ IDE_Morph.prototype.createCorralBar = function () { this.corralBar.add(paintbutton); xlabel = new StringMorph( - "X: 0", - 24, - 'sans-serif', - true, - false, - false, - MorphicPreferences.isFlat ? null : new Point(2, 1), - this.frameColor.darker(this.buttonContrast) - ); + "X: 0", + 24, + 'sans-serif', + true, + false, + false, + MorphicPreferences.isFlat ? null : new Point(2, 1), + this.frameColor.darker(this.buttonContrast) + ); xlabel.color = this.buttonLabelColor; xlabel.drawNew(); @@ -1501,15 +1501,15 @@ IDE_Morph.prototype.createCorralBar = function () { this.corralBar.add(xlabel); ylabel = new StringMorph( - "Y: 0", - 24, - 'sans-serif', - true, - false, - false, - MorphicPreferences.isFlat ? null : new Point(2, 1), - this.frameColor.darker(this.buttonContrast) - ); + "Y: 0", + 24, + 'sans-serif', + true, + false, + false, + MorphicPreferences.isFlat ? null : new Point(2, 1), + this.frameColor.darker(this.buttonContrast) + ); ylabel.color = this.buttonLabelColor; ylabel.drawNew(); ylabel.setLeft( @@ -1519,40 +1519,40 @@ IDE_Morph.prototype.createCorralBar = function () { this.corralBar.add(ylabel); this.corralBar.step = function() { - this.parent.updateCorralBar(); + this.parent.updateCorralBar(); } }; IDE_Morph.prototype.updateCorralBar = function () { - var MouseX = this.stage.reportMouseX(); - var MouseY = this.stage.reportMouseY(); + var MouseX = this.stage.reportMouseX(); + var MouseY = this.stage.reportMouseY(); Morph.prototype.trackChanges = false; - if(this.isSmallStage || - MouseX > StageMorph.prototype.dimensions.x / 2 || - MouseY > StageMorph.prototype.dimensions.y / 2 || - MouseX < StageMorph.prototype.dimensions.x / -2 || - MouseY < StageMorph.prototype.dimensions.y / -2) - { - this.corralBar.children[2].text = ""; - this.corralBar.children[3].text = ""; - } else { - this.corralBar.children[2].text = "X: " + this.stage.reportMouseX(); - this.corralBar.children[3].text = "Y: " + this.stage.reportMouseY(); - } - Morph.prototype.trackChanges = true; - - //update only if the coordinates have changed to save CPU - if(this.corralBarOldX != this.corralBar.children[2].text || this.corralBarOldY != this.corralBar.children[3].text) - { - this.corralBarOldX = this.corralBar.children[2].text; - this.corralBarOldY = this.corralBar.children[3].text; - this.corralBar.children[2].drawNew(); - this.corralBar.children[3].drawNew(); - - this.corralBar.changed(); - } + if(this.isSmallStage || + MouseX > StageMorph.prototype.dimensions.x / 2 || + MouseY > StageMorph.prototype.dimensions.y / 2 || + MouseX < StageMorph.prototype.dimensions.x / -2 || + MouseY < StageMorph.prototype.dimensions.y / -2) + { + this.corralBar.children[2].text = ""; + this.corralBar.children[3].text = ""; + } else { + this.corralBar.children[2].text = "X: " + this.stage.reportMouseX(); + this.corralBar.children[3].text = "Y: " + this.stage.reportMouseY(); + } + Morph.prototype.trackChanges = true; + + //update only if the coordinates have changed to save CPU + if(this.corralBarOldX != this.corralBar.children[2].text || this.corralBarOldY != this.corralBar.children[3].text) + { + this.corralBarOldX = this.corralBar.children[2].text; + this.corralBarOldY = this.corralBar.children[3].text; + this.corralBar.children[2].drawNew(); + this.corralBar.children[3].drawNew(); + + this.corralBar.changed(); + } }; @@ -1687,7 +1687,7 @@ IDE_Morph.prototype.fixLayout = function (situation) { this.stage.setScale(Math.floor(Math.min( (this.width() - padding * 2) / this.stage.dimensions.x, (this.height() - this.controlBar.height() * 2 - padding * 2) - / this.stage.dimensions.y + / this.stage.dimensions.y ) * 10) / 10); this.stage.setCenter(this.center()); } else { @@ -1751,19 +1751,19 @@ IDE_Morph.prototype.setExtent = function (point) { this.controlBar.height() + 10 ); } else { - /* // auto-switches to small stage mode, commented out b/c I don't like it - if (point.x < 910) { - this.isSmallStage = true; - this.stageRatio = 0.5; - } - */ - minExt = this.isSmallStage ? - padding.add(StageMorph.prototype.dimensions.divideBy(2)) - : padding.add(StageMorph.prototype.dimensions); -/* + /* // auto-switches to small stage mode, commented out b/c I don't like it + if (point.x < 910) { + this.isSmallStage = true; + this.stageRatio = 0.5; + } + */ minExt = this.isSmallStage ? - new Point(700, 350) : new Point(910, 490); -*/ + padding.add(StageMorph.prototype.dimensions.divideBy(2)) + : padding.add(StageMorph.prototype.dimensions); + /* + minExt = this.isSmallStage ? + new Point(700, 350) : new Point(910, 490); + */ } ext = point.max(minExt); IDE_Morph.uber.setExtent.call(this, ext); @@ -1797,10 +1797,10 @@ IDE_Morph.prototype.droppedImage = function (aCanvas, name, url) { this.inform( 'Unable to import this image', 'The picture you wish to import has been\n' + - 'tainted by a restrictive cross-origin policy\n' + - 'making it unusable for costumes in Snap!. \n\n' + - 'Try downloading this picture first to your\n' + - 'computer, and import it from there.' + 'tainted by a restrictive cross-origin policy\n' + + 'making it unusable for costumes in Snap!. \n\n' + + 'Try downloading this picture first to your\n' + + 'computer, and import it from there.' ); return; } @@ -2214,25 +2214,25 @@ IDE_Morph.prototype.snapMenu = function () { window.open('http://community.csdt.rpi.edu/', 'CSnapWebsite'); } ); -/* XXX: If we really need this in the future, we should link to the CSnap GitHub page. - * - * menu.addItem( - * 'Download source', - * function () { - * window.open( - * 'http://snap.berkeley.edu/snapsource/snap.zip', - * 'CSnapSource' - * ); - * } - * ); - */ + /* XXX: If we really need this in the future, we should link to the CSnap GitHub page. + * + * menu.addItem( + * 'Download source', + * function () { + * window.open( + * 'http://snap.berkeley.edu/snapsource/snap.zip', + * 'CSnapSource' + * ); + * } + * ); + */ if (world.isDevMode) { menu.addLine(); menu.addItem( 'Switch back to user mode', 'switchToUserMode', 'disable deep-Morphic\ncontext menus' - + '\nand show user-friendly ones', + + '\nand show user-friendly ones', new Color(0, 100, 0) ); } else if (world.currentKey === 16) { // shift-click @@ -2241,7 +2241,7 @@ IDE_Morph.prototype.snapMenu = function () { 'Switch to dev mode', 'switchToDevMode', 'enable Morphic\ncontext menus\nand inspectors,' - + '\nnot user-friendly!', + + '\nnot user-friendly!', new Color(100, 0, 0) ); } @@ -2377,7 +2377,7 @@ IDE_Morph.prototype.goalImagesMenu = function() { pos = this.controlBar.goalImagesButton.bottomLeft(), shiftClicked = (world.currentKey === 16); - function addPreference(label, toggle, test, onHint, offHint, hide) { + function addPreference(label, toggle, test, onHint, offHint, hide) { var on = '\u2611 ', off = '\u2610 '; if (!hide || shiftClicked) { @@ -2609,7 +2609,7 @@ IDE_Morph.prototype.projectMenu = function () { world = this.world(), pos = this.controlBar.projectButton.bottomLeft(), graphicsName = this.currentSprite instanceof SpriteMorph ? - 'Costumes' : 'Backgrounds', + 'Costumes' : 'Backgrounds', shiftClicked = (world.currentKey === 16); menu = new MenuMorph(this); @@ -2732,7 +2732,7 @@ IDE_Morph.prototype.projectMenu = function () { menu.addItem( shiftClicked ? - 'Export project as plain text...' : 'Export project...', + 'Export project as plain text...' : 'Export project...', function () { if (myself.projectName) { myself.exportProject(myself.projectName, shiftClicked); @@ -2775,8 +2775,8 @@ IDE_Morph.prototype.projectMenu = function () { function loadLib(name) { var url = 'https://community.csdt.rpi.edu/csnapsource/libraries/' - + name - + '.xml'; + + name + + '.xml'; myself.droppedText(myself.getURL(url), name); } @@ -2816,12 +2816,15 @@ IDE_Morph.prototype.projectMenu = function () { menu.addHoverItem( 'Load Costume... >', - submenu + submenu ); + // console.log(myself); + // console.log(myself.parent); + // this will be changed to a block but just adding this here for now submenu.addItem('Custom 3D Polygon Shape', - myself.dropped3dObject(myself.addCustom3DPolygonIcosahedron(myself, 5, 0, "red")) + addCustom3DPolygonIcosahedron(myself, 5, 0, "red") ); @@ -2833,22 +2836,22 @@ IDE_Morph.prototype.projectMenu = function () { let directory = config.asset_path + graphicsName, - names = myself.getCostumesList(directory+'/costumes.html'), // Passing in a url or in this + names = myself.getCostumesList(directory+'/costumes.html'), // Passing in a url or in this // a path to the getCostumesList function returns // an array of images gathered from a html page using a regular expression to filter out the name from // from the // i.e alonzo etc, whatever url you pass into here, this method will make a get request - libMenu = new MenuMorph( - myself, - localize('Import') + ' ' + '2D ' + localize(graphicsName) - ); + libMenu = new MenuMorph( + myself, + localize('Import') + ' ' + '2D ' + localize(graphicsName) + ); function loadCostume(name) { var url = directory + '/' + name, - img = new Image(); + img = new Image(); img.onload = function () { var canvas = newCanvas(new Point(img.width, img.height)); @@ -2875,11 +2878,11 @@ IDE_Morph.prototype.projectMenu = function () { '3D ' + localize(graphicsName) + '...', function () { var dir = config.asset_path + graphicsName + '3D', - names = myself.getCostumesList(dir+'/list.html'), - libMenu = new MenuMorph( - myself, - localize('Import') + ' ' + '3D ' + localize(graphicsName) - ); + names = myself.getCostumesList(dir+'/list.html'), + libMenu = new MenuMorph( + myself, + localize('Import') + ' ' + '3D ' + localize(graphicsName) + ); function loadCostume(name) { var url = dir + '/' + name; @@ -2888,7 +2891,7 @@ IDE_Morph.prototype.projectMenu = function () { request.open('GET', url, false); request.send(); if (request.status === 200) { - myself.dropped3dObject(name, 'data:text/json,'+encodeURIComponent(request.responseText)); + myself.dropped3dObject(name, 'data:text/json,'+encodeURIComponent(request.responseText)); } } catch(e){} @@ -2913,11 +2916,11 @@ IDE_Morph.prototype.projectMenu = function () { 'Textures...', // TODO: localize this function () { var dir = 'Textures', - names = myself.getTexturesList(dir), - libMenu = new MenuMorph( - myself, - localize('Import') + ' ' + dir - ); + names = myself.getTexturesList(dir), + libMenu = new MenuMorph( + myself, + localize('Import') + ' ' + dir + ); function loadTexture(name) { var url = dir + '/' + name; @@ -2945,15 +2948,15 @@ IDE_Morph.prototype.projectMenu = function () { localize(graphicsName) + '...', function () { var dir = graphicsName, - names = myself.getCostumesList(dir), - libMenu = new MenuMorph( - myself, - localize('Import') + ' ' + localize(dir) - ); + names = myself.getCostumesList(dir), + libMenu = new MenuMorph( + myself, + localize('Import') + ' ' + localize(dir) + ); function loadCostume(name) { var url = dir + '/' + name, - img = new Image(); + img = new Image(); img.onload = function () { var canvas = newCanvas(new Point(img.width, img.height)); canvas.getContext('2d').drawImage(img, 0, 0); @@ -3081,7 +3084,7 @@ IDE_Morph.prototype.aboutCSnap = function () { for (module in modules) { if (Object.prototype.hasOwnProperty.call(modules, module)) { versions += ('\n' + module + ' (' + - modules[module] + ')'); + modules[module] + ')'); } } if (versions !== '') { @@ -3358,7 +3361,7 @@ IDE_Morph.prototype.exportGlobalBlocks = function () { this.inform( 'Export blocks', 'this project doesn\'t have any\n' - + 'custom global blocks yet' + + 'custom global blocks yet' ); } }; @@ -3602,9 +3605,9 @@ IDE_Morph.prototype.switchToDevMode = function () { delete world.reactToDropOf; this.showMessage( 'entering development mode.\n\n' - + 'error catching is turned off,\n' - + 'use the browser\'s web console\n' - + 'to see error messages.' + + 'error catching is turned off,\n' + + 'use the browser\'s web console\n' + + 'to see error messages.' ); }; @@ -3887,7 +3890,7 @@ IDE_Morph.prototype.languageMenu = function () { SnapTranslator.languages().forEach(function (lang) { menu.addItem( (SnapTranslator.language === lang ? '\u2713 ' : ' ') + - SnapTranslator.languageName(lang), + SnapTranslator.languageName(lang), function () {myself.setLanguage(lang); } ); }); @@ -3908,7 +3911,7 @@ IDE_Morph.prototype.setLanguage = function (lang, callback) { translation = document.createElement('script'); translation.id = 'language'; translation.onload = function () { - myself.reflectLanguage(lang, callback); + myself.reflectLanguage(lang, callback); }; document.head.appendChild(translation); translation.src = src; @@ -3987,15 +3990,15 @@ IDE_Morph.prototype.userSetBlocksScale = function () { sample.add(shield); action = function (num) { - /* - var c; - blck.setScale(num); - blck.drawNew(); - blck.setSpec(blck.blockSpec); - c = blck.inputs()[0]; - c.setScale(num); - c.nestedBlock(scrpt); - */ + /* + var c; + blck.setScale(num); + blck.drawNew(); + blck.setSpec(blck.blockSpec); + c = blck.inputs()[0]; + c.setScale(num); + c.nestedBlock(scrpt); + */ scrpt.blockSequence().forEach(function (block) { block.setScale(num); block.drawNew(); @@ -4237,22 +4240,22 @@ IDE_Morph.prototype.exportProjectAsSTL = function () { // Testing to see what world is console.log(world); try { - menu = this.showMessage('Exporting as STL'); - let scene = copy(this.stage.scene); - // console.log("Scene is: " + scene); + menu = this.showMessage('Exporting as STL'); + let scene = copy(this.stage.scene); + // console.log("Scene is: " + scene); - let exporter = new THREE.STLExporter(); - // console.log("Exporter: " + exporter); + let exporter = new THREE.STLExporter(); + // console.log("Exporter: " + exporter); - let exportedScene = exporter.parse(scene); - let blob = new Blob( [exportedScene], { type: 'text/plain'}); - saveAs(blob, (this.projectName ? this.projectName : '3DCSDT') + '.stl'); + let exportedScene = exporter.parse(scene); + let blob = new Blob( [exportedScene], { type: 'text/plain'}); + saveAs(blob, (this.projectName ? this.projectName : '3DCSDT') + '.stl'); - menu.destroy(); - this.showMessage('Exported!', 1); + menu.destroy(); + this.showMessage('Exported!', 1); } catch (err) { - this.showMessage('Export failed: ' + err); - console.log(err) + this.showMessage('Export failed: ' + err); + console.log(err) } }; @@ -4264,12 +4267,12 @@ IDE_Morph.prototype.saveFileAs = function ( newWindow // (optional) defaults to false. ) { /** Allow for downloading a file to a disk or open in a new tab. - This relies on the FileSaver.js library which exports saveAs() - Two utility methods saveImageAs and saveXMLAs should be used first. - 1. Opening a new window uses standard URI encoding. - 2. downloading a file uses Blobs. - - every other combo is unsupposed. - */ + This relies on the FileSaver.js library which exports saveAs() + Two utility methods saveImageAs and saveXMLAs should be used first. + 1. Opening a new window uses standard URI encoding. + 2. downloading a file uses Blobs. + - every other combo is unsupposed. + */ var blobIsSupported = false, world = this.world(), fileExt, @@ -4283,7 +4286,7 @@ IDE_Morph.prototype.saveFileAs = function ( // This is a workaround for a known Chrome crash with large URLs function exhibitsChomeBug(contents) { var MAX_LENGTH = 2e6, - isChrome = navigator.userAgent.indexOf('Chrome') !== -1; + isChrome = navigator.userAgent.indexOf('Chrome') !== -1; return isChrome && contents.length > MAX_LENGTH; } @@ -4439,8 +4442,8 @@ IDE_Morph.prototype.cloudAcknowledge = function () { new DialogBoxMorph().inform( 'Cloud Connection', 'Successfully connected to:\n' - + 'http://' - + url, + + 'http://' + + url, myself.world(), myself.cloudIcon(null, new Color(0, 180, 0)) ); @@ -4457,9 +4460,9 @@ IDE_Morph.prototype.cloudResponse = function () { new DialogBoxMorph().inform( 'Snap!Cloud', 'http://' - + url + ':\n\n' - + 'responds:\n' - + response, + + url + ':\n\n' + + 'responds:\n' + + response, myself.world(), myself.cloudIcon(null, new Color(0, 180, 0)) ); @@ -4503,7 +4506,7 @@ IDE_Morph.prototype.cloudError = function () { new DialogBoxMorph().inform( 'Snap!Cloud', (url ? url + '\n' : '') - + response, + + response, myself.world(), myself.cloudIcon(null, new Color(180, 0, 0)) ); @@ -4540,7 +4543,7 @@ IDE_Morph.prototype.setCloudURL = function () { { 'Snap!Cloud' : 'https://snapcloud.miosoft.com/miocon/app/' + - 'login?_app=SnapCloud', + 'login?_app=SnapCloud', 'local network lab' : '192.168.2.107:8087/miocon/app/login?_app=SnapCloud', 'local network office' : @@ -4766,7 +4769,7 @@ ProjectDialogMorph.prototype.buildContents = function () { this.preview.drawNew(); if (this.task === 'save') { - this.body.add(this.listField); + this.body.add(this.listField); thumbnail = this.ide.stage.thumbnail( SnapSerializer.prototype.thumbnailSize ); @@ -4792,31 +4795,31 @@ ProjectDialogMorph.prototype.buildContents = function () { this.notesText = new TextMorph(''); } else { // 'save' - this.classroomListField = new ListMorph([]); - this.fixClassRoomItemColors(); - this.classroomListField.fixLayout = nop; - this.classroomListField.edge = InputFieldMorph.prototype.edge; - this.classroomListField.fontSize = InputFieldMorph.prototype.fontSize; - this.classroomListField.typeInPadding = InputFieldMorph.prototype.typeInPadding; - this.classroomListField.contrast = InputFieldMorph.prototype.contrast; - this.classroomListField.drawNew = InputFieldMorph.prototype.drawNew; - this.classroomListField.drawRectBorder = InputFieldMorph.prototype.drawRectBorder; - this.classroomListField.acceptsDrops = false; - this.classroomListField.contents.acceptsDrops = false; - this.classroomListField.isTextLineWrapping = true; - this.classroomListField.padding = 3; - this.classroomListField.setWidth(this.preview.width()); - this.body.add(this.classroomListField); + this.classroomListField = new ListMorph([]); + this.fixClassRoomItemColors(); + this.classroomListField.fixLayout = nop; + this.classroomListField.edge = InputFieldMorph.prototype.edge; + this.classroomListField.fontSize = InputFieldMorph.prototype.fontSize; + this.classroomListField.typeInPadding = InputFieldMorph.prototype.typeInPadding; + this.classroomListField.contrast = InputFieldMorph.prototype.contrast; + this.classroomListField.drawNew = InputFieldMorph.prototype.drawNew; + this.classroomListField.drawRectBorder = InputFieldMorph.prototype.drawRectBorder; + this.classroomListField.acceptsDrops = false; + this.classroomListField.contents.acceptsDrops = false; + this.classroomListField.isTextLineWrapping = true; + this.classroomListField.padding = 3; + this.classroomListField.setWidth(this.preview.width()); + this.body.add(this.classroomListField); this.notesText = new TextMorph(this.ide.projectNotes); this.notesText.isEditable = true; this.notesText.enableSelecting(); } - this.notesField.isTextLineWrapping = true; - this.notesField.padding = 3; - this.notesField.setContents(this.notesText); - this.notesField.setWidth(this.preview.width()); + this.notesField.isTextLineWrapping = true; + this.notesField.padding = 3; + this.notesField.setContents(this.notesText); + this.notesField.setWidth(this.preview.width()); this.body.add(this.notesField); @@ -4976,101 +4979,101 @@ ProjectDialogMorph.prototype.setSource = function (source) { button.refresh(); }); switch (this.source) { - case 'cloud': - msg = myself.ide.showMessage('Updating\nproject list...'); - this.projectList = []; - SnapCloud.getProjectList( - function (projectList) { - myself.installCloudProjectList(projectList); - msg.destroy(); - }, - function (err, lbl) { - msg.destroy(); - myself.ide.cloudError().call(null, err, lbl); - } - ); - this.classroomList = []; - SnapCloud.getClassroomList( - function (classroomList) { - myself.installCloudClassroomList(classroomList); - msg.destroy(); - }, - function (err, lbl) { - msg.destroy(); - myself.ide.cloudError().call(null, err, lbl); - } - ); - return; - case 'examples': - this.projectList = this.getExamplesProjectList(); - break; - case 'goals': - this.projectList = this.getGoalProjectList(); - break; - case 'local': - this.projectList = this.getLocalProjectList(); - break; + case 'cloud': + msg = myself.ide.showMessage('Updating\nproject list...'); + this.projectList = []; + SnapCloud.getProjectList( + function (projectList) { + myself.installCloudProjectList(projectList); + msg.destroy(); + }, + function (err, lbl) { + msg.destroy(); + myself.ide.cloudError().call(null, err, lbl); + } + ); + this.classroomList = []; + SnapCloud.getClassroomList( + function (classroomList) { + myself.installCloudClassroomList(classroomList); + msg.destroy(); + }, + function (err, lbl) { + msg.destroy(); + myself.ide.cloudError().call(null, err, lbl); + } + ); + return; + case 'examples': + this.projectList = this.getExamplesProjectList(); + break; + case 'goals': + this.projectList = this.getGoalProjectList(); + break; + case 'local': + this.projectList = this.getLocalProjectList(); + break; } this.listField.destroy(); this.classroomListField.destroy(); - if(this.source === 'goals'){ - this.listField = new ListMorph( - this.projectList, - this.projectList.length > 0 ? - function (element) { - return element.thumb; - } : null, - null, - function () {myself.ok();} - ); - - //We need action declaration here to select default - this.listField.action = function (item) { + if(this.source === 'goals'){ + this.listField = new ListMorph( + this.projectList, + this.projectList.length > 0 ? + function (element) { + return element.thumb; + } : null, + null, + function () {myself.ok();} + ); + + //We need action declaration here to select default + this.listField.action = function (item) { var img, desc; if (item === undefined) {return; } if (myself.nameField) { - myself.nameField.setContents(item.name || ''); + myself.nameField.setContents(item.name || ''); } - var request = new XMLHttpRequest(); - request.open("GET", config.urls.goals_url, false); - request.send(); - var JSON_object = JSON.parse(request.responseText); - for (var i = 0; i < JSON_object.length; i++){ - if(JSON_object[i].name === item.name){ - img = JSON_object[i].img_url; - desc = JSON_object[i].description; - myself.notesText.text = desc || ''; - myself.notesText.drawNew(); - myself.notesField.contents.adjustBounds(); - myself.preview.texture = img || null; - myself.preview.cachedTexture = img; - myself.preview.drawNew(); - myself.edit(); - } - } - }; - this.listField.action(this.listField.elements[0]); - } - else{ - this.listField = new ListMorph( - this.projectList, - this.projectList.length > 0 ? - function (element) { - return element.name; - } : null, - null, - function () {myself.ok(); } - ); - } + var request = new XMLHttpRequest(); + request.open("GET", config.urls.goals_url, false); + request.send(); + var JSON_object = JSON.parse(request.responseText); + for (var i = 0; i < JSON_object.length; i++){ + if(JSON_object[i].name === item.name){ + img = JSON_object[i].img_url; + desc = JSON_object[i].description; + myself.notesText.text = desc || ''; + myself.notesText.drawNew(); + myself.notesField.contents.adjustBounds(); + myself.preview.texture = img || null; + myself.preview.cachedTexture = img; + myself.preview.drawNew(); + myself.edit(); + } + } + }; + this.listField.action(this.listField.elements[0]); + } + else{ + this.listField = new ListMorph( + this.projectList, + this.projectList.length > 0 ? + function (element) { + return element.name; + } : null, + null, + function () {myself.ok(); } + ); + } if(this.source === 'save'){ this.classroomListField = new ListMorph( this.classroomList, this.classroomList.length > 0 ? - function (element) { - return element.team_name; - } : null, + function (element) { + return element.team_name; + } : null, null, function () {myself.ok();} ); @@ -5117,14 +5120,14 @@ ProjectDialogMorph.prototype.setSource = function (source) { myself.preview.drawNew(); } myself.edit(); - this.classroomListField.hide(); + this.classroomListField.hide(); }; } else if (this.source === 'goals'){ this.listField.action = function (item) { var img, desc; if (item === undefined) {return; } if (myself.nameField) { - myself.nameField.setContents(item.name || ''); + myself.nameField.setContents(item.name || ''); } var request = new XMLHttpRequest(); request.open("GET", config.urls.goals_url, false); @@ -5200,9 +5203,9 @@ ProjectDialogMorph.prototype.installCloudClassroomList = function (cl) { this.classroomListField = new ListMorph( this.classroomList, this.classroomList.length > 0 ? - function (element) { - return element.team_name; - } : null, + function (element) { + return element.team_name; + } : null, [ // format: display shared project names bold [ 'bold', @@ -5211,7 +5214,7 @@ ProjectDialogMorph.prototype.installCloudClassroomList = function (cl) { ], function () {myself.ok(); } ); - this.fixClassRoomItemColors(); + this.fixClassRoomItemColors(); this.classroomListField.fixLayout = nop; this.classroomListField.edge = InputFieldMorph.prototype.edge; this.classroomListField.fontSize = InputFieldMorph.prototype.fontSize; @@ -5219,14 +5222,14 @@ ProjectDialogMorph.prototype.installCloudClassroomList = function (cl) { this.classroomListField.contrast = InputFieldMorph.prototype.contrast; this.classroomListField.drawNew = InputFieldMorph.prototype.drawNew; this.classroomListField.drawRectBorder = InputFieldMorph.prototype.drawRectBorder; - this.classroomListField.action = function (item) { + this.classroomListField.action = function (item) { if (item === undefined) {return; } if (item.team) { SnapCloud.classroom_id = item.team; } myself.edit(); }; - this.classroomListField.select(this.classroomListField.elements[0],true); + this.classroomListField.select(this.classroomListField.elements[0],true); this.body.add(this.classroomListField); this.fixLayout(); }; @@ -5236,7 +5239,7 @@ ProjectDialogMorph.prototype.getLocalProjectList = function () { projects = []; for (stored in localStorage) { if (Object.prototype.hasOwnProperty.call(localStorage, stored) - && stored.substr(0, 14) === '-snap-project-') { + && stored.substr(0, 14) === '-snap-project-') { name = stored.substr(14); dta = { name: name, @@ -5255,23 +5258,23 @@ ProjectDialogMorph.prototype.getLocalProjectList = function () { ProjectDialogMorph.prototype.getGoalProjectList = function () { var dir, dta, projects = [], thumbnail; - var request = new XMLHttpRequest(); - if(request.open("GET", config.urls.goals_url, false)){ - request.send(); - } - var JSON_object = JSON.parse(request.responseText); - for (var i = 0; i < JSON_object.length; i++){ - //preload images - thumbnail = new Image(); - thumbnail.src = JSON_object[i].thumb_url; - dta = { - name: JSON_object[i].name, - img: JSON_object[i].img_url, - thumb: thumbnail, - notes: JSON_object[i].description - }; - projects.push(dta); - } + var request = new XMLHttpRequest(); + if(request.open("GET", config.urls.goals_url, false)){ + request.send(); + } + var JSON_object = JSON.parse(request.responseText); + for (var i = 0; i < JSON_object.length; i++){ + //preload images + thumbnail = new Image(); + thumbnail.src = JSON_object[i].thumb_url; + dta = { + name: JSON_object[i].name, + img: JSON_object[i].img_url, + thumb: thumbnail, + notes: JSON_object[i].description + }; + projects.push(dta); + } var request = new XMLHttpRequest(); request.open("GET", config.urls.goals_url, false); request.send(); @@ -5295,24 +5298,24 @@ ProjectDialogMorph.prototype.getGoalProjectList = function () { }; ProjectDialogMorph.prototype.getExamplesProjectList = function () { - var dir, - projects = []; - try { - var request = new XMLHttpRequest(); - request.open("GET", config.urls.demos_url, false); - request.send(); - var JSON_object = JSON.parse(request.responseText); - for (var i = 0; i < JSON_object.length; i++){ - dta = { - name: JSON_object[i]["name"], - thumb: null, - notes: null - }; - projects.push(dta); - } - /*projects.sort(function (x, y) { - return x.name < y.name ? -1 : 1; - });*/ + var dir, + projects = []; + try { + var request = new XMLHttpRequest(); + request.open("GET", config.urls.demos_url, false); + request.send(); + var JSON_object = JSON.parse(request.responseText); + for (var i = 0; i < JSON_object.length; i++){ + dta = { + name: JSON_object[i]["name"], + thumb: null, + notes: null + }; + projects.push(dta); + } + /*projects.sort(function (x, y) { + return x.name < y.name ? -1 : 1; + });*/ } catch(e) { this.ide.showMessage("Failed to load examples."); @@ -5348,9 +5351,9 @@ ProjectDialogMorph.prototype.installCloudProjectList = function (pl) { this.listField = new ListMorph( this.projectList, this.projectList.length > 0 ? - function (element) { - return element.name; - } : null, + function (element) { + return element.name; + } : null, [ // format: display shared project names bold [ 'bold', @@ -5414,27 +5417,27 @@ ProjectDialogMorph.prototype.openProject = function () { if (this.source === 'cloud') { this.openCloudProject(proj); } else if (this.source === 'examples') { - var request = new XMLHttpRequest(); - request.open("GET", config.urls.demos_url, false); + var request = new XMLHttpRequest(); + request.open("GET", config.urls.demos_url, false); request.send(); var JSON_object = JSON.parse(request.responseText); for (var i = 0; i < JSON_object.length; i++){ if(JSON_object[i]["name"] === proj.name){ - demoId = JSON_object[i]["id"]; - src = this.ide.getURL(JSON_object[i]["project_url"]); + demoId = JSON_object[i]["id"]; + src = this.ide.getURL(JSON_object[i]["project_url"]); } } if(config.urls.demo_detail_url) { - SnapCloud.updateURL(config.urls.demo_detail_url + demoId); - } + SnapCloud.updateURL(config.urls.demo_detail_url + demoId); + } var request = new XMLHttpRequest(); request.open("GET", config.urls.demos_url, false); request.send(); var JSON_object = JSON.parse(request.responseText); for (var i = 0; i < JSON_object.length; i++){ - if(JSON_object[i]["name"] === proj.name){ - src = this.ide.getURL(JSON_object[i]["project_url"]); - } + if(JSON_object[i]["name"] === proj.name){ + src = this.ide.getURL(JSON_object[i]["project_url"]); + } } this.ide.openProjectString(src); this.destroy(); @@ -5475,8 +5478,8 @@ ProjectDialogMorph.prototype.saveProject = function () { var isUnique = true; for(var i = 0; i Date: Mon, 22 Apr 2019 13:47:59 -0400 Subject: [PATCH 13/17] still working on add the mesh as a costume to the stage --- gui.js | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/gui.js b/gui.js index 79748adf64..62bfff549b 100644 --- a/gui.js +++ b/gui.js @@ -2807,24 +2807,26 @@ IDE_Morph.prototype.projectMenu = function () { let submenu = new MenuMorph(myself); - // submenu.addItem('Testing', - // function () { - // console.log("submenu worked"); - // }, - // 'testing submenu' - // ); - - menu.addHoverItem( - 'Load Costume... >', - submenu + submenu.addItem('Testing', + function () { + console.log("submenu worked"); + }, + 'testing submenu' ); // console.log(myself); // console.log(myself.parent); // this will be changed to a block but just adding this here for now - submenu.addItem('Custom 3D Polygon Shape', - addCustom3DPolygonIcosahedron(myself, 5, 0, "red") + submenu.addItem('Custom 3D Polygon Shape', function () { + addCustom3DPolygonIcosahedron(myself, 5, 0, "red") + }, + 'Add Icosahedron Polygon' + ); + + menu.addHoverItem( + 'Load Costume... >', + submenu ); @@ -7230,8 +7232,8 @@ function addCustom3DPolygonIcosahedron(myself, radius, detail, colorParam){ emissive = color; } - console.log(color); - console.log(emissive); + // console.log(color); + // console.log(emissive); let geometry = new THREE.IcosahedronGeometry(radius, detail); @@ -7249,16 +7251,26 @@ function addCustom3DPolygonIcosahedron(myself, radius, detail, colorParam){ let new_object = icosahedron(); + myself.currentSprite.addCostume(new_object); + myself.currentSprite.wearCostume(new_object); + myself.spriteBar.tabBar.tabTo('costumes'); + myself.hasChangedMedia = true; + // myself.object.add(new_object); // myself.mesh = new_object; // myself.parent.changed(); // console.log(new_object); - console.log(myself); - let stage = myself.stage; - console.log(stage); - console.log(new_object); - stage.costume.addCostume(new_object); + // console.log(myself); + // let stage = myself.stage; + // console.log(stage); + // console.log(new_object); + // let childrenOfStage = stage.children; + // console.log(childrenOfStage); + // console.log(childrenOfStage[0].name); + // childrenOfStage[0].costumes[0] = new_object; + // console.log(childrenOfStage[0].costumes); + } catch (e) { console.log(e); From 63f7279acc86c885b9ad1f6629087127e899aea3 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Mon, 22 Apr 2019 15:20:47 -0400 Subject: [PATCH 14/17] getting boundingSphere --- gui.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gui.js b/gui.js index 62bfff549b..510bb768aa 100644 --- a/gui.js +++ b/gui.js @@ -7251,6 +7251,9 @@ function addCustom3DPolygonIcosahedron(myself, radius, detail, colorParam){ let new_object = icosahedron(); + let sphere = new_object.geometry.boundingSphere; // THREE.Sphere + new_object.position.set( -sphere.center.x, -sphere.center.y, -sphere.center.z ); + myself.currentSprite.addCostume(new_object); myself.currentSprite.wearCostume(new_object); myself.spriteBar.tabBar.tabTo('costumes'); From 875df6d3323ba9507900bce9452fa16e5babc3d2 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Tue, 23 Apr 2019 13:09:15 -0400 Subject: [PATCH 15/17] reset radius to 1 --- gui.js | 2 +- objects.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gui.js b/gui.js index 510bb768aa..47e6aff4a5 100644 --- a/gui.js +++ b/gui.js @@ -7216,7 +7216,7 @@ function addCustom3DPolygonIcosahedron(myself, radius, detail, colorParam){ try { let icosahedron = function () { if (radius === undefined || detail === undefined) { - radius = 5; + radius = 1; detail = 0; } diff --git a/objects.js b/objects.js index 649b23d545..b34105f038 100644 --- a/objects.js +++ b/objects.js @@ -1565,6 +1565,8 @@ SpriteMorph.prototype.drawNew = function () { ctx, handle; + console.log(myself); + if (this.costume && this.costume.is3D) { // the 3D object will be rendered in StageMorph.drawOn() later this.hide(); @@ -6476,7 +6478,7 @@ function Costume(canvas, name, rotationCenter, url, is3D, is3dSwitchable) { // newly added for 3D this.url = url; this.is3D = is3D; - this.is3dSwitchable = is3dSwitchable + this.is3dSwitchable = is3dSwitchable; this.geometry = null; this.map = null; } From d1fe9c44e9682bf39a657e99e4f187cc9166b890 Mon Sep 17 00:00:00 2001 From: chinedu amadi-ndukwe Date: Tue, 23 Apr 2019 15:24:17 -0400 Subject: [PATCH 16/17] cleaning up and now making sense, added the shape the same way other shapes exist --- Chinedu_Changes_To_IDE_Morph.js | 45 -------- gui.js | 194 -------------------------------- objects.js | 49 +++++++- 3 files changed, 45 insertions(+), 243 deletions(-) delete mode 100644 Chinedu_Changes_To_IDE_Morph.js diff --git a/Chinedu_Changes_To_IDE_Morph.js b/Chinedu_Changes_To_IDE_Morph.js deleted file mode 100644 index cbba80bf31..0000000000 --- a/Chinedu_Changes_To_IDE_Morph.js +++ /dev/null @@ -1,45 +0,0 @@ -// /** -// * function below allows for adding icosahedron shape to scene -// * @param myself CSnap world -// * @param radius default is set to 5 -// * @param detail default is set to 1, changing this will effectively make this a sphere so be careful with this -// * @param colorParam default is set to blue but we can pass in any color we like -// * for reference see https://threejs.org/docs/#api/en/geometries/IcosahedronGeometry -// */ -// IDE_Morph.prototype.addCustom3DPolygonIcosahedron = function (myself, radius, detail, colorParam){ -// -// let icosahedron = function () { -// if (radius === undefined || detail === undefined){ -// radius = 5; -// detail = 0; -// } -// -// let enteredColorToLowerCase = colorParam.toLowerCase(); -// let color = ""; -// let emissive = ""; -// -// if (enteredColorToLowerCase !== undefined){ -// color = new THREE.Color(enteredColorToLowerCase); -// emissive = color; -// } else { -// color = new THREE.Color( 'blue' ); -// emissive = color; -// } -// -// console.log(color); -// console.log(emissive); -// -// -// let geometry = new THREE.IcosahedronGeometry(radius, detail); -// let material = new THREE.MeshLambertMaterial({ emissive: emissive, color: color }); -// return new THREE.Mesh(geometry, material); -// }; -// -// //TODO Add icosahedron as a costume to CSnap's stage. -// // Unsure about below, let's see if it works -// -// this.currentSprite.addCostume(icosahedron()); -// this.currentSprite.wearCostume(icosahedron()); -// this.spriteBar.tabBar.tabTo('costumes'); -// this.hasChangedMedia = true; -// }; \ No newline at end of file diff --git a/gui.js b/gui.js index 47e6aff4a5..805a612376 100644 --- a/gui.js +++ b/gui.js @@ -2814,16 +2814,6 @@ IDE_Morph.prototype.projectMenu = function () { 'testing submenu' ); - // console.log(myself); - // console.log(myself.parent); - - // this will be changed to a block but just adding this here for now - submenu.addItem('Custom 3D Polygon Shape', function () { - addCustom3DPolygonIcosahedron(myself, 5, 0, "red") - }, - 'Add Icosahedron Polygon' - ); - menu.addHoverItem( 'Load Costume... >', submenu @@ -7095,187 +7085,3 @@ ProjectDialogMorph.prototype.fixClassRoomItemColors = function () { item.noticesTransparentClick = true; }); }; - - -// // Everything below will be moved to a different JS file but for now, lets leave it here for debugging -// -// function doActualExtrusionOfImage(pathToImgWeWantToExtrude, x, y) { -// // temporary canvas to hold the image and retrieve its data -// let tempCanvasToGetImageData = document.createElement('canvas'); -// let ctx = tempCanvasToGetImageData.getContext("2d"); -// tempCanvasToGetImageData.width = pathToImgWeWantToExtrude.width; -// tempCanvasToGetImageData.height = pathToImgWeWantToExtrude.height; -// ctx.drawImage(pathToImgWeWantToExtrude, 0, 0); // this should draw the image with its intrinsic size -// -// let myImageData = ctx.getImageData(x, y, pathToImgWeWantToExtrude.width, pathToImgWeWantToExtrude.height); -// -// for (let i=0;i Date: Wed, 24 Apr 2019 07:58:57 -0400 Subject: [PATCH 17/17] made further corrections to fix bugs --- objects.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/objects.js b/objects.js index 036fa0273b..46b4772882 100644 --- a/objects.js +++ b/objects.js @@ -732,6 +732,7 @@ SpriteMorph.prototype.initBlocks = function () { spec: 'text %s size: %n height: %n', defaults: [localize('Hello!'), 30, 3] }, + // Still Working on below renderIcosahedron: { "type": "command", "category": "pen", @@ -3329,7 +3330,7 @@ SpriteMorph.prototype.renderText = function (text, size, height) { //Todo confirm with Ron to see if this is the right spot to add the Icosahedron -SpriteMorph.prototype.renderIcosahedron = function (myself, radius, detail, colorParam){ +SpriteMorph.prototype.renderIcosahedron = function (radius, detail, colorParam){ try { let icosahedron = function () { if (radius === undefined || detail === undefined) { @@ -3353,6 +3354,11 @@ SpriteMorph.prototype.renderIcosahedron = function (myself, radius, detail, colo return new THREE.Mesh(geometry, material); }; this.render3dShape(icosahedron()); + + // For debugging + console.log(myself); + console.log(this); + } catch (e) { console.log(e); }