Skip to content

Commit 6988a39

Browse files
committed
Update main.ts
1 parent 2fc46a4 commit 6988a39

File tree

1 file changed

+85
-65
lines changed

1 file changed

+85
-65
lines changed

main.ts

Lines changed: 85 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
namespace polymesh {
44

55
export enum Angles {
6-
//% block="angle x"
6+
//% block="x"
77
Angle_X,
8-
//% block="angle y"
8+
//% block="y"
99
Angle_Y,
10-
//% block="angle z"
10+
//% block="z"
1111
Angle_Z,
1212
}
1313
export enum Cameras {
14-
//% block="cam x"
14+
//% block="x"
1515
Cam_x,
16-
//% block="cam y"
16+
//% block="y"
1717
Cam_y,
18-
//% block="cam z"
18+
//% block="z"
1919
Cam_z,
2020
}
2121
export enum MeshType {
@@ -50,98 +50,106 @@ namespace polymesh {
5050
}
5151

5252
export class cvc { constructor(public x: number, public y: number, public z: number) { } }
53-
//% blockid=poly_clsvertice
53+
//% blockid=poly_shadow_vertice
5454
//% block="vertice of x $x y $y z $z"
5555
//% x.defl=0
5656
//% y.defl=0
5757
//% z.defl=0
58-
export function clsvertice(x: number, y: number, z: number): cvc {
58+
export function clsvertice(x: number, y: number, z: number) {
5959
return new cvc(x, y, z)
6060
}
6161

6262
export class ctc { constructor(public i1: number, public i2: number, public i3: number, public c: number) { } }
63-
//% blockid=poly_clstriangle
63+
//% blockid=poly_shadow_triangle
6464
//% block="triangle of idc1 $i1 idc2 $i2 idc3 $i3 color $col"
6565
//% i1.defl=0
6666
//% i2.defl=0
6767
//% i3.defl=0
6868
//% col.shadow=colorindexpicker
69-
export function clstriangle(i1: number, i2: number, i3: number, col: number): ctc {
69+
export function clstriangle(i1: number, i2: number, i3: number, col: number) {
7070
return new ctc(i1, i2, i3, col)
7171
}
7272

7373
//% blockid=poly_newmesh
7474
//% block="create new mesh"
7575
//% blockSetVariable=myMesh
76+
//% weight=100
7677
export function newmesh() {
7778
return new cmesh()
7879
}
7980

8081
export class cmesh {
81-
v: mesh
82+
public v: mesh
8283

8384
constructor() {
8485
this.v.cts = [{indices: [0,0,0], color: 0}]
8586
this.v.cvs = [{x: 0, y: 0, z: 0}]
8687
}
87-
}
88-
8988

90-
//% blockid=poly_class_addvertice
91-
//% block=" $from add vertice by $ccv|| at $idx"
92-
//% from.shadow=variables_get from.defl=myMesh
93-
//% ccv.shadow=poly_clsvertice
94-
export function addvertice(from: cmesh, ccv: cvc, idx: number = -1) {
95-
if (idx < 0) {
96-
from.v.cvs.insertAt(idx, { x: ccv.x, y: ccv.y, z: ccv.z })
97-
return
89+
//% blockid=poly_addvertice
90+
//% block=" $this add vertice by x: $x y: $y z: $z|| at $idx"
91+
//% this.shadow=variables_get this.defl=myMesh
92+
//% ccv.shadow=poly_shadow_vertice
93+
//% weight=90
94+
public addvertice(x: number, y: number, z: number, idx: number = -1) {
95+
if (idx < 0) {
96+
this.v.cvs.insertAt(idx, { x: x, y: y, z: z })
97+
return
98+
}
99+
this.v.cvs.push({ x: x, y: y, z: z })
98100
}
99-
from.v.cvs.push({ x: ccv.x, y: ccv.y, z: ccv.z })
100-
}
101-
102-
//% blockid=poly_class_addtriangle
103-
//% block=" $from add triangle by $cct|| at $idx"
104-
//% from.shadow=variables_get from.defl=myMesh
105-
//% cct.shadow=poly_clstriangle
106-
export function addtriangle(from: cmesh, cct: ctc, idx: number = -1) {
107-
if (idx < 0) {
108-
from.v.cts.insertAt(idx, { indices: [cct.i1, cct.i2, cct.i3], color: cct.c })
109-
return
101+
102+
//% blockid=poly_addtriangle
103+
//% block=" $this add triangle by idc1 $i1 idc2 $i2 idc3 $i3 color $c|| at $idx"
104+
//% this.shadow=variables_get this.defl=myMesh
105+
//% c.shadow=colorindexpicker
106+
//% cct.shadow=poly_shadow_triangle
107+
//% weight=89
108+
public addtriangle(i1: number, i2: number, i3: number, c: number, idx: number = -1) {
109+
if (idx < 0) {
110+
this.v.cts.insertAt(idx, { indices: [i1, i2, i3], color: c })
111+
return
112+
}
113+
this.v.cts.push({ indices: [i1, i2, i3], color: c })
114+
}
115+
116+
//% blockid=poly_addvertice
117+
//% block=" $this set vertice at $idx by x: $x y: $y z: $z"
118+
//% this.shadow=variables_get this.defl=myMesh
119+
//% ccv.shadow=poly_shadow_vertice
120+
//% weight=88
121+
public setvertice(idx: number, x: number, y: number, z: number) {
122+
this.v.cvs[idx] = { x: x, y: y, z: z }
123+
}
124+
125+
//% blockid=poly_addtriangle
126+
//% block=" $this set triangle at $idx by idc1 $i1 idc2 $i2 idc3 $i3 color $c"
127+
//% this.shadow=variables_get this.defl=myMesh
128+
//% cct.shadow=poly_shadow_triangle
129+
//% c.shadow=colorindexpicker
130+
//% weight=87
131+
public settriangle(idx: number, i1: number, i2: number, i3: number, c: number) {
132+
this.v.cts[idx] = { indices: [i1, i2, i3], color: c }
133+
}
134+
135+
//% blockid=poly_delvertice
136+
//% block=" $this remove vertice at $idx"
137+
//% this.shadow=variables_get this.defl=myMesh
138+
//% weight=86
139+
public delvertice(idx: number) {
140+
this.v.cvs.removeAt(idx)
141+
}
142+
143+
//% blockid=poly_deltriangle
144+
//% block=" $this remove triangle at $idx"
145+
//% this.shadow=variables_get this.defl=myMesh
146+
//% weight=85
147+
public deltriangle(idx: number) {
148+
this.v.cts.removeAt(idx)
110149
}
111-
from.v.cts.push({ indices: [cct.i1, cct.i2, cct.i3], color: cct.c })
112-
}
113-
114-
//% blockid=poly_class_addvertice
115-
//% block=" $from set vertice at $idx by $ccv"
116-
//% from.shadow=variables_get from.defl=myMesh
117-
//% ccv.shadow=poly_clsvertice
118-
export function setvertice(from: cmesh, idx: number, ccv: cvc) {
119-
from.v.cvs.set(idx, { x: ccv.x, y: ccv.y, z: ccv.z })
120-
}
121-
122-
//% blockid=poly_class_addtriangle
123-
//% block=" $from set triangle at $idx by $cct"
124-
//% from.shadow=variables_get from.defl=myMesh
125-
//% cct.shadow=poly_clstriangle
126-
export function settriangle(from: cmesh, idx: number, cct: ctc) {
127-
from.v.cts.set(idx, { indices: [cct.i1, cct.i2, cct.i3], color: cct.c })
128-
}
129-
130-
//% blockid=poly_class_delvertice
131-
//% block=" $from remove vertice at $idx"
132-
//% from.shadow=variables_get from.defl=myMesh
133-
export function delvertice(from: cmesh, idx: number) {
134-
from.v.cvs.removeAt(idx)
135-
}
136150

137-
//% blockid=poly_class_deltriangle
138-
//% block=" $from remove triangle at $idx"
139-
//% from.shadow=variables_get from.defl=myMesh
140-
export function deltriangle(from: cmesh, idx: number) {
141-
from.v.cts.removeAt(idx)
142151
}
143152

144-
145153
let axchange = 0
146154
let azchange = 0
147155
let camx = 0
@@ -155,6 +163,7 @@ namespace polymesh {
155163
//% block=" $mymesh render to $image"
156164
//% mymesh.shadow=variables_get mymesh.defl=myMesh
157165
//% image.shadow=screen_image_picker
166+
//% weight=80
158167
export function render(mymesh: cmesh, image: Image) {
159168
function updateCube() {
160169
let bg = image;
@@ -364,6 +373,7 @@ namespace polymesh {
364373
//% blockHidden
365374
//% blockid=poly_getvertice
366375
//% block="get vertice x $x y $y z $z"
376+
//% weight=70
367377
export function getvertice(x: number, y: number, z: number): cv {
368378
return {
369379
x, y, z,
@@ -373,14 +383,16 @@ namespace polymesh {
373383
//% blockHidden
374384
//% blockid=poly_gettriangle
375385
//% block="get triangle indice 1 $i1 indice 2 $i2 indice 3 $i3 color $col"
386+
//% weight=69
376387
export function gettriangle(i1: number, i2: number, i3: number, col: number): ct {
377388
return {
378389
indices: [i1, i2, i3], color: col
379390
}
380391
}
381392

382393
//% blockid=poly_angle_change
383-
//% block="change $choice by $x"
394+
//% block="change angle $choice by $x"
395+
//% weight=60
384396
export function change(choice: Angles, x: number) {
385397
if (choice === 0) {
386398
axchange += x
@@ -391,7 +403,8 @@ namespace polymesh {
391403
}
392404
}
393405
//% blockid=poly_camera_change
394-
//% block="change $choice by $x"
406+
//% block="change camera $choice by $x"
407+
//% weight=59
395408
export function changecam(choice: Cameras, x: number) {
396409
if (choice === 0) {
397410
camx += x
@@ -403,6 +416,7 @@ namespace polymesh {
403416
}
404417
//% blockid=poly_angle_set
405418
//% block="set $choice to $x"
419+
//% weight=58
406420
export function setangle(choice: Angles, x: number) {
407421
if (choice === 0) {
408422
axchange = x
@@ -414,12 +428,14 @@ namespace polymesh {
414428
}
415429
//% blockid=poly_size
416430
//% block="set size to $x"
431+
//% weight=50
417432
export function setsize(x: number) {
418433
sizechange = x
419434
}
420435

421436
//% blockid=poly_sorttype
422437
//% block="set sorting method to $method"
438+
//% weight=49
423439
export function sortingmethod(method: SortingMethods) {
424440
if (method === 0) {
425441
sort = 0
@@ -432,22 +448,26 @@ namespace polymesh {
432448

433449
//% blockid=poly_angle_x
434450
//% block="angle x"
451+
//% weight=40
435452
export function anglex() {
436453
return axchange
437454
}
438455
//% blockid=poly_angle_y
439456
//% block="angle y"
457+
//% weight=39
440458
export function angley() {
441459
return aychange
442460
}
443461
//% blockid=poly_angle_z
444462
//% block="angle z"
463+
//% weight=38
445464
export function anglez() {
446465
return azchange
447466
}
448467

449468
//% blockid=poly_camera_set
450469
//% block="set camera position to x: $x y: $y z: $z"
470+
//% weight=48
451471
export function setcampos(x: number, y: number, z: number) {
452472
camx = x
453473
camy = y

0 commit comments

Comments
 (0)