FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/core/src/processing/opengl/PShapeOpenGL.java at master · 2php/processing · GitHub
processing/core/src/processing/opengl/PShapeOpenGL.java at master · 2php/processing · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
2php
processing
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
core
/
src
/
processing
/
opengl
/
PShapeOpenGL.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
5129 lines (4263 loc) · 151 KB
Breadcrumbs
processing
/
core
/
src
/
processing
/
opengl
/
PShapeOpenGL.java
Copy path
File metadata and controls
5129 lines (4263 loc) · 151 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, version 2.1.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
package
processing
.
opengl
;
import
processing
.
core
.
PApplet
;
import
processing
.
core
.
PConstants
;
import
processing
.
core
.
PGraphics
;
import
processing
.
core
.
PImage
;
import
processing
.
core
.
PMatrix
;
import
processing
.
core
.
PMatrix2D
;
import
processing
.
core
.
PMatrix3D
;
import
processing
.
core
.
PShape
;
import
processing
.
core
.
PVector
;
import
processing
.
opengl
.
PGraphicsOpenGL
.
AttributeMap
;
import
processing
.
opengl
.
PGraphicsOpenGL
.
IndexCache
;
import
processing
.
opengl
.
PGraphicsOpenGL
.
InGeometry
;
import
processing
.
opengl
.
PGraphicsOpenGL
.
TessGeometry
;
import
processing
.
opengl
.
PGraphicsOpenGL
.
Tessellator
;
import
processing
.
opengl
.
PGraphicsOpenGL
.
VertexAttribute
;
import
java
.
nio
.
Buffer
;
import
java
.
util
.
Arrays
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
Stack
;
/**
* This class holds a 3D model composed of vertices, normals, colors
* (per vertex) and texture coordinates (also per vertex). All this data is
* stored in Vertex Buffer Objects (VBO) in GPU memory for very fast access.
* OBJ loading implemented using code from Saito's OBJLoader library:
* http://code.google.com/p/saitoobjloader/
* and OBJReader from Ahmet Kizilay
* http://www.openprocessing.org/visuals/?visualID=191
* By Andres Colubri
*
*
* Other formats to consider:
* AMF: http://en.wikipedia.org/wiki/Additive_Manufacturing_File_Format
* STL: http://en.wikipedia.org/wiki/STL_(file_format)
* OFF: http://people.sc.fsu.edu/~jburkardt/data/off/off.html(file_format)
* DXF: http://en.wikipedia.org/wiki/AutoCAD_DXF
*/
public
class
PShapeOpenGL
extends
PShape
{
// Testing these constants, not use as they might go away...
static
public
final
int
POSITION
=
0
;
static
public
final
int
NORMAL
=
1
;
static
public
final
int
TEXCOORD
=
2
;
static
public
final
int
DIRECTION
=
3
;
static
public
final
int
OFFSET
=
4
;
static
protected
final
int
TRANSLATE
=
0
;
static
protected
final
int
ROTATE
=
1
;
static
protected
final
int
SCALE
=
2
;
static
protected
final
int
MATRIX
=
3
;
protected
PGraphicsOpenGL
pg
;
protected
PGL
pgl
;
protected
int
context
;
// The context that created this shape.
protected
PShapeOpenGL
root
;
// ........................................................
// Input, tessellated geometry
protected
InGeometry
inGeo
;
protected
TessGeometry
tessGeo
;
protected
Tessellator
tessellator
;
protected
AttributeMap
polyAttribs
;
// ........................................................
// Texturing
protected
HashSet
<
PImage
>
textures
;
protected
boolean
strokedTexture
;
protected
boolean
untexChild
;
// ........................................................
// OpenGL buffers
protected
VertexBuffer
bufPolyVertex
;
protected
VertexBuffer
bufPolyColor
;
protected
VertexBuffer
bufPolyNormal
;
protected
VertexBuffer
bufPolyTexcoord
;
protected
VertexBuffer
bufPolyAmbient
;
protected
VertexBuffer
bufPolySpecular
;
protected
VertexBuffer
bufPolyEmissive
;
protected
VertexBuffer
bufPolyShininess
;
protected
VertexBuffer
bufPolyIndex
;
protected
VertexBuffer
bufLineVertex
;
protected
VertexBuffer
bufLineColor
;
protected
VertexBuffer
bufLineAttrib
;
protected
VertexBuffer
bufLineIndex
;
protected
VertexBuffer
bufPointVertex
;
protected
VertexBuffer
bufPointColor
;
protected
VertexBuffer
bufPointAttrib
;
protected
VertexBuffer
bufPointIndex
;
// Testing this field, not use as it might go away...
public
int
glUsage
=
PGL
.
STATIC_DRAW
;
// ........................................................
// Offsets for geometry aggregation and update.
protected
int
polyVertCopyOffset
;
protected
int
polyIndCopyOffset
;
protected
int
lineVertCopyOffset
;
protected
int
lineIndCopyOffset
;
protected
int
pointVertCopyOffset
;
protected
int
pointIndCopyOffset
;
protected
int
polyIndexOffset
;
protected
int
polyVertexOffset
;
protected
int
polyVertexAbs
;
protected
int
polyVertexRel
;
protected
int
lineIndexOffset
;
protected
int
lineVertexOffset
;
protected
int
lineVertexAbs
;
protected
int
lineVertexRel
;
protected
int
pointIndexOffset
;
protected
int
pointVertexOffset
;
protected
int
pointVertexAbs
;
protected
int
pointVertexRel
;
protected
int
firstPolyIndexCache
;
protected
int
lastPolyIndexCache
;
protected
int
firstLineIndexCache
;
protected
int
lastLineIndexCache
;
protected
int
firstPointIndexCache
;
protected
int
lastPointIndexCache
;
protected
int
firstPolyVertex
;
protected
int
lastPolyVertex
;
protected
int
firstLineVertex
;
protected
int
lastLineVertex
;
protected
int
firstPointVertex
;
protected
int
lastPointVertex
;
// ........................................................
// Geometric transformations.
protected
PMatrix
transform
;
protected
Stack
<
PMatrix
>
transformStack
;
// ........................................................
// State/rendering flags
protected
boolean
tessellated
;
protected
boolean
needBufferInit
=
false
;
// Flag to indicate if the shape can have holes or not.
protected
boolean
solid
=
true
;
protected
boolean
breakShape
=
false
;
protected
boolean
shapeCreated
=
false
;
// These variables indicate if the shape contains
// polygon, line and/or point geometry. In the case of
// 3D shapes, poly geometry is coincident with the fill
// triangles, as the lines and points are stored separately.
// However, for 2D shapes the poly geometry contains all of
// the three since the same rendering shader applies to
// fill, line and point geometry.
protected
boolean
hasPolys
;
protected
boolean
hasLines
;
protected
boolean
hasPoints
;
// ........................................................
// Bezier and Catmull-Rom curves
protected
int
bezierDetail
;
protected
int
curveDetail
;
protected
float
curveTightness
;
protected
int
savedBezierDetail
;
protected
int
savedCurveDetail
;
protected
float
savedCurveTightness
;
// ........................................................
// Normals
protected
float
normalX
,
normalY
,
normalZ
;
// normal calculated per triangle
static
protected
final
int
NORMAL_MODE_AUTO
=
0
;
// one normal manually specified per shape
static
protected
final
int
NORMAL_MODE_SHAPE
=
1
;
// normals specified for each shape vertex
static
protected
final
int
NORMAL_MODE_VERTEX
=
2
;
// Current mode for normals, one of AUTO, SHAPE, or VERTEX
protected
int
normalMode
;
// ........................................................
// Modification variables (used only by the root shape)
protected
boolean
modified
;
protected
boolean
modifiedPolyVertices
;
protected
boolean
modifiedPolyColors
;
protected
boolean
modifiedPolyNormals
;
protected
boolean
modifiedPolyTexCoords
;
protected
boolean
modifiedPolyAmbient
;
protected
boolean
modifiedPolySpecular
;
protected
boolean
modifiedPolyEmissive
;
protected
boolean
modifiedPolyShininess
;
protected
boolean
modifiedLineVertices
;
protected
boolean
modifiedLineColors
;
protected
boolean
modifiedLineAttributes
;
protected
boolean
modifiedPointVertices
;
protected
boolean
modifiedPointColors
;
protected
boolean
modifiedPointAttributes
;
protected
int
firstModifiedPolyVertex
;
protected
int
lastModifiedPolyVertex
;
protected
int
firstModifiedPolyColor
;
protected
int
lastModifiedPolyColor
;
protected
int
firstModifiedPolyNormal
;
protected
int
lastModifiedPolyNormal
;
protected
int
firstModifiedPolyTexcoord
;
protected
int
lastModifiedPolyTexcoord
;
protected
int
firstModifiedPolyAmbient
;
protected
int
lastModifiedPolyAmbient
;
protected
int
firstModifiedPolySpecular
;
protected
int
lastModifiedPolySpecular
;
protected
int
firstModifiedPolyEmissive
;
protected
int
lastModifiedPolyEmissive
;
protected
int
firstModifiedPolyShininess
;
protected
int
lastModifiedPolyShininess
;
protected
int
firstModifiedLineVertex
;
protected
int
lastModifiedLineVertex
;
protected
int
firstModifiedLineColor
;
protected
int
lastModifiedLineColor
;
protected
int
firstModifiedLineAttribute
;
protected
int
lastModifiedLineAttribute
;
protected
int
firstModifiedPointVertex
;
protected
int
lastModifiedPointVertex
;
protected
int
firstModifiedPointColor
;
protected
int
lastModifiedPointColor
;
protected
int
firstModifiedPointAttribute
;
protected
int
lastModifiedPointAttribute
;
// ........................................................
// Saved style variables to style can be re-enabled after disableStyle,
// although it won't work if properties are defined on a per-vertex basis.
protected
boolean
savedStroke
;
protected
int
savedStrokeColor
;
protected
float
savedStrokeWeight
;
protected
int
savedStrokeCap
;
protected
int
savedStrokeJoin
;
protected
boolean
savedFill
;
protected
int
savedFillColor
;
protected
boolean
savedTint
;
protected
int
savedTintColor
;
protected
int
savedAmbientColor
;
protected
int
savedSpecularColor
;
protected
int
savedEmissiveColor
;
protected
float
savedShininess
;
protected
int
savedTextureMode
;
PShapeOpenGL
() {
}
public
PShapeOpenGL
(
PGraphicsOpenGL
pg
,
int
family
) {
this
.
pg
=
pg
;
this
.
family
=
family
;
pgl
=
pg
.
pgl
;
context
=
pgl
.
createEmptyContext
();
bufPolyVertex
=
null
;
bufPolyColor
=
null
;
bufPolyNormal
=
null
;
bufPolyTexcoord
=
null
;
bufPolyAmbient
=
null
;
bufPolySpecular
=
null
;
bufPolyEmissive
=
null
;
bufPolyShininess
=
null
;
bufPolyIndex
=
null
;
bufLineVertex
=
null
;
bufLineColor
=
null
;
bufLineAttrib
=
null
;
bufLineIndex
=
null
;
bufPointVertex
=
null
;
bufPointColor
=
null
;
bufPointAttrib
=
null
;
bufPointIndex
=
null
;
this
.
tessellator
=
pg
.
tessellator
;
this
.
root
=
this
;
this
.
parent
=
null
;
this
.
tessellated
=
false
;
if
(
family
==
GEOMETRY
||
family
==
PRIMITIVE
||
family
==
PATH
) {
polyAttribs
=
PGraphicsOpenGL
.
newAttributeMap
();
inGeo
=
PGraphicsOpenGL
.
newInGeometry
(
pg
,
polyAttribs
,
PGraphicsOpenGL
.
RETAINED
);
}
// Style parameters are retrieved from the current values in the renderer.
textureMode
=
pg
.
textureMode
;
colorMode
(
pg
.
colorMode
,
pg
.
colorModeX
,
pg
.
colorModeY
,
pg
.
colorModeZ
,
pg
.
colorModeA
);
// Initial values for fill, stroke and tint colors are also imported from
// the renderer. This is particular relevant for primitive shapes, since is
// not possible to set their color separately when creating them, and their
// input vertices are actually generated at rendering time, by which the
// color configuration of the renderer might have changed.
fill
=
pg
.
fill
;
fillColor
=
pg
.
fillColor
;
stroke
=
pg
.
stroke
;
strokeColor
=
pg
.
strokeColor
;
strokeWeight
=
pg
.
strokeWeight
;
strokeCap
=
pg
.
strokeCap
;
strokeJoin
=
pg
.
strokeJoin
;
tint
=
pg
.
tint
;
tintColor
=
pg
.
tintColor
;
setAmbient
=
pg
.
setAmbient
;
ambientColor
=
pg
.
ambientColor
;
specularColor
=
pg
.
specularColor
;
emissiveColor
=
pg
.
emissiveColor
;
shininess
=
pg
.
shininess
;
sphereDetailU
=
pg
.
sphereDetailU
;
sphereDetailV
=
pg
.
sphereDetailV
;
bezierDetail
=
pg
.
bezierDetail
;
curveDetail
=
pg
.
curveDetail
;
curveTightness
=
pg
.
curveTightness
;
rectMode
=
pg
.
rectMode
;
ellipseMode
=
pg
.
ellipseMode
;
normalX
=
normalY
=
0
;
normalZ
=
1
;
normalMode
=
NORMAL_MODE_AUTO
;
// To make sure that the first vertex is marked as a break.
// Same behavior as in the immediate mode.
breakShape
=
false
;
if
(
family
==
GROUP
) {
// GROUP shapes are always marked as ended.
shapeCreated
=
true
;
}
// OpenGL supports per-vertex coloring (unlike Java2D)
perVertexStyles
=
true
;
}
/** Create a shape from the PRIMITIVE family, using this kind and these params */
public
PShapeOpenGL
(
PGraphicsOpenGL
pg
,
int
kind
,
float
...
p
) {
this
(
pg
,
PRIMITIVE
);
setKind
(
kind
);
setParams
(
p
);
}
@
Override
public
void
addChild
(
PShape
who
) {
if
(
who
instanceof
PShapeOpenGL
) {
if
(
family
==
GROUP
) {
PShapeOpenGL
c3d
= (
PShapeOpenGL
)
who
;
super
.
addChild
(
c3d
);
c3d
.
updateRoot
(
root
);
markForTessellation
();
if
(
c3d
.
family
==
GROUP
) {
if
(
c3d
.
textures
!=
null
) {
for
(
PImage
tex
:
c3d
.
textures
) {
addTexture
(
tex
);
}
}
else
{
untexChild
(
true
);
}
if
(
c3d
.
strokedTexture
) {
strokedTexture
(
true
);
}
}
else
{
if
(
c3d
.
image
!=
null
) {
addTexture
(
c3d
.
image
);
if
(
c3d
.
stroke
) {
strokedTexture
(
true
);
}
}
else
{
untexChild
(
true
);
}
}
}
else
{
PGraphics
.
showWarning
(
"Cannot add child shape to non-group shape."
);
}
}
else
{
PGraphics
.
showWarning
(
"Shape must be OpenGL to be added to the group."
);
}
}
@
Override
public
void
addChild
(
PShape
who
,
int
idx
) {
if
(
who
instanceof
PShapeOpenGL
) {
if
(
family
==
GROUP
) {
PShapeOpenGL
c3d
= (
PShapeOpenGL
)
who
;
super
.
addChild
(
c3d
,
idx
);
c3d
.
updateRoot
(
root
);
markForTessellation
();
if
(
c3d
.
family
==
GROUP
) {
if
(
c3d
.
textures
!=
null
) {
for
(
PImage
tex
:
c3d
.
textures
) {
addTexture
(
tex
);
}
}
else
{
untexChild
(
true
);
}
if
(
c3d
.
strokedTexture
) {
strokedTexture
(
true
);
}
}
else
{
if
(
c3d
.
image
!=
null
) {
addTexture
(
c3d
.
image
);
if
(
c3d
.
stroke
) {
strokedTexture
(
true
);
}
}
else
{
untexChild
(
true
);
}
}
}
else
{
PGraphics
.
showWarning
(
"Cannot add child shape to non-group shape."
);
}
}
else
{
PGraphics
.
showWarning
(
"Shape must be OpenGL to be added to the group."
);
}
}
@
Override
public
void
removeChild
(
int
idx
) {
super
.
removeChild
(
idx
);
strokedTexture
(
false
);
untexChild
(
false
);
markForTessellation
();
}
protected
void
updateRoot
(
PShape
root
) {
this
.
root
= (
PShapeOpenGL
)
root
;
if
(
family
==
GROUP
) {
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
child
.
updateRoot
(
root
);
}
}
}
///////////////////////////////////////////////////////////
//
// Shape creation (temporary hack)
public
static
PShapeOpenGL
createShape
(
PGraphicsOpenGL
pg
,
PShape
src
) {
PShapeOpenGL
dest
=
null
;
if
(
src
.
getFamily
() ==
GROUP
) {
//dest = PGraphics3D.createShapeImpl(pg, GROUP);
dest
= (
PShapeOpenGL
)
pg
.
createShapeFamily
(
GROUP
);
copyGroup
(
pg
,
src
,
dest
);
}
else
if
(
src
.
getFamily
() ==
PRIMITIVE
) {
//dest = PGraphics3D.createShapeImpl(pg, src.getKind(), src.getParams());
dest
= (
PShapeOpenGL
)
pg
.
createShapePrimitive
(
src
.
getKind
(),
src
.
getParams
());
PShape
.
copyPrimitive
(
src
,
dest
);
}
else
if
(
src
.
getFamily
() ==
GEOMETRY
) {
//dest = PGraphics3D.createShapeImpl(pg, PShape.GEOMETRY);
dest
= (
PShapeOpenGL
)
pg
.
createShapeFamily
(
PShape
.
GEOMETRY
);
PShape
.
copyGeometry
(
src
,
dest
);
}
else
if
(
src
.
getFamily
() ==
PATH
) {
dest
= (
PShapeOpenGL
)
pg
.
createShapeFamily
(
PShape
.
PATH
);
//dest = PGraphics3D.createShapeImpl(pg, PATH);
PShape
.
copyPath
(
src
,
dest
);
}
dest
.
setName
(
src
.
getName
());
dest
.
width
=
src
.
width
;
dest
.
height
=
src
.
height
;
dest
.
depth
=
src
.
depth
;
return
dest
;
}
/*
static public PShapeOpenGL createShape2D(PGraphicsOpenGL pg, PShape src) {
PShapeOpenGL dest = null;
if (src.getFamily() == GROUP) {
//dest = PGraphics2D.createShapeImpl(pg, GROUP);
dest = (PShapeOpenGL) pg.createShapeFamily(GROUP);
copyGroup2D(pg, src, dest);
} else if (src.getFamily() == PRIMITIVE) {
//dest = PGraphics2D.createShapeImpl(pg, src.getKind(), src.getParams());
dest = (PShapeOpenGL) pg.createShapePrimitive(src.getKind(), src.getParams());
PShape.copyPrimitive(src, dest);
} else if (src.getFamily() == GEOMETRY) {
//dest = PGraphics2D.createShapeImpl(pg, PShape.GEOMETRY);
dest = (PShapeOpenGL) pg.createShapeFamily(PShape.GEOMETRY);
PShape.copyGeometry(src, dest);
} else if (src.getFamily() == PATH) {
//dest = PGraphics2D.createShapeImpl(pg, PATH);
dest = (PShapeOpenGL) pg.createShapeFamily(PShape.PATH);
PShape.copyPath(src, dest);
}
dest.setName(src.getName());
dest.width = src.width;
dest.height = src.height;
return dest;
}
*/
static
public
void
copyGroup
(
PGraphicsOpenGL
pg
,
PShape
src
,
PShape
dest
) {
copyMatrix
(
src
,
dest
);
copyStyles
(
src
,
dest
);
copyImage
(
src
,
dest
);
for
(
int
i
=
0
;
i
<
src
.
getChildCount
();
i
++) {
PShape
c
=
createShape
(
pg
,
src
.
getChild
(
i
));
dest
.
addChild
(
c
);
}
}
/*
static public void copyGroup2D(PGraphicsOpenGL pg, PShape src, PShape dest) {
copyMatrix(src, dest);
copyStyles(src, dest);
copyImage(src, dest);
for (int i = 0; i < src.getChildCount(); i++) {
PShape c = createShape2D(pg, src.getChild(i));
dest.addChild(c);
}
}
*/
///////////////////////////////////////////////////////////
//
// Query methods
@
Override
public
float
getWidth
() {
PVector
min
=
new
PVector
(
Float
.
POSITIVE_INFINITY
,
Float
.
POSITIVE_INFINITY
,
Float
.
POSITIVE_INFINITY
);
PVector
max
=
new
PVector
(
Float
.
NEGATIVE_INFINITY
,
Float
.
NEGATIVE_INFINITY
,
Float
.
NEGATIVE_INFINITY
);
if
(
shapeCreated
) {
getVertexMin
(
min
);
getVertexMax
(
max
);
}
width
=
max
.
x
-
min
.
x
;
return
width
;
}
@
Override
public
float
getHeight
() {
PVector
min
=
new
PVector
(
Float
.
POSITIVE_INFINITY
,
Float
.
POSITIVE_INFINITY
,
Float
.
POSITIVE_INFINITY
);
PVector
max
=
new
PVector
(
Float
.
NEGATIVE_INFINITY
,
Float
.
NEGATIVE_INFINITY
,
Float
.
NEGATIVE_INFINITY
);
if
(
shapeCreated
) {
getVertexMin
(
min
);
getVertexMax
(
max
);
}
height
=
max
.
y
-
min
.
y
;
return
height
;
}
@
Override
public
float
getDepth
() {
PVector
min
=
new
PVector
(
Float
.
POSITIVE_INFINITY
,
Float
.
POSITIVE_INFINITY
,
Float
.
POSITIVE_INFINITY
);
PVector
max
=
new
PVector
(
Float
.
NEGATIVE_INFINITY
,
Float
.
NEGATIVE_INFINITY
,
Float
.
NEGATIVE_INFINITY
);
if
(
shapeCreated
) {
getVertexMin
(
min
);
getVertexMax
(
max
);
}
depth
=
max
.
z
-
min
.
z
;
return
depth
;
}
protected
void
getVertexMin
(
PVector
min
) {
updateTessellation
();
if
(
family
==
GROUP
) {
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
child
.
getVertexMin
(
min
);
}
}
else
{
if
(
hasPolys
) {
tessGeo
.
getPolyVertexMin
(
min
,
firstPolyVertex
,
lastPolyVertex
);
}
if
(
is3D
()) {
if
(
hasLines
) {
tessGeo
.
getLineVertexMin
(
min
,
firstLineVertex
,
lastLineVertex
);
}
if
(
hasPoints
) {
tessGeo
.
getPointVertexMin
(
min
,
firstPointVertex
,
lastPointVertex
);
}
}
}
}
protected
void
getVertexMax
(
PVector
max
) {
updateTessellation
();
if
(
family
==
GROUP
) {
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
child
.
getVertexMax
(
max
);
}
}
else
{
if
(
hasPolys
) {
tessGeo
.
getPolyVertexMax
(
max
,
firstPolyVertex
,
lastPolyVertex
);
}
if
(
is3D
()) {
if
(
hasLines
) {
tessGeo
.
getLineVertexMax
(
max
,
firstLineVertex
,
lastLineVertex
);
}
if
(
hasPoints
) {
tessGeo
.
getPointVertexMax
(
max
,
firstPointVertex
,
lastPointVertex
);
}
}
}
}
protected
int
getVertexSum
(
PVector
sum
,
int
count
) {
updateTessellation
();
if
(
family
==
GROUP
) {
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
count
+=
child
.
getVertexSum
(
sum
,
count
);
}
}
else
{
if
(
hasPolys
) {
count
+=
tessGeo
.
getPolyVertexSum
(
sum
,
firstPolyVertex
,
lastPolyVertex
);
}
if
(
is3D
()) {
if
(
hasLines
) {
count
+=
tessGeo
.
getLineVertexSum
(
sum
,
firstLineVertex
,
lastLineVertex
);
}
if
(
hasPoints
) {
count
+=
tessGeo
.
getPointVertexSum
(
sum
,
firstPointVertex
,
lastPointVertex
);
}
}
}
return
count
;
}
///////////////////////////////////////////////////////////
//
// Drawing methods
@
Override
public
void
setTextureMode
(
int
mode
) {
if
(
openShape
) {
PGraphics
.
showWarning
(
INSIDE_BEGIN_END_ERROR
,
"setTextureMode()"
);
return
;
}
if
(
family
==
GROUP
) {
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
child
.
setTextureMode
(
mode
);
}
}
else
{
setTextureModeImpl
(
mode
);
}
}
protected
void
setTextureModeImpl
(
int
mode
) {
if
(
textureMode
==
mode
)
return
;
textureMode
=
mode
;
if
(
image
!=
null
) {
float
uFactor
=
image
.
width
;
float
vFactor
=
image
.
height
;
if
(
textureMode
==
NORMAL
) {
uFactor
=
1.0f
/
uFactor
;
vFactor
=
1.0f
/
vFactor
;
}
scaleTextureUV
(
uFactor
,
vFactor
);
}
}
@
Override
public
void
setTexture
(
PImage
tex
) {
if
(
openShape
) {
PGraphics
.
showWarning
(
INSIDE_BEGIN_END_ERROR
,
"setTexture()"
);
return
;
}
if
(
family
==
GROUP
) {
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
child
.
setTexture
(
tex
);
}
}
else
{
setTextureImpl
(
tex
);
}
}
protected
void
setTextureImpl
(
PImage
tex
) {
PImage
image0
=
image
;
image
=
tex
;
if
(
textureMode
==
IMAGE
&&
image0
!=
image
) {
// Need to rescale the texture coordinates
float
uFactor
=
1
;
float
vFactor
=
1
;
if
(
image
!=
null
) {
uFactor
/=
image
.
width
;
vFactor
/=
image
.
height
;
}
if
(
image0
!=
null
) {
uFactor
*=
image0
.
width
;
vFactor
*=
image0
.
height
;
}
scaleTextureUV
(
uFactor
,
vFactor
);
}
if
(
image0
!=
tex
&&
parent
!=
null
) {
((
PShapeOpenGL
)
parent
).
removeTexture
(
image0
,
this
);
}
if
(
parent
!=
null
) {
((
PShapeOpenGL
)
parent
).
addTexture
(
image
);
if
(
is2D
() &&
stroke
) {
((
PShapeOpenGL
)
parent
).
strokedTexture
(
true
);
}
}
}
protected
void
scaleTextureUV
(
float
uFactor
,
float
vFactor
) {
if
(
PGraphicsOpenGL
.
same
(
uFactor
,
1
) &&
PGraphicsOpenGL
.
same
(
vFactor
,
1
))
return
;
for
(
int
i
=
0
;
i
<
inGeo
.
vertexCount
;
i
++) {
float
u
=
inGeo
.
texcoords
[
2
*
i
+
0
];
float
v
=
inGeo
.
texcoords
[
2
*
i
+
1
];
inGeo
.
texcoords
[
2
*
i
+
0
] =
PApplet
.
min
(
1
,
u
*
uFactor
);
inGeo
.
texcoords
[
2
*
i
+
1
] =
PApplet
.
min
(
1
,
v
*
uFactor
);
}
if
(
shapeCreated
&&
tessellated
&&
hasPolys
) {
int
last1
=
0
;
if
(
is3D
()) {
last1
=
lastPolyVertex
+
1
;
}
else
if
(
is2D
()) {
last1
=
lastPolyVertex
+
1
;
if
(-
1
<
firstLineVertex
)
last1
=
firstLineVertex
;
if
(-
1
<
firstPointVertex
)
last1
=
firstPointVertex
;
}
for
(
int
i
=
firstLineVertex
;
i
<
last1
;
i
++) {
float
u
=
tessGeo
.
polyTexCoords
[
2
*
i
+
0
];
float
v
=
tessGeo
.
polyTexCoords
[
2
*
i
+
1
];
tessGeo
.
polyTexCoords
[
2
*
i
+
0
] =
PApplet
.
min
(
1
,
u
*
uFactor
);
tessGeo
.
polyTexCoords
[
2
*
i
+
1
] =
PApplet
.
min
(
1
,
v
*
uFactor
);
}
root
.
setModifiedPolyTexCoords
(
firstPolyVertex
,
last1
-
1
);
}
}
protected
void
addTexture
(
PImage
tex
) {
if
(
textures
==
null
) {
textures
=
new
HashSet
<
PImage
>();
}
textures
.
add
(
tex
);
if
(
parent
!=
null
) {
((
PShapeOpenGL
)
parent
).
addTexture
(
tex
);
}
}
protected
void
removeTexture
(
PImage
tex
,
PShapeOpenGL
caller
) {
if
(
textures
==
null
|| !
textures
.
contains
(
tex
))
return
;
// Nothing to remove.
// First check that none of the child shapes have texture tex...
boolean
childHasTex
=
false
;
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
if
(
child
==
caller
)
continue
;
if
(
child
.
hasTexture
(
tex
)) {
childHasTex
=
true
;
break
;
}
}
if
(!
childHasTex
) {
// ...if not, it is safe to remove from this shape.
textures
.
remove
(
tex
);
if
(
textures
.
size
() ==
0
) {
textures
=
null
;
}
}
// Since this shape and all its child shapes don't contain
// tex anymore, we now can remove it from the parent.
if
(
parent
!=
null
) {
((
PShapeOpenGL
)
parent
).
removeTexture
(
tex
,
this
);
}
}
protected
void
strokedTexture
(
boolean
newValue
) {
strokedTexture
(
newValue
,
null
);
}
protected
void
strokedTexture
(
boolean
newValue
,
PShapeOpenGL
caller
) {
if
(
strokedTexture
==
newValue
)
return
;
// Nothing to change.
if
(
newValue
) {
strokedTexture
=
true
;
}
else
{
// Check that none of the child shapes have a stroked texture...
strokedTexture
=
false
;
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
if
(
child
==
caller
)
continue
;
if
(
child
.
hasStrokedTexture
()) {
strokedTexture
=
true
;
break
;
}
}
}
// Now we can update the parent shape.
if
(
parent
!=
null
) {
((
PShapeOpenGL
)
parent
).
strokedTexture
(
newValue
,
this
);
}
}
protected
void
untexChild
(
boolean
newValue
) {
untexChild
(
newValue
,
null
);
}
protected
void
untexChild
(
boolean
newValue
,
PShapeOpenGL
caller
) {
if
(
untexChild
==
newValue
)
return
;
// Nothing to change.
if
(
newValue
) {
untexChild
=
true
;
}
else
{
// Check if any of the child shapes is not textured...
untexChild
=
false
;
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
if
(
child
==
caller
)
continue
;
if
(!
child
.
hasTexture
()) {
untexChild
=
true
;
break
;
}
}
}
// Now we can update the parent shape.
if
(
parent
!=
null
) {
((
PShapeOpenGL
)
parent
).
untexChild
(
newValue
,
this
);
}
}
protected
boolean
hasTexture
() {
if
(
family
==
GROUP
) {
return
textures
!=
null
&&
0
<
textures
.
size
();
}
else
{
return
image
!=
null
;
}
}
protected
boolean
hasTexture
(
PImage
tex
) {
if
(
family
==
GROUP
) {
return
textures
!=
null
&&
textures
.
contains
(
tex
);
}
else
{
return
image
==
tex
;
}
}
protected
boolean
hasStrokedTexture
() {
if
(
family
==
GROUP
) {
return
strokedTexture
;
}
else
{
return
image
!=
null
&&
stroke
;
}
}
@
Override
public
void
solid
(
boolean
solid
) {
if
(
family
==
GROUP
) {
for
(
int
i
=
0
;
i
<
childCount
;
i
++) {
PShapeOpenGL
child
= (
PShapeOpenGL
)
children
[
i
];
child
.
solid
(
solid
);
}
}
else
{
this
.
solid
=
solid
;
}
}
@
Override
protected
void
beginContourImpl
() {
breakShape
=
true
;
}
@
Override
protected
void
endContourImpl
() {
}
@
Override
View remainder of file in raw view
Footer
© 2026 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Community
Docs
Contact
You can’t perform that action at this time.
Back
|
FazBrowse Home
|
New Git URL