Normand Briere
2019-04-23 ec9d13e42c9c8674739acefb0769a9273a1048c9
Object3D.java
....@@ -5,6 +5,7 @@
55 import java.util.Vector;
66
77 import javax.media.j3d.Transform3D;
8
+import javax.media.opengl.GL;
89 import javax.vecmath.Vector3d;
910
1011 import javax.imageio.ImageIO;
....@@ -5371,7 +5372,7 @@
53715372 return;
53725373 }
53735374
5374
- javax.media.opengl.GL gl = display.GetGL();
5375
+ //javax.media.opengl.GL gl = display.GetGL();
53755376
53765377 /*
53775378 if (touched)
....@@ -5423,7 +5424,7 @@
54235424 //if (displaylist == -1 && usecalllists)
54245425 if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
54255426 {
5426
- bRep.displaylist = gl.glGenLists(1);
5427
+ bRep.displaylist = display.GenList();
54275428 assert(bRep.displaylist != 0);
54285429 // System.err.println("glGenLists: " + bRep.displaylist + " for " + this);
54295430 //System.out.println("\tgen list " + list);
....@@ -5435,14 +5436,16 @@
54355436 if (usecalllists)
54365437 {
54375438 // System.err.println("new list " + bRep.displaylist + " for " + this);
5438
- gl.glNewList(bRep.displaylist, gl.GL_COMPILE); //_AND_EXECUTE);
5439
+ display.NewList(bRep.displaylist);
54395440 }
5441
+
54405442 CallList(display, root, selected, blocked);
5443
+
54415444 // compiled = true;
54425445 if (usecalllists)
54435446 {
54445447 // System.err.println("end list " + bRep.displaylist + " for " + this);
5445
- gl.glEndList();
5448
+ display.EndList();
54465449 }
54475450 //gl.glDrawBuffer(gl.GL_BACK);
54485451 // XXX touched = false;
....@@ -5490,7 +5493,7 @@
54905493 if (display.DrawMode() == iCameraPane.SHADOW)
54915494 {
54925495 if (!link2master // tricky to cull in shadow mode.
5493
- && GetBRep().FrustumCull(this, gl, display.LightCamera(), true))
5496
+ && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
54945497 {
54955498 //System.out.print("CULLED");
54965499 culled = true;
....@@ -5498,7 +5501,7 @@
54985501 }
54995502 else
55005503 //GetBRep().getBounds(v0, v1, this);
5501
- if (GetBRep().FrustumCull(this, gl, display.RenderCamera(), false))
5504
+ if (GetBRep().FrustumCull(this, null, display.RenderCamera(), false))
55025505 culled = true;
55035506
55045507 // LA.xformPos(v0, display.renderCamera.toScreen, v0);
....@@ -5538,7 +5541,7 @@
55385541 {
55395542 if (GetBRep() != null)
55405543 {
5541
- CameraPane.NextIndex(this, gl);
5544
+ display.NextIndex();
55425545 // vertex color conflict : gl.glCallList(list);
55435546 DrawNode(display, root, selected);
55445547 if (this instanceof BezierPatch)
....@@ -5595,7 +5598,7 @@
55955598
55965599 // System.err.println("glCallList: " + bRep.displaylist + " for " + this);
55975600 assert(bRep.displaylist != 0);
5598
- gl.glCallList(bRep.displaylist);
5601
+ display.CallList(bRep.displaylist);
55995602 // june 2013 drawSelf(display, root, selected);
56005603 }
56015604 }
....@@ -5897,7 +5900,7 @@
58975900
58985901 // bRep.lock = true;
58995902
5900
- javax.media.opengl.GL gl = display.GetGL();
5903
+ //javax.media.opengl.GL gl = display.GetGL();
59015904
59025905 if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
59035906 {
....@@ -5914,23 +5917,7 @@
59145917
59155918 bRep.getMinMax(min, max, 100);
59165919
5917
- gl.glBegin(gl.GL_LINES);
5918
-
5919
- gl.glVertex3d(min.x, min.y, min.z);
5920
- gl.glVertex3d(min.x, min.y, max.z);
5921
- gl.glVertex3d(min.x, min.y, min.z);
5922
- gl.glVertex3d(min.x, max.y, min.z);
5923
- gl.glVertex3d(min.x, min.y, min.z);
5924
- gl.glVertex3d(max.x, min.y, min.z);
5925
-
5926
- gl.glVertex3d(max.x, max.y, max.z);
5927
- gl.glVertex3d(min.x, max.y, max.z);
5928
- gl.glVertex3d(max.x, max.y, max.z);
5929
- gl.glVertex3d(max.x, min.y, max.z);
5930
- gl.glVertex3d(max.x, max.y, max.z);
5931
- gl.glVertex3d(max.x, max.y, min.z);
5932
-
5933
- gl.glEnd();
5920
+ display.DrawBox(min, max);
59345921
59355922 return;
59365923 }
....@@ -5984,178 +5971,14 @@
59845971 new Exception().printStackTrace();
59855972 return;
59865973 }
5987
-
5988
- // TRIANGLE STRIP ARRAY
5989
- if (bRep.trimmed)
5990
- {
5991
- float[] v = bRep.getRawVertices();
5992
- float[] n = bRep.getRawNormals();
5993
- float[] c = bRep.getRawColors();
5994
- float[] uv = bRep.getRawUVMap();
5995
-
5996
- int count2 = 0;
5997
- int count3 = 0;
5998
-
5999
- if (n.length > 0)
6000
- {
6001
- for (int i = 0; i < strips.length; i++)
6002
- {
6003
- gl.glBegin(gl.GL_TRIANGLE_STRIP);
6004
-
6005
- /*
6006
- boolean locked = false;
6007
- float eps = 0.1f;
6008
- boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
6009
-
6010
- int dot = 0;
6011
-
6012
- if ((dot&1) == 0)
6013
- dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
6014
-
6015
- if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
6016
- gl.glTexCoord2f((float) qv.s, (float) qv.t);
6017
- else
6018
- {
6019
- locked = true;
6020
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
6021
- }
6022
- //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
6023
- gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
6024
- if (hasnorm)
6025
- {
6026
- //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
6027
- gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
6028
- }
6029
-
6030
- if ((dot&4) == 0)
6031
- dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
6032
-
6033
- if (wrap || !locked && (dot&8) != 0)
6034
- gl.glTexCoord2f((float) rv.s, (float) rv.t);
6035
- else
6036
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
6037
-
6038
- f.dot = dot;
6039
- */
6040
-
6041
- if (!selectmode)
6042
- {
6043
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
6044
- {
6045
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
6046
- } else
6047
- {
6048
- gl.glNormal3f(0, 0, 1);
6049
- }
6050
-
6051
- if (c != null)
6052
- //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
6053
- {
6054
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
6055
- }
6056
- }
6057
- if (flipV)
6058
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
6059
- else
6060
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
6061
- //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
6062
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
6063
-
6064
- count2 += 2;
6065
- count3 += 3;
6066
- if (!selectmode)
6067
- {
6068
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
6069
- {
6070
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
6071
- } else
6072
- {
6073
- gl.glNormal3f(0, 0, 1);
6074
- }
6075
- if (c != null)
6076
- {
6077
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
6078
- }
6079
- }
6080
- if (flipV)
6081
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
6082
- else
6083
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
6084
- //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
6085
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
6086
-
6087
- count2 += 2;
6088
- count3 += 3;
6089
- for (int j = 0; j < strips[i] - 2; j++)
6090
- {
6091
- //gl.glTexCoord2d(...);
6092
- if (!selectmode)
6093
- {
6094
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
6095
- {
6096
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
6097
- } else
6098
- {
6099
- gl.glNormal3f(0, 0, 1);
6100
- }
6101
- if (c != null)
6102
- {
6103
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
6104
- }
6105
- }
6106
-
6107
- if (flipV)
6108
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
6109
- else
6110
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
6111
- //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
6112
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
6113
- count2 += 2;
6114
- count3 += 3;
6115
- }
6116
-
6117
- gl.glEnd();
6118
- }
6119
- }
6120
-
6121
- assert count3 == v.length;
6122
- }
6123
- else // !trimmed
6124
- {
6125
- int count = 0;
6126
- for (int i = 0; i < strips.length; i++)
6127
- {
6128
- gl.glBegin(gl.GL_TRIANGLE_STRIP);
6129
-
6130
- Vertex p = bRep.GetVertex(bRep.indices[count++]);
6131
- Vertex q = bRep.GetVertex(bRep.indices[count++]);
6132
-
6133
- drawVertex(gl, p, selectmode);
6134
- drawVertex(gl, q, selectmode);
6135
-
6136
- for (int j = 0; j < strips[i] - 2; j++)
6137
- {
6138
- Vertex r = bRep.GetVertex(bRep.indices[count++]);
6139
-
6140
-// if (j%2 == 0)
6141
-// drawFace(p, q, r, display, null);
6142
-// else
6143
-// drawFace(p, r, q, display, null);
6144
-
6145
-// p = q;
6146
-// q = r;
6147
- drawVertex(gl, r, selectmode);
6148
- }
6149
-
6150
- gl.glEnd();
6151
- }
6152
- }
5974
+
5975
+ display.DrawGeometry(bRep, flipV, selectmode);
61535976 } else // catch (Error e)
61545977 {
61555978 // TRIANGLE ARRAY
61565979 if (IsOpaque()) // Static())
61575980 {
6158
- gl.glBegin(gl.GL_TRIANGLES);
5981
+ display.StartTriangles();
61595982 int facecount = bRep.FaceCount();
61605983 for (int i = 0; i < facecount; i++)
61615984 {
....@@ -6220,7 +6043,7 @@
62206043
62216044 display.DrawFace(this, p, q, r, face);
62226045 }
6223
- gl.glEnd();
6046
+ display.EndTriangles();
62246047 }
62256048 else
62266049 {
....@@ -6249,8 +6072,8 @@
62496072 //System.out.println("SORT");
62506073
62516074 java.util.Arrays.sort(facescompare);
6252
-
6253
- gl.glBegin(gl.GL_TRIANGLES);
6075
+
6076
+ display.StartTriangles();
62546077 for (int i = 0; i < facecount; i++)
62556078 {
62566079 Face face = bRep.GetFace(facescompare[i].index);
....@@ -6264,11 +6087,12 @@
62646087
62656088 display.DrawFace(this, p, q, r, face);
62666089 }
6267
- gl.glEnd();
6090
+ display.EndTriangles();
62686091 }
62696092
62706093 if (false) // live && support != null && support.bRep != null) // debug weights
62716094 {
6095
+ /*
62726096 gl.glDisable(gl.GL_LIGHTING);
62736097 float[] colorV = new float[3];
62746098
....@@ -6347,6 +6171,7 @@
63476171 // gl.glEnd();
63486172 }
63496173 }
6174
+ */
63506175 }
63516176 }
63526177
....@@ -6405,22 +6230,6 @@
64056230 void Print(Vertex v)
64066231 {
64076232 //System.err.println("(" + v.x + ", " + v.y + ", " + v.z + ")");
6408
- }
6409
-
6410
- void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean selectmode)
6411
- {
6412
- if (!selectmode)
6413
- {
6414
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
6415
- gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
6416
-
6417
- if (flipV)
6418
- gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
6419
- else
6420
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
6421
- }
6422
-
6423
- gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
64246233 }
64256234
64266235 void drawSelf(ClickInfo info, int level, boolean select)