11
2- //% block="poly mesh" color="#279139" icon="\uf1b2"
2+ //% block="poly mesh" color="#279139" icon="\uf1b2" groups='["Create","Controls","Styling"]'
33namespace polymesh {
44
55 export enum Angles {
@@ -51,15 +51,89 @@ namespace polymesh {
5151
5252 export class cvc { constructor ( public x : number , public y : number , public z : number ) { } }
5353
54- export class ctc { constructor ( public x : number , public y : number , public z : number , public c : number ) { } }
54+ export class ctc { constructor ( public i1 : number , public i2 : number , public i3 : number , public c : number ) { } }
55+
56+ //% blockid=poly_newmesh
57+ //% block="create new mesh"
58+ //% blockSetVariable=myMenu
59+ export function newmesh ( ) {
60+ return new cmesh ( )
61+ }
62+
63+ //% blockid=poly_clsvertice
64+ //% block="vertice of x $x y $y z $z"
65+ export function clsvertice ( x : number , y : number , z : number ) : cvc {
66+ return new cvc ( x , y , z )
67+ }
68+
69+ //% blockid=poly_clstriangle
70+ //% block="triangle of idc1 $x idc2 $y idc3 $z color $col"
71+ export function clstriangle ( i1 : number , i2 : number , i3 : number , col : number ) : ctc {
72+ return new ctc ( i1 , i2 , i3 , col )
73+ }
5574
5675 export class cmesh {
57- public v : mesh
76+ v : mesh
5877
5978 constructor ( ) {
6079 this . v . cts = [ { indices : [ 0 , 0 , 0 ] , color : 0 } ]
6180 this . v . cvs = [ { x : 0 , y : 0 , z : 0 } ]
6281 }
82+
83+ //% blockid=poly_class_addvertice
84+ //% block=" $this add vertice by $ccv|| at $idx"
85+ //% this.defl=myMesh
86+ //% ccv.shadow=poly_clsvertice
87+ public addvertice ( ccv : cvc , idx : number = - 1 ) {
88+ if ( idx < 0 ) {
89+ this . v . cvs . insertAt ( idx , { x : ccv . x , y : ccv . y , z : ccv . z } )
90+ return
91+ }
92+ this . v . cvs . push ( { x : ccv . x , y : ccv . y , z : ccv . z } )
93+ }
94+
95+ //% blockid=poly_class_addtriangle
96+ //% block=" $this add triangle by $cct|| at $idx"
97+ //% this.defl=myMesh
98+ //% cct.shadow=poly_clstriangle
99+ public addtriangle ( cct : ctc , idx : number = - 1 ) {
100+ if ( idx < 0 ) {
101+ this . v . cts . insertAt ( idx , { indices : [ cct . i1 , cct . i2 , cct . i3 ] , color : cct . c } )
102+ return
103+ }
104+ this . v . cts . push ( { indices : [ cct . i1 , cct . i2 , cct . i3 ] , color : cct . c } )
105+ }
106+
107+ //% blockid=poly_class_addvertice
108+ //% block=" $this set vertice at $idx by $ccv"
109+ //% this.defl=myMesh
110+ //% ccv.shadow=poly_clsvertice
111+ public setvertice ( idx : number , ccv : cvc ) {
112+ this . v . cvs . set ( idx , { x : ccv . x , y : ccv . y , z : ccv . z } )
113+ }
114+
115+ //% blockid=poly_class_addtriangle
116+ //% block=" $this set triangle at $idx by $cct"
117+ //% this.deflmyMesh
118+ //% cct.shadow=poly_clstriangle
119+ public settriangle ( idx : number , cct : ctc ) {
120+ this . v . cts . set ( idx , { indices : [ cct . i1 , cct . i2 , cct . i3 ] , color : cct . c } )
121+ }
122+
123+ //% blockid=poly_class_delvertice
124+ //% block=" $this remove vertice at $idx"
125+ //% this.defl=myMesh
126+ public delvertice ( idx : number ) {
127+ this . v . cvs . removeAt ( idx )
128+ }
129+
130+ //% blockid=poly_class_deltriangle
131+ //% block=" $this remove triangle at $idx"
132+ //% this.deflmyMesh
133+ public deltriangle ( idx : number ) {
134+ this . v . cts . removeAt ( idx )
135+ }
136+
63137 }
64138
65139 let axchange = 0
@@ -71,25 +145,6 @@ namespace polymesh {
71145 let aychange = 0
72146 let sort = 2
73147
74- //% blockid=poly_clsvertice
75- //% block="vertice of x $x y $y z $z"
76- export function clsvertice ( x : number , y : number , z : number ) : cvc {
77- return new cvc ( x , y , z , )
78- }
79-
80- //% blockid=poly_clstriangle
81- //% block="triangle of indice 1 $x indice 2 $y indice 3 $z color $col"
82- export function clstriangle ( x : number , y : number , z : number , col : number ) : ctc {
83- return new ctc ( x , y , z , col )
84- }
85-
86- //% blockid=poly_newmesh
87- //% block="create new mesh"
88- //% blockSetVariable=myMenu
89- export function newmesh ( ) {
90- return new cmesh ( )
91- }
92-
93148 //% blockid=poly_setvertice
94149 //% block=" $mymesh set vertice array by $ccv"
95150 //% mymesh.shadow=variables_get mymesh.defl=myMesh
@@ -107,7 +162,7 @@ namespace polymesh {
107162 //% cct.defl=poly_clstriangle
108163 export function settriangle ( mymesh : cmesh , cct : ctc [ ] ) {
109164 mymesh . v . cts = [ ]
110- for ( let clsv of cct ) mymesh . v . cts . push ( { indices : [ clsv . x , clsv . y , clsv . z ] , color : clsv . c } )
165+ for ( let clsv of cct ) mymesh . v . cts . push ( { indices : [ clsv . i1 , clsv . i2 , clsv . i3 ] , color : clsv . c } )
111166 }
112167
113168 //% blockid=poly_rendermesh
0 commit comments