From 0a52bd4800459cd9935f360d7ca9555b6bea2146 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Fri, 19 Jul 2019 20:56:44 -0400
Subject: [PATCH] CSG + paint mode.
---
ObjEditor.java | 13 +-
cMesh.java | 2
CameraPane.java | 77 +++++++++---
GroupEditor.java | 16 +-
CSGEditor.java | 175 +++++++++++++---------------
Object3D.java | 48 +++++++
6 files changed, 204 insertions(+), 127 deletions(-)
diff --git a/CSGEditor.java b/CSGEditor.java
index fe9aa98..01423e2 100644
--- a/CSGEditor.java
+++ b/CSGEditor.java
@@ -10,6 +10,8 @@
import java.util.Vector;
+import grafeme.ui.*;
+
class CSGEditor extends ObjEditor implements ChangeListener, ActionListener, ObjectUI
{
@@ -44,19 +46,18 @@
super.SetupUI2(oe); // Shows composite UI !!
//super.SetupName(oe);
- oe.aConstraints.weighty = 0;
+ oe.ctrlPanel.add(refreshButton = new JButton("Refresh")); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+ oe.ctrlPanel.Return();
- oe.aConstraints.fill = 0;
- oe.aConstraints.gridwidth = 1;
- oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
- oe.ctrlPanel.add(refreshButton = new JButton("Refresh"), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
- oe.aConstraints.gridwidth = 1;
- oe.aConstraints.gridx /* = 0;
- oe.aConstraints.gridy */ += 1;
-
- oe.aConstraints.fill = 0;
- oe.aConstraints.gridwidth = 1;
- //this.csg = (CSG) copy;
+ menuPane = new cGridBag();
+ oe.ctrlPanel.add(menuPane);
+ oe.ctrlPanel.Return();
+
+ menuPane2 = new cGridBag();
+ oe.ctrlPanel.add(menuPane2);
+ oe.ctrlPanel.Return();
+
+ //this.csg = (CSG) copy;
/*
oe.ctrlPanel.add(typeLabel = new JLabel("Type"), oe.aConstraints);
oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
@@ -67,33 +68,26 @@
list.add("Merge");
list.add("Intersection");
list.add("Difference");
- oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
- oe.ctrlPanel.add(typeMenu = new JComboBox(new ObjEditor.cListModel(list, csg.csgType - 1)), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+ menuPane.add(typeMenu = new JComboBox(new ObjEditor.cListModel(list, csg.csgType - 1))); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
//typeMenu.select(csg.csgType - 1);
- oe.aConstraints.gridx += 1;
- //oe.aConstraints.gridy += 1;
- //oe.aConstraints.gridx = 0;
-
+ oe.ctrlPanel.Return();
+
list = new Vector();
list.add("Surface");
list.add("Volume");
list.add("Inner");
list.add("Outer");
list.add("Boundary");
+
/*
oe.aConstraints.fill = 0;
oe.ctrlPanel.add(genLabel = new JLabel("Generation"), oe.aConstraints);
oe.aConstraints.gridx += 1;
*/
- oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
- oe.ctrlPanel.add(genMenu = new JComboBox(new ObjEditor.cListModel(list, 0)), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+ menuPane.add(genMenu = new JComboBox(new ObjEditor.cListModel(list, 0))); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
//typeMenu.select(csg.csgType - 1);
- //oe.aConstraints.gridy += 1;
- oe.aConstraints.gridx += 1;
- oe.ctrlPanel.Return();
-
list = new Vector();
list.add("Smooth");
list.add("Flat");
@@ -102,11 +96,8 @@
oe.ctrlPanel.add(normalsLabel = new JLabel("Shading"), oe.aConstraints);
oe.aConstraints.gridx += 1;
*/
- oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
- oe.ctrlPanel.add(normalsMenu = new JComboBox(new ObjEditor.cListModel(list, 0)), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+ menuPane2.add(normalsMenu = new JComboBox(new ObjEditor.cListModel(list, 0))); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
//typeMenu.select(csg.csgType - 1);
- oe.aConstraints.gridx += 1;
- oe.aConstraints.gridwidth = 1;
list = new Vector();
list.add("Strip");
@@ -117,55 +108,39 @@
oe.ctrlPanel.add(normalsLabel = new JLabel("Shading"), oe.aConstraints);
oe.aConstraints.gridx += 1;
*/
- oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
- oe.ctrlPanel.add(stripifyMenu = new JComboBox(new ObjEditor.cListModel(list, 0)), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+ menuPane2.add(stripifyMenu = new JComboBox(new ObjEditor.cListModel(list, 0))); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
//typeMenu.select(csg.csgType - 1);
- oe.aConstraints.gridy += 1;
- oe.aConstraints.gridx = 0;
- oe.aConstraints.gridwidth = 1;
- //oe.aConstraints.fill = 0;
- oe.ctrlPanel.add(sizeLabel = new JLabel("Depth"), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
- oe.aConstraints.gridx += 1;
- oe.aConstraints.gridwidth = ObjEditor.GRIDWIDTH;
- oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
- oe.ctrlPanel.add(sizeField = new NumberSlider(0,10), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
- oe.aConstraints.gridy += 1;
- oe.aConstraints.gridx = 0;
+// oe.ctrlPanel.add(sizeLabel = new JLabel("Depth")); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+// oe.ctrlPanel.add(sizeSlider = new NumberSlider(0,10)); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+ sizeSliderPane = AddSlider(oe.ctrlPanel, "Depth", 0, 10, 0);
+ sizeSlider = (cNumberSlider)sizeSliderPane.getComponent(1);
+ oe.ctrlPanel.Return();
- oe.aConstraints.fill = 0;
- oe.aConstraints.gridwidth = 1;
- oe.ctrlPanel.add(size2Label = new JLabel("Depth2"), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
- oe.aConstraints.gridx += 1;
- oe.aConstraints.gridwidth = ObjEditor.GRIDWIDTH;
- oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
- oe.ctrlPanel.add(size2Field = new NumberSlider(0,10), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
- oe.aConstraints.gridy += 1;
- oe.aConstraints.gridx = 0;
+// oe.ctrlPanel.add(size2Label = new JLabel("Depth2")); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+// oe.ctrlPanel.add(size2Slider = new NumberSlider(0,10)); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+ size2SliderPane = AddSlider(oe.ctrlPanel, "Depth2", 0, 10, 0);
+ size2Slider = (cNumberSlider)size2SliderPane.getComponent(1);
+ oe.ctrlPanel.Return();
- oe.aConstraints.gridwidth = 1;
- oe.aConstraints.fill = 0;
- oe.ctrlPanel.add(tolLabel = new JLabel("Tolerance"), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
- oe.aConstraints.gridx += 1;
- oe.aConstraints.gridwidth = ObjEditor.GRIDWIDTH;
- oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
- oe.ctrlPanel.add(tolField = new NumberSlider(0,10,1), oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
- oe.aConstraints.gridy += 1;
- oe.aConstraints.gridx = 0;
- oe.aConstraints.gridwidth = 1;
+// oe.ctrlPanel.add(tolLabel = new JLabel("Tolerance")); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+// oe.ctrlPanel.add(toleranceSlider = new NumberSlider(0,10,1)); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2);
+ toleranceSliderPane = AddSlider(oe.ctrlPanel, "Tolerance", 0, 10, 1, 1);
+ toleranceSlider = (cNumberSlider)toleranceSliderPane.getComponent(1);
+ oe.ctrlPanel.Return();
- sizeField.setInteger(csg.cellSize);
- size2Field.setInteger(csg.cellSize2);
+ sizeSlider.setInteger(csg.cellSize);
+ size2Slider.setInteger(csg.cellSize2);
System.out.println("csg.tolerance = " + csg.tolerance);
- tolField.setFloat(csg.tolerance);
+ toleranceSlider.setFloat(csg.tolerance);
normalsMenu.setSelectedIndex(csg.normals?0:1);
typeMenu.setSelectedIndex(csg.csgType - 1);
genMenu.setSelectedIndex(csg.genType);
stripifyMenu.setSelectedIndex(csg.userType); // ==0?0:1);
- sizeField.addChangeListener(this);
- size2Field.addChangeListener(this);
- tolField.addChangeListener(this);
+ sizeSlider.addChangeListener(this);
+ size2Slider.addChangeListener(this);
+ toleranceSlider.addChangeListener(this);
typeMenu.addActionListener(this);
genMenu.addActionListener(this);
@@ -199,24 +174,29 @@
normalsMenu.removeActionListener(this);
refreshButton.removeActionListener(this);
- sizeField.removeChangeListener(this);
- size2Field.removeChangeListener(this);
- tolField.removeChangeListener(this);
- oe.ctrlPanel.remove(sizeField);
- oe.ctrlPanel.remove(size2Field);
- oe.ctrlPanel.remove(tolField);
- oe.ctrlPanel.remove(sizeLabel);
- oe.ctrlPanel.remove(size2Label);
- oe.ctrlPanel.remove(tolLabel);
- oe.ctrlPanel.remove(typeMenu);
- //oe.ctrlPanel.remove(typeLabel);
- oe.ctrlPanel.remove(genMenu);
- //oe.ctrlPanel.remove(genLabel);
- oe.ctrlPanel.remove(normalsMenu);
- oe.ctrlPanel.remove(stripifyMenu);
- //oe.ctrlPanel.remove(normalsLabel);
- oe.ctrlPanel.remove(refreshButton);
- //oe.ctrlPanel.repaint();
+ sizeSlider.removeChangeListener(this);
+ size2Slider.removeChangeListener(this);
+ toleranceSlider.removeChangeListener(this);
+
+ oe.ctrlPanel.remove(this.refreshButton);
+ oe.ctrlPanel.remove(menuPane);
+ oe.ctrlPanel.remove(menuPane2);
+ oe.ctrlPanel.remove(sizeSliderPane);
+ oe.ctrlPanel.remove(size2SliderPane);
+ oe.ctrlPanel.remove(toleranceSliderPane);
+
+// oe.ctrlPanel.remove(sizeLabel);
+// oe.ctrlPanel.remove(size2Label);
+// oe.ctrlPanel.remove(tolLabel);
+// oe.ctrlPanel.remove(typeMenu);
+// //oe.ctrlPanel.remove(typeLabel);
+// oe.ctrlPanel.remove(genMenu);
+// //oe.ctrlPanel.remove(genLabel);
+// oe.ctrlPanel.remove(normalsMenu);
+// oe.ctrlPanel.remove(stripifyMenu);
+// //oe.ctrlPanel.remove(normalsLabel);
+// oe.ctrlPanel.remove(refreshButton);
+// //oe.ctrlPanel.repaint();
super.closeUI();
}
@@ -226,7 +206,7 @@
{
super.doLayout();
labelAndField(typeLabel, typeMenu);
- labelAndField(sizeLabel, sizeField);
+ labelAndField(sizeLabel, sizeSlider);
widgetPos += 5;
}
*/
@@ -252,9 +232,9 @@
public void stateChanged(ChangeEvent e)
{
- if (e.getSource() == sizeField ||
- e.getSource() == size2Field ||
- e.getSource() == tolField)
+ if (e.getSource() == sizeSlider ||
+ e.getSource() == size2Slider ||
+ e.getSource() == toleranceSlider)
{
// Can't choose...
//applySelf();
@@ -272,15 +252,16 @@
csg.genType = genMenu.getSelectedIndex();
csg.normals = normalsMenu.getSelectedIndex() == 0;
csg.userType = stripifyMenu.getSelectedIndex();
- csg.cellSize = sizeField.getInteger();
- csg.cellSize2 = size2Field.getInteger();
- csg.tolerance = tolField.getFloat();
+ csg.cellSize = sizeSlider.getInteger();
+ csg.cellSize2 = size2Slider.getInteger();
+ csg.tolerance = toleranceSlider.getFloat();
if (csg.link2master)
csg.retile();
}
CSG csg;
+
JLabel typeLabel;
JLabel genLabel;
JLabel normalsLabel;
@@ -291,10 +272,16 @@
JComboBox genMenu;
JComboBox normalsMenu;
JComboBox stripifyMenu;
- NumberSlider sizeField;
- NumberSlider size2Field;
- NumberSlider tolField;
+ cNumberSlider sizeSlider;
+ cNumberSlider size2Slider;
+ cNumberSlider toleranceSlider;
+ cGridBag menuPane;
+ cGridBag menuPane2;
+ cGridBag sizeSliderPane;
+ cGridBag size2SliderPane;
+ cGridBag toleranceSliderPane;
+
JButton refreshButton;
//GroupEditor objEditor;
diff --git a/CameraPane.java b/CameraPane.java
index 6286dc1..52608e6 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -2298,10 +2298,17 @@
HANDLES ^= true;
}
+ Object3D paintFolder;
+
void TogglePaint()
{
PAINTMODE ^= true;
paintcount = 0;
+
+ if (PAINTMODE)
+ {
+ paintFolder = GetFolder();
+ }
}
void SwapCamera(int a, int b)
@@ -8503,7 +8510,7 @@
return texture!=null?texture.texturedata:null;
}
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
+ com.sun.opengl.util.texture.Texture BindTexture(String tex, boolean bump, int resolution) throws Exception
{
if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
{
@@ -8515,7 +8522,7 @@
com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
if (texture == null)
- return false;
+ return texture;
/**/
if (textureon || tex.equals("DEFAULT_TEXTURE") || tex.equals("DEFAULT_TEXTURE_BUMP") || tex.equals("WHITE_NOISE")) // || tex.equals("IMMORTAL"))
@@ -16553,6 +16560,14 @@
}
}
+ private Object3D GetFolder()
+ {
+ Object3D folder = object.GetWindow().copy;
+ if (object.GetWindow().copy.selection.Size() > 0)
+ folder = object.GetWindow().copy.selection.elementAt(0);
+ return folder;
+ }
+
class SelectBuffer implements GLEventListener
{
@@ -16632,6 +16647,17 @@
//gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
+ if (PAINTMODE)
+ {
+ if (object.GetWindow().copy.selection.Size() > 0)
+ {
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
+
+ // Make what you paint not selectable.
+ paintobj.ResetSelectable();
+ }
+ }
+
//int tmp = selection_view;
//selection_view = -1;
int temp = DrawMode();
@@ -16643,6 +16669,17 @@
// temp = DEFAULT; // patch for selection debug
Globals.drawMode = temp; // WARNING
+ if (PAINTMODE)
+ {
+ if (object.GetWindow().copy.selection.Size() > 0)
+ {
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
+
+ // Revert.
+ paintobj.RestoreSelectable();
+ }
+ }
+
//gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
// trying different ways of getting the depth info over
@@ -16748,27 +16785,29 @@
if (!movingcamera && !PAINTMODE)
object.GetWindow().ScreenFitPoint(); // fev 2014
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
{
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
-
- Object3D group = new Object3D("inst" + paintcount++);
-
- group.CreateMaterial(); // use a void leaf to select instances
-
- group.add(paintobj); // link
-
- object.GetWindow().SnapObject(group);
-
- Object3D folder = object.GetWindow().copy;
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
if (object.GetWindow().copy.selection.Size() > 0)
- folder = object.GetWindow().copy.selection.elementAt(0);
+ {
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
- folder.add(group);
-
- object.GetWindow().ResetModel();
- object.GetWindow().refreshContents();
+ Object3D inst = new Object3D("inst" + paintcount++);
+
+ inst.CreateMaterial(); // use a void leaf to select instances
+
+ inst.add(paintobj); // link
+
+ object.GetWindow().SnapObject(inst);
+
+ Object3D folder = paintFolder; // GetFolder();
+
+ folder.add(inst);
+
+ object.GetWindow().ResetModel();
+ object.GetWindow().refreshContents();
+ }
}
else
paintcount = 0;
diff --git a/GroupEditor.java b/GroupEditor.java
index 1e0e863..9edd20b 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -80,18 +80,20 @@
this.copy = this.group = copy;
//selectees = this.group.selectees;
- if (copy.versions == null)
- {
- copy.versions = new byte[100][];
- copy.versionindex = -1;
- }
-
SetupMenu2(this); //objEditor);
SetupUI2(objEditor);
objEditor.SetupUI(true);
SetupViews(objEditor);
((cRadio)radioPanel.getComponent(0)).SetCamera(cameraView.renderCamera, true);
+
+ if (copy.versions == null)
+ {
+ copy.versions = new byte[100][];
+ copy.versionindex = -1;
+
+ Save(true);
+ }
}
void CloneSelection(boolean supports)
@@ -4798,7 +4800,7 @@
void refreshContents(boolean cp)
{
- if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Info"))
+ if (objectPanel.getSelectedIndex() == 2) // objectPanel.indexOfTab("Info"))
if (!Globals.MOUSEDRAGGED && group.selection != null) // && !Globals.TIMERRUNNING)
{
objEditor.ClearInfo(); // .GetMaterial());
diff --git a/ObjEditor.java b/ObjEditor.java
index 30d64e6..f3f020f 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -327,8 +327,8 @@
if (copy.versions == null)
{
- copy.versions = new byte[100][];
- copy.versionindex = -1;
+// copy.versions = new byte[100][];
+// copy.versionindex = -1;
}
SetupMenu();
@@ -974,7 +974,7 @@
// NumberSlider vDivsField;
// JCheckBox endcaps;
JCheckBox liveCB;
- JCheckBox selectCB;
+ JCheckBox selectableCB;
JCheckBox hideCB;
JCheckBox link2masterCB;
JCheckBox markCB;
@@ -1186,9 +1186,10 @@
liveCB = AddCheckBox(setupPanel, "Live", copy.live);
liveCB.setToolTipText("Animate object");
- selectCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
- selectCB.setToolTipText("Make object selectable");
+ selectableCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
+ selectableCB.setToolTipText("Make object selectable");
// Return();
+
hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
hideCB.setToolTipText("Hide object");
markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
@@ -3250,7 +3251,7 @@
{
copy.live ^= true;
return;
- } else if (event.getSource() == selectCB)
+ } else if (event.getSource() == selectableCB)
{
copy.dontselect ^= true;
return;
diff --git a/Object3D.java b/Object3D.java
index 94907db..0fe5ff5 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -29,7 +29,7 @@
Object3D saveskeleton;
//
- byte[] versions[] = new byte[100][];
+ byte[] versions[];
int versionindex = -1;
ScriptNode scriptnode;
@@ -426,6 +426,7 @@
}
boolean live = false;
+ transient boolean keepdontselect;
boolean dontselect = false;
boolean hide = false;
boolean link2master = false; // performs reset support/master at each frame
@@ -5420,6 +5421,51 @@
blockloop = false;
}
+ void ResetSelectable()
+ {
+ if (blockloop)
+ return;
+
+ blockloop = true;
+
+ keepdontselect = dontselect;
+ dontselect = true;
+
+ Object3D child;
+ int nb = Size();
+ for (int i = 0; i < nb; i++)
+ {
+ child = (Object3D) get(i);
+ if (child == null)
+ continue;
+ child.ResetSelectable();
+ }
+
+ blockloop = false;
+ }
+
+ void RestoreSelectable()
+ {
+ if (blockloop)
+ return;
+
+ blockloop = true;
+
+ dontselect = keepdontselect;
+
+ Object3D child;
+ int nb = Size();
+ for (int i = 0; i < nb; i++)
+ {
+ child = (Object3D) get(i);
+ if (child == null)
+ continue;
+ child.RestoreSelectable();
+ }
+
+ blockloop = false;
+ }
+
boolean IsSelected()
{
if (parent == null)
diff --git a/cMesh.java b/cMesh.java
index 9bf2540..a31f4dd 100644
--- a/cMesh.java
+++ b/cMesh.java
@@ -560,6 +560,8 @@
maxima = new cVector();
}
+ CameraPane.CreateSelectedPoint();
+
// ref.getBounds(minima, maxima, true);
// Phys.reference.set((maxima.x+minima.x)/2,(maxima.y+minima.y)/2,(maxima.z+minima.z)/2);
//ref.
--
Gitblit v1.6.2