From 47cd0f0a3870d843cb758535316060d30f15c811 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Mon, 24 Jun 2019 19:10:13 -0400 Subject: [PATCH] Toolbox + DnD --- CameraPane.java | 277 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 220 insertions(+), 57 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index b4be4fc..3697e29 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -37,7 +37,6 @@ static boolean[] selectedstack = new boolean[65536]; static int materialdepth = 0; - static boolean DEBUG = false; static boolean FRUSTUM = false; // still bogus true; // frustum culling // camera change fix @@ -327,7 +326,7 @@ cStatic.objectstack[materialdepth++] = obj; //System.out.println("material " + material); //Applet3D.tracein(this, selected); - display.vector2buffer = obj.projectedVertices; + //display.vector2buffer = obj.projectedVertices; if (obj instanceof Camera) { display.options1[0] = material.shift; @@ -359,7 +358,7 @@ /**/ } else { - DrawMaterial(material, selected); + DrawMaterial(material, selected, obj.projectedVertices); } } else { @@ -383,8 +382,8 @@ cStatic.objectstack[materialdepth++] = obj; //System.out.println("material " + material); //Applet3D.tracein("selected ", selected); - display.vector2buffer = obj.projectedVertices; - display.DrawMaterial(material, selected); + //display.vector2buffer = obj.projectedVertices; + display.DrawMaterial(material, selected, obj.projectedVertices); } } @@ -401,8 +400,8 @@ materialdepth -= 1; if (materialdepth > 0) { - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); } //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); } else if (selected && CameraPane.flash && obj.GetMaterial() != null) @@ -422,8 +421,8 @@ materialdepth -= 1; if (materialdepth > 0) { - display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; - display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); } //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); //else @@ -464,10 +463,12 @@ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0) { //gl.glBegin(gl.GL_TRIANGLES); - boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0); + boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0) + // TEST LIVE NORMALS && !obj.dontselect + ; if (!hasnorm) { - // System.out.println("FUCK!!"); + // System.out.println("Mesh normal"); LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0); LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1); LA.vecCross(obj.v0, obj.v1, obj.v2); @@ -1192,10 +1193,12 @@ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); } } + if (flipV) gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); else gl.glTexCoord2f(uv[count2], uv[count2 + 1]); + //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); @@ -1215,10 +1218,12 @@ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); } } + if (flipV) gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); else gl.glTexCoord2f(uv[count2], uv[count2 + 1]); + //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); @@ -1246,8 +1251,10 @@ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); else gl.glTexCoord2f(uv[count2], uv[count2 + 1]); + //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]); gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); + count2 += 2; count3 += 3; } @@ -1603,7 +1610,7 @@ // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0); } - void DrawMaterial(cMaterial material, boolean selected) + void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others) { CameraPane display = this; //new Exception().printStackTrace(); @@ -1638,7 +1645,7 @@ colorV[0] = display.modelParams0[0] * material.diffuse; colorV[1] = display.modelParams0[1] * material.diffuse; colorV[2] = display.modelParams0[2] * material.diffuse; - colorV[3] = material.opacity; + colorV[3] = 1; // material.opacity; gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity); //System.out.println("Opacity = " + opacity); @@ -1746,9 +1753,9 @@ display.modelParams7[2] = 0; display.modelParams7[3] = 0; - display.modelParams6[0] = 100; // criss de bug de bump + //display.modelParams6[0] = 100; // criss de bug de bump - Object3D.cVector2[] extparams = display.vector2buffer; + Object3D.cVector2[] extparams = others; // display.vector2buffer; if (extparams != null && extparams.length > 0 && extparams[0] != null) { display.modelParams6[0] = extparams[0].x / 1000.0f; // bump @@ -1890,7 +1897,7 @@ void PushMatrix(double[][] matrix) { // GrafreeD.tracein(matrix); - PushMatrix(matrix,1); + PushMatrix(matrix, 1); } void PushMatrix() @@ -2259,7 +2266,7 @@ void ToggleDebug() { - DEBUG ^= true; + Globals.DEBUG ^= true; } void ToggleLookAt() @@ -7921,6 +7928,64 @@ ReleaseTexture(pigment, false); } + public void ReleasePigmentTexture(cTexture tex) // INTERFACE + { + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) + { + return; + } + + if (tex == null) + { + ReleaseTexture(null, false); + return; + } + + String pigment = Object3D.GetPigment(tex); + + if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + { + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); + // System.out.println("; bump = " + bump); + } + + if (pigment.equals("")) + { + pigment = null; + } + + ReleaseTexture(pigment, false); + } + + public void ReleaseBumpTexture(cTexture tex) // INTERFACE + { + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) + { + return; + } + + if (tex == null) + { + ReleaseTexture(null, true); + return; + } + + String bump = Object3D.GetBump(tex); + + if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + { + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); + // System.out.println("; bump = " + bump); + } + + if (bump.equals("")) + { + bump = null; + } + + ReleaseTexture(bump, true); + } + void ReleaseTexture(String tex, boolean bump) { if (// DrawMode() != 0 || /*tex == null ||*/ @@ -8067,6 +8132,73 @@ GetGL().glActiveTexture(GetGL().GL_TEXTURE0); return; // true; + } + + /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE + { + if (// DrawMode() != 0 || /*tex == null ||*/ + ambientOcclusion ) // || !textureon) + { + return; // false; + } + + if (tex == null) + { + BindTexture(null,false,resolution); + return; + } + + String pigment = Object3D.GetPigment(tex); + + usedtextures.put(pigment, pigment); + + if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + { + // System.out.print("BIND +++++++++++++++ pigment = " + pigment); + // System.out.println("; bump = " + bump); + } + + if (pigment.equals("")) + { + pigment = null; + } + + GetGL().glActiveTexture(GetGL().GL_TEXTURE0); + BindTexture(pigment, false, resolution); + } + + /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE + { + if (// DrawMode() != 0 || /*tex == null ||*/ + ambientOcclusion ) // || !textureon) + { + return; // false; + } + + if (tex == null) + { + BindTexture(null,true,resolution); + return; + } + + String bump = Object3D.GetBump(tex); + + usedtextures.put(bump, bump); + + if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + { + // System.out.print("BIND +++++++++++++++ pigment = " + pigment); + // System.out.println("; bump = " + bump); + } + + if (bump.equals("")) + { + bump = null; + } + + GetGL().glActiveTexture(GetGL().GL_TEXTURE2); + BindTexture(bump, true, resolution); + GetGL().glActiveTexture(GetGL().GL_TEXTURE0); } java.util.HashSet<String> missingTextures = new java.util.HashSet<String>(); @@ -9335,7 +9467,7 @@ if (renderCamera != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); + LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); @@ -9351,7 +9483,7 @@ if (renderCamera != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); + LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); @@ -10416,7 +10548,8 @@ ambientOcclusion = false; } - if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) + if (//Globals.lighttouched && + DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) { //if (RENDERSHADOW) // ? if (!IsFrozen()) @@ -10550,7 +10683,7 @@ // if (parentcam != renderCamera) // not a light if (cam != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); + LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); for (int j = 0; j < 4; j++) { @@ -10565,7 +10698,7 @@ // if (parentcam != renderCamera) // not a light if (cam != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); + LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); @@ -10959,7 +11092,7 @@ // if (cam != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 + LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 } LA.xformDir(lightposition, cam.toScreen, lightposition); @@ -10981,7 +11114,7 @@ { if (cam != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformDir(light0, parentcam.GlobalTransformInv(), light0); // may 2013 + LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013 } LA.xformPos(light0, cam.toScreen, light0); @@ -11326,6 +11459,24 @@ static boolean zoomonce = false; + static void CreateSelectedPoint() + { + if (selectedpoint == null) + { + debugpointG = new Sphere(); + debugpointP = new Sphere(); + debugpointC = new Sphere(); + debugpointR = new Sphere(); + + selectedpoint = new Superellipsoid(); + + for (int i=0; i<8; i++) + { + debugpoints[i] = new Sphere(); + } + } + } + void DrawObject(GL gl, boolean draw) { //System.out.println("DRAW OBJECT " + mouseDown); @@ -11406,8 +11557,9 @@ if (DrawMode() == DEFAULT) { - if (DEBUG) + if (Globals.DEBUG) { + CreateSelectedPoint(); float radius = 0.05f; if (selectedpoint.radius != radius) { @@ -11894,7 +12046,7 @@ for (int i = tp.size(); --i >= 0;) { //for (int count = tp.get(i).GetTransformCount(); --count>=0;) - LA.xformPos(light, tp.get(i).GlobalTransformInv(), light); + LA.xformPos(light, tp.get(i).GlobalTransform(), light); } @@ -11912,7 +12064,7 @@ } //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformPos(light, parentcam.GlobalTransformInv(), light); // may 2013 + LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013 LA.xformPos(light, renderCamera.toScreen, light); @@ -13164,7 +13316,8 @@ /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power - Object3D.cVector2[] vector2buffer; + + //Object3D.cVector2[] vector2buffer; // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea // OUT : diff, spec @@ -13833,6 +13986,8 @@ public void mouseDragged(MouseEvent e) { + Globals.MOUSEDRAGGED = true; + //System.out.println("mouseDragged: " + e); if (isRenderer) movingcamera = true; @@ -14222,7 +14377,8 @@ info.camera = renderCamera; info.x = x; info.y = y; - object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); + object.GetWindow().copy + .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); } else { if (x < startX) @@ -14386,7 +14542,9 @@ ci.camera = renderCamera; if (!isRenderer) { - if (object.editWindow.copy.doEditClick(ci, 0)) + //ObjEditor editWindow = object.editWindow; + //Object3D copy = editWindow.copy; + if (object.doEditClick(ci, 0)) { setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else @@ -14398,6 +14556,8 @@ public void mouseReleased(MouseEvent e) { + Globals.MOUSEDRAGGED = false; + movingcamera = false; X = Y = 0; //System.out.println("mouseReleased: " + e); @@ -14765,8 +14925,14 @@ RevertCamera(); repaint(); break; - case 'L': case 'l': + lightMode ^= true; + Globals.lighttouched = true; + manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; + targetLookAt.set(manipCamera.lookAt); + repaint(); + break; + case 'L': if (lightMode) { lightMode = false; @@ -14913,16 +15079,14 @@ kompactbit = 6; break; case ' ': - lightMode ^= true; - Globals.lighttouched = true; - manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; - targetLookAt.set(manipCamera.lookAt); + ObjEditor.theFrame.ToggleFullScreen(); repaint(); break; //case '`' : case ESC: RENDERPROGRAM += 1; RENDERPROGRAM %= 3; + repaint(); break; case 'Z': @@ -15214,7 +15378,7 @@ } */ - object.editWindow.EditSelection(); + object.editWindow.EditSelection(false); } void SelectParent() @@ -15513,12 +15677,17 @@ { switch (object.selection.get(0).hitSomething) { - case Object3D.hitCenter: gr.setColor(Color.pink); break; - case Object3D.hitRotate: gr.setColor(Color.green); break; - case Object3D.hitScale: gr.setColor(Color.cyan); break; + case Object3D.hitCenter: gr.setColor(Color.pink); + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); + break; + case Object3D.hitRotate: gr.setColor(Color.yellow); + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); + break; + case Object3D.hitScale: gr.setColor(Color.cyan); + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); + break; } - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); } } } @@ -16221,16 +16390,16 @@ cStatic.objectstack[materialdepth++] = checker; //System.out.println("material " + material); //Applet3D.tracein(this, selected); - vector2buffer = checker.projectedVertices; + //vector2buffer = checker.projectedVertices; //checker.GetMaterial().Draw(this, false); // true); - DrawMaterial(checker.GetMaterial(), false); // true); + DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true); materialdepth -= 1; if (materialdepth > 0) { - vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; - DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]); + //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; + DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); } //checker.GetMaterial().opacity = 1f; ////checker.GetMaterial().ambient = 1f; @@ -16453,6 +16622,8 @@ // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]); // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]); // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]); + + CreateSelectedPoint(); // Will fit the mesh !!! selectedpoint.toParent[0][0] = 0.0001; @@ -17093,23 +17264,15 @@ int AAbuffersize = 0; //double[] selectedpoint = new double[3]; - static Superellipsoid selectedpoint = new Superellipsoid(); + static Superellipsoid selectedpoint; static Sphere previousselectedpoint = null; - static Sphere debugpointG = new Sphere(); - static Sphere debugpointP = new Sphere(); - static Sphere debugpointC = new Sphere(); - static Sphere debugpointR = new Sphere(); + static Sphere debugpointG; + static Sphere debugpointP; + static Sphere debugpointC; + static Sphere debugpointR; static Sphere debugpoints[] = new Sphere[8]; - static - { - for (int i=0; i<8; i++) - { - debugpoints[i] = new Sphere(); - } - } - static void InitPoints(float radius) { for (int i=0; i<8; i++) -- Gitblit v1.6.2