Skip to content

Commit

Permalink
- feature: Added quick controls for the UV fields.
Browse files Browse the repository at this point in the history
  - Can hold CTRL + Mousewheel to move UVs in single pixel increments
  - Can hold SHIFT + Mousewheel to move UVs in 0.1 steps
- tweak: re-added 'vs model creator' text in center pane for balduranne
- fixed: fixed highlighted/selected UV rects not visible behind other UVs in the left pane

code cleanup
  • Loading branch information
tyronx committed Feb 5, 2021
1 parent f75e892 commit 1fb35d5
Show file tree
Hide file tree
Showing 7 changed files with 386 additions and 359 deletions.
11 changes: 8 additions & 3 deletions src/at/vintagestory/modelcreator/gui/ControlsDialog.java
Expand Up @@ -55,10 +55,15 @@ public static void show(JFrame parent)
+ "<li>Hold CTRL and click on any up/down arrows of the cubes position to not move the origin</li>"
+ "<li>Focus any of the position/origin/size text fields and use mouse wheel to modify increase/decrease the size in -1/+1 (also works in conjunction with the CTRL and Shift modifiers)</li>"
+ "</ul>"
+ "<p><b>Face Pane (Right)<b></p>"
+ "<p><b>Face Pane, UVs (Right)<b></p>"
+ "<ul>"
+ "<li>Hold SHIFT and mousewheel or click on any of the up/down arrows to modify in increments of 0.1</li>"
+ "<li>Hold CTRL and mousewheel or click on any of the up/down arrows to modify in increments of single texture pixels</li>"
+ "</ul>"
+ "<p><b>Face Pane, Textures (Right)<b></p>"
+ "<ul>"
+ "<li>Press Copy Button and then hold SHIFT + Left Mousue Click the Paste Button to quickly assign a texture to all the faces of a cube</li>"
+ "<li>Press Copy Button and then hold CTRL + SHIFT + Left Mousue Click the Paste Button to quickly assign a texture to all the faces of a cube and all its child elements</li>"
+ "<li>Press Copy Button and then hold CTRL + SHIFT + Left Mouse Click the Paste Button to quickly assign a texture to all the faces of a cube and all its child elements</li>"
+ "<li>Hold SHIFT and toggle 'Enabled', 'Auto Resolution' or 'Snap UV' to toggle it for all faces</li>"
+ "</ul>"
+ "<p><b>Keyframe Pane (Right)<b></p>"
Expand All @@ -84,7 +89,7 @@ public static void show(JFrame parent)

JDialog dialog = new JDialog(parent, "Quick Controls", false);
dialog.setResizable(false);
dialog.setPreferredSize(new Dimension(700, 800));
dialog.setPreferredSize(new Dimension(800, 800));
dialog.add(container);
dialog.pack();
dialog.setLocationRelativeTo(null);
Expand Down
169 changes: 102 additions & 67 deletions src/at/vintagestory/modelcreator/gui/left/LeftUVSidebar.java
Expand Up @@ -17,6 +17,7 @@
import static org.lwjgl.opengl.GL11.glVertex2i;

import java.util.ArrayList;
import java.util.Stack;

import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
Expand All @@ -28,6 +29,7 @@
import at.vintagestory.modelcreator.interfaces.IElementManager;
import at.vintagestory.modelcreator.model.Element;
import at.vintagestory.modelcreator.model.Face;
import at.vintagestory.modelcreator.model.RenderFaceTask;
import at.vintagestory.modelcreator.model.Sized;
import at.vintagestory.modelcreator.model.TextureEntry;

Expand All @@ -49,6 +51,9 @@ public class LeftUVSidebar extends LeftSidebar

int canvasHeight;

Stack<RenderFaceTask> renderLastStack = new Stack<RenderFaceTask>();


public LeftUVSidebar(String title, IElementManager manager)
{
super(title);
Expand Down Expand Up @@ -234,90 +239,120 @@ private void drawElementList(String textureCode, ArrayList<Element> elems, doubl
for (Element elem : elems) {
Face[] faces = elem.getAllFaces();


for (int i = 0; i < 6; i++) {
Face face = faces[i];
if (!face.isEnabled() || (textureCode != null && !textureCode.equals(face.getTextureCode()))) continue;

Sized uv = face.translateVoxelPosToUvPos(face.getStartU(), face.getStartV(), true);
Sized uvend = face.translateVoxelPosToUvPos(face.getEndU(), face.getEndV(), true);

Color color = Face.getFaceColour(i);


GL11.glColor4f(color.r * elem.brightnessByFace[i], color.g * elem.brightnessByFace[i], color.b * elem.brightnessByFace[i], 0.3f);

glBegin(GL_QUADS);
{
glTexCoord2f(0, 1);
glVertex2d(uv.W * texBoxWidth, uvend.H * texBoxHeight);

glTexCoord2f(1, 1);
glVertex2d(uvend.W * texBoxWidth, uvend.H * texBoxHeight);

glTexCoord2f(1, 0);
glVertex2d(uvend.W * texBoxWidth, uv.H * texBoxHeight);

glTexCoord2f(0, 0);
glVertex2d(uv.W * texBoxWidth, uv.H * texBoxHeight);
}
glEnd();


glColor3f(0.5f, 0.5f, 0.5f);
if (elem == selectedElem) {
glColor3f(0f, 0f, 1f);
renderLastStack.push(new RenderFaceTask(face, elem));
continue;
}

if (elem == grabbedElement && face.isAutoUVEnabled()) {
glColor3f(0f, 0.75f, 1f);
renderLastStack.push(new RenderFaceTask(face, elem));
continue;
}

if (elem == grabbedElement && !face.isAutoUVEnabled() && i == grabbedFaceIndex) {
glColor3f(0f, 1f, 0.75f);
}


glBegin(GL_LINES);
{
glVertex2d(uv.W * texBoxWidth, uv.H * texBoxHeight);
glVertex2d(uv.W * texBoxWidth, uvend.H * texBoxHeight);

glVertex2d(uv.W * texBoxWidth, uvend.H * texBoxHeight);
glVertex2d(uvend.W * texBoxWidth, uvend.H * texBoxHeight);

glVertex2d(uvend.W * texBoxWidth, uvend.H * texBoxHeight);
glVertex2d(uvend.W * texBoxWidth, uv.H * texBoxHeight);

glVertex2d(uvend.W * texBoxWidth, uv.H * texBoxHeight);
glVertex2d(uv.W * texBoxWidth, uv.H * texBoxHeight);
renderLastStack.push(new RenderFaceTask(face, elem));
continue;
}

glEnd();



boolean renderName = (ModelCreator.uvShowNames && (!elem.isAutoUnwrapEnabled() || (elem.getUnwrapMode() <= 0 && i ==0) || i == elem.getUnwrapMode() - 1));

if (renderName) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_BLEND);

float width = EnumFonts.BEBAS_NEUE_12.getWidth(elem.getName());
float height = EnumFonts.BEBAS_NEUE_12.getHeight(elem.getName());

int x = (int)((uv.W + (uvend.W - uv.W) / 2) * texBoxWidth - width/2);
int y = (int)((uv.H + (uvend.H - uv.H) / 2) * texBoxHeight - height/2);

EnumFonts.BEBAS_NEUE_12.drawString(x, y, elem.getName(), BLACK_ALPHA);

TextureImpl.bindNone();
}

drawFace(elem, face);

}

drawElementList(textureCode, elem.ChildElements, texBoxWidth, texBoxHeight, canvasHeight);
}

// Needs to be drawn at the end so the selected highlight is always visible
while (renderLastStack.size() > 0) {
RenderFaceTask rft = renderLastStack.pop();
drawFace(rft.elem, rft.face);
}
}

private void drawFace(Element elem, Face face) {
Element selectedElem = ModelCreator.currentProject.SelectedElement;

Sized uv = face.translateVoxelPosToUvPos(face.getStartU(), face.getStartV(), true);
Sized uvend = face.translateVoxelPosToUvPos(face.getEndU(), face.getEndV(), true);

int sidei = face.getSide();

Color color = Face.getFaceColour(sidei);


GL11.glColor4f(color.r * elem.brightnessByFace[sidei], color.g * elem.brightnessByFace[sidei], color.b * elem.brightnessByFace[sidei], 0.3f);

glBegin(GL_QUADS);
{
glTexCoord2f(0, 1);
glVertex2d(uv.W * texBoxWidth, uvend.H * texBoxHeight);

glTexCoord2f(1, 1);
glVertex2d(uvend.W * texBoxWidth, uvend.H * texBoxHeight);

glTexCoord2f(1, 0);
glVertex2d(uvend.W * texBoxWidth, uv.H * texBoxHeight);

glTexCoord2f(0, 0);
glVertex2d(uv.W * texBoxWidth, uv.H * texBoxHeight);
}
glEnd();


glColor3f(0.5f, 0.5f, 0.5f);


if (elem == selectedElem) {
glColor3f(0f, 0f, 1f);
}

if (elem == grabbedElement && face.isAutoUVEnabled()) {
glColor3f(0f, 0.75f, 1f);
}

if (elem == grabbedElement && !face.isAutoUVEnabled() && sidei == grabbedFaceIndex) {
glColor3f(0f, 1f, 0.75f);
}

glBegin(GL_LINES);
{
glVertex2d(uv.W * texBoxWidth, uv.H * texBoxHeight);
glVertex2d(uv.W * texBoxWidth, uvend.H * texBoxHeight);

glVertex2d(uv.W * texBoxWidth, uvend.H * texBoxHeight);
glVertex2d(uvend.W * texBoxWidth, uvend.H * texBoxHeight);

glVertex2d(uvend.W * texBoxWidth, uvend.H * texBoxHeight);
glVertex2d(uvend.W * texBoxWidth, uv.H * texBoxHeight);

glVertex2d(uvend.W * texBoxWidth, uv.H * texBoxHeight);
glVertex2d(uv.W * texBoxWidth, uv.H * texBoxHeight);
}

glEnd();


boolean renderName = (ModelCreator.uvShowNames && (!elem.isAutoUnwrapEnabled() || (elem.getUnwrapMode() <= 0 && sidei ==0) || sidei == elem.getUnwrapMode() - 1));

if (renderName) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_BLEND);

float width = EnumFonts.BEBAS_NEUE_12.getWidth(elem.getName());
float height = EnumFonts.BEBAS_NEUE_12.getHeight(elem.getName());

int x = (int)((uv.W + (uvend.W - uv.W) / 2) * texBoxWidth - width/2);
int y = (int)((uv.H + (uvend.H - uv.H) / 2) * texBoxHeight - height/2);

EnumFonts.BEBAS_NEUE_12.drawString(x, y, elem.getName(), BLACK_ALPHA);

TextureImpl.bindNone();
}
}


Expand Down Expand Up @@ -661,8 +696,8 @@ public void onMouseDownOnPanel()
{
face.setAutoUVEnabled(false);

face.addTextureXEnd(xMovement / scale.W);
face.addTextureYEnd(-yMovement / scale.H);
face.addTextureUEnd(xMovement / scale.W);
face.addTextureVEnd(-yMovement / scale.H);

face.setAutoUVEnabled(false);
}
Expand Down
Expand Up @@ -57,6 +57,7 @@ public void Render(int leftSidebarWidth, int width, int height, int frameHeight)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLU.gluOrtho2D(0, width, height, 0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Expand Down Expand Up @@ -185,10 +186,10 @@ public void drawGridAndElements()
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

/*GL11.glTranslated(8, 0, 16);
GL11.glTranslated(0, 0, 16);
GL11.glScaled(0.018, 0.018, 0.018);
GL11.glRotated(90, 1, 0, 0);
EnumFonts.BEBAS_NEUE_50.drawString(8, 0, "S", new Color(0.5F, 0.5F, 0.6F));*/
EnumFonts.BEBAS_NEUE_50.drawString(8, 0, "VS Model Creator", new Color(0.5F, 0.5F, 0.6F));

GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
Expand Down

0 comments on commit 1fb35d5

Please sign in to comment.