First commit
This commit is contained in:
Executable
+665
@@ -0,0 +1,665 @@
|
||||
@tool
|
||||
class_name PdDocs
|
||||
## In-plugin documentation: a resizable window with a section list on the
|
||||
## left and the full user guide on the right. Covers every button, tool,
|
||||
## menu, mode and workflow of the plugin, with how-tos and use cases.
|
||||
|
||||
const ACCENT := "4da3ff"
|
||||
|
||||
# ------------------------------------------------------------- links -----
|
||||
# Public pages opened in the OS browser: from the docs window's top line
|
||||
# and from the links row at the top of the Welcome page.
|
||||
const URL_PLUGIN := "https://choco-ted.itch.io/polydoodle"
|
||||
const URL_RATE := "https://choco-ted.itch.io/polydoodle/rate?source=game"
|
||||
const URL_OTHER := "https://choco-ted.itch.io/"
|
||||
|
||||
const SECTIONS := [
|
||||
["Welcome", "welcome"],
|
||||
["The Two Workspaces", "workspaces"],
|
||||
["Toolbar Reference", "toolbar"],
|
||||
["Object Mode", "mode_object"],
|
||||
["Vertex / Edge / Face Modes", "mode_elements"],
|
||||
["Draw Mode", "mode_draw"],
|
||||
["Gizmos: Move, Scale & Rotate", "gizmos"],
|
||||
["Grid, Snapping & Views", "views"],
|
||||
["Hierarchy Panel", "hierarchy"],
|
||||
["Texture Editor: Painting", "paint"],
|
||||
["Brush, Fill & Pixel Tools", "paint_tools"],
|
||||
["Smooth & Pixel Filter Modes", "filter"],
|
||||
["Texture Resolution", "resolution"],
|
||||
["Import Images (Stickers)", "stickers"],
|
||||
["Texture Editor: Edit UV", "uv"],
|
||||
["Rotate & Scale UVs", "rotate"],
|
||||
["Undo, Save & Open", "files"],
|
||||
["Import 3D Models", "import3d"],
|
||||
["Export for Godot", "export"],
|
||||
["Keyboard & Mouse Map", "keys"],
|
||||
["Use Cases & Workflows", "usecases"],
|
||||
["Troubleshooting", "trouble"],
|
||||
]
|
||||
|
||||
const BODY := """
|
||||
[h2]Welcome to Polydoodle[/h2]
|
||||
[b]Enjoying Polydoodle?[/b] [color=#4da3ff][url=[[RATE]]]★ Rate this plugin[/url][/color] · [color=#4da3ff][url=[[PLUGIN]]]Plugin page[/url][/color] · [color=#4da3ff][url=[[OTHER]]]My other works[/url][/color]
|
||||
Polydoodle is a cute little poly modeler that lives inside the Godot
|
||||
editor. It gives you two connected workspaces: a [b]3D modeler[/b] for
|
||||
building low-poly shapes from primitives, freehand doodles and per-element
|
||||
editing, and a [b]texture editor[/b] for painting textures and editing UVs
|
||||
on those shapes. Everything you make can be exported straight into Godot
|
||||
as a mesh, a scene, an OBJ (with its texture), or dropped into the current
|
||||
scene.
|
||||
[color=#4da3ff]Use case:[/color] model a low-poly dungeon prop, paint its
|
||||
texture in the same editor, and export it - without ever leaving Godot.
|
||||
|
||||
[h2]The Two Workspaces[/h2]
|
||||
The [b]first toolbar button[/b] is a joined pair: [b]3D Editor[/b] |
|
||||
[b]Texture Editor[/b] (or press [b]6[/b]). Exactly one half is active.
|
||||
[color=#4da3ff]3D Editor[/color] - the classic quad view (Top / Perspective /
|
||||
Side / Front) with all modeling tools: selection modes, drawing, gizmos,
|
||||
mesh context menus, the hierarchy and the properties panel.
|
||||
[color=#4da3ff]Texture Editor[/color] - the 3D viewport moves to the top and
|
||||
the [b]texture canvas[/b] takes the lower half. The top toolbar swaps the
|
||||
modeling buttons for the texture tools (Paint | Edit UV, brush, fill,
|
||||
pixel, import, snap, rotate, detach) - sliders and deeper settings live in
|
||||
the right panel. The modeling buttons come back when you return to the 3D
|
||||
editor.
|
||||
|
||||
[h2]Toolbar Reference[/h2]
|
||||
[color=#4da3ff]Workspace pair[/color] - switch between the 3D editor and the
|
||||
texture editor (key 6).
|
||||
[color=#4da3ff]Object / Vertex / Edge / Face[/color] - the four selection
|
||||
modes (keys 1-4). Their buttons are exclusive: exactly one is active.
|
||||
[color=#4da3ff]Draw[/color] - a split button: the main half enters Draw mode
|
||||
(key 5) with the current shape; the small arrow half opens the shape menu
|
||||
(Freehand, Rectangle, Circle, Triangle, Pentagon, Hexagon, Star, Torus).
|
||||
The main icon always shows the current shape.
|
||||
[color=#4da3ff]Move | Scale | Rotate Gizmo[/color] - the gizmo buttons show
|
||||
the move arrows, the scale handles or the rotation rings on the selection.
|
||||
The active one is pressed; click it again to hide the gizmo. In the 3D
|
||||
workspace the keys [b]G / S / R[/b] pick the Move / Scale / Rotate gizmo
|
||||
(pressing the active one's key hides it again).
|
||||
[color=#4da3ff]Snap / Grid / Both Sides[/color] - grid snapping on/off (T,
|
||||
off by default), grid visibility (V), and rendering both sides of every
|
||||
face without backface culling (B, on by default).
|
||||
[color=#4da3ff]Add[/color] - the FIRST button of the toolbar group, right after
|
||||
the workspace switch. Insert a primitive: Cube, Plane, Cylinder,
|
||||
Sphere, Prism or Torus.
|
||||
[color=#4da3ff]Duplicate / Delete[/color] - duplicate the selection
|
||||
(Ctrl+D) or delete it (Del).
|
||||
[color=#4da3ff]Undo / Redo[/color] - step history back or forward
|
||||
(Ctrl+Z / Ctrl+Shift+Z).
|
||||
[color=#4da3ff]Save / Open[/color] - write or load a .pdoodle project file.
|
||||
[color=#4da3ff]Import Model[/color] - bring in an existing 3D model (OBJ, glTF /
|
||||
GLB, FBX) together with its textures.
|
||||
[color=#4da3ff]Export[/color] - Mesh (.tres), Scene (.tscn), OBJ
|
||||
(+ .mtl + texture PNG), or add the model to the current scene.
|
||||
[color=#4da3ff]Background color[/color] - the color swatch on the right
|
||||
tints all viewports.
|
||||
[color=#4da3ff]Gear[/color] - editor settings: 3D shading mode (Shaded + Wire,
|
||||
Shaded, Wireframe), grid visibility, the [b]Contextual Hints[/b] toggle
|
||||
that shows or hides the in-viewport tip lines, and the [b]Checkerboard[/b]
|
||||
section: [b]Show Checkerboard[/b] (hide it and every unpainted texel is
|
||||
fully transparent in all views - and exports transparent) and
|
||||
[b]Bake Into Export[/b] (force the checkerboard into every exported texture
|
||||
so nothing is transparent). The popup opens on the
|
||||
right, right-aligned under the gear, and always stays inside the plugin
|
||||
area.
|
||||
[color=#4da3ff]Book[/color] - this documentation.
|
||||
|
||||
[h2]Object Mode (1)[/h2]
|
||||
Click a shape to select it. [b]Shift+Click[/b] adds to the selection,
|
||||
clicking an already-selected object keeps the whole multi-selection so a
|
||||
drag moves every part together. Drag empty space in a 2D view to
|
||||
box-select. Drag the selection (or use the gizmo) to move it. In the 3D
|
||||
view, dragging empty space orbits and a plain click on empty space
|
||||
deselects. [b]Ctrl+drag[/b] rectangle-selects several objects at once.
|
||||
Right-click opens the object menu (Duplicate, Delete, Select All,
|
||||
Deselect) in the 3D view AND in every 2D view. The right panel edits the
|
||||
selected object's name, position and scale numerically.
|
||||
[color=#4da3ff]Use case:[/color] lay out a whole scene of props, then
|
||||
multi-select and move them as one group.
|
||||
|
||||
[h2]Vertex / Edge / Face Modes (2-4)[/h2]
|
||||
These edit the active object's elements. Click a vertex, edge or face to
|
||||
select it (Shift adds, clicking a selected one removes it), then drag to
|
||||
move it. Drag empty space in 2D views to box-select; in the 3D view
|
||||
[b]Ctrl+drag[/b] rectangle-selects. Right-click in the 3D view OR any 2D
|
||||
view offers the mesh operations of the mode:
|
||||
[b]Vertex:[/b] Merge Vertices (weld to the centroid), Delete, Select All.
|
||||
[b]Edge:[/b] Extrude Edges (push fins out of the selected edges), Delete.
|
||||
[b]Face:[/b] with several faces selected the menu offers BOTH extrude
|
||||
modes - [b]Extrude Faces (Individual)[/b] pushes every face along its
|
||||
own normal, [b]Extrude Faces (Combined)[/b] moves the whole selection
|
||||
as ONE region: edges shared between selected faces get no wall and the
|
||||
sheet lifts along the average normal, exactly like a single face. The
|
||||
selected faces MOVE in both: side walls connect the old boundary to the
|
||||
moved copy which becomes the selection (drag it to keep extruding; no
|
||||
leftover face stays behind at the old spot), [b]Inset Face(s)[/b] /
|
||||
[b]Outset Face(s)[/b] - the face's vertex ring moves toward (or away
|
||||
from) the face center in its own plane: one coplanar quad strip per
|
||||
original edge plus the smaller / larger inner face, the surface stays
|
||||
closed and NOTHING overlaps (no duplicate faces; new faces inherit the
|
||||
face's color; the depth comes from the right panel's Inset slider),
|
||||
Fill Face(s) with the current paint color, Clear Face Paint, Delete.
|
||||
[color=#4da3ff]Use case:[/color] select the top face of a cube and extrude it
|
||||
twice for a tower; select its four side vertices and merge them into a
|
||||
pyramid tip.
|
||||
|
||||
[h2]Draw Mode (5)[/h2]
|
||||
Pick a shape from the Draw split button, then drag in ANY viewport:
|
||||
[list][*][b]Freehand[/b] - sketch a closed loop; it becomes a "Doodle"
|
||||
polygon face (self-crossing loops are triangulated robustly).
|
||||
[*][b]Rectangle[/b] - drags a true rectangle.
|
||||
[*][b]Circle[/b] - drags an ellipse (Shift = circle).
|
||||
[*][b]Triangle / Pentagon / Hexagon / Star[/b] - regular n-gons fitted to
|
||||
the drag rect (Shift = square rect).
|
||||
[*][b]Torus[/b] - drags a full 3D torus; the drag defines the outer
|
||||
radius and the ring sits on the surface or plane under the cursor.[/list]
|
||||
In the 3D viewport the shape is drawn on the face under the cursor (or a
|
||||
horizontal plane through the selection) - draw straight onto walls and
|
||||
floors. The preview outline follows the drag; release to create. Every
|
||||
shape lands as a normal editable object.
|
||||
[color=#4da3ff]Use case:[/color] draw a star flat on the ground, extrude its
|
||||
face, and you have a badge; draw a torus on the floor for a ring gate.
|
||||
|
||||
[h2]Gizmos: Move, Scale & Rotate[/h2]
|
||||
The gizmo buttons show handles on the current selection's center. The
|
||||
gizmo only appears when something is actually selected: a shape in Object
|
||||
mode, or vertices / edges / faces in the element modes. With nothing
|
||||
selected, turning a gizmo on shows a notice telling you what to select.
|
||||
[b]Move gizmo:[/b] drag an axis arrow to slide the selection along that
|
||||
world axis; drag near the center chip for direct element dragging.
|
||||
[b]Scale gizmo:[/b] the axis tips are little cubes - drag one to scale
|
||||
that single axis; the [b]center cube[/b] scales the selection uniformly.
|
||||
Scale factor 1.0 is the untouched size; snapping quantizes to 0.05 steps
|
||||
when enabled. The scale gizmo works on whole objects AND on selected
|
||||
vertices/edges/faces (it scales their positions around the selection
|
||||
center). Direct dragging without the gizmo always works too.
|
||||
[b]Rotate gizmo:[/b] drag a ring to spin the selection around that axis
|
||||
(15-degree steps while snapping is on). In the 3D view there is one ring
|
||||
per world axis; in the Top/Front/Side 2D views there is a single ring
|
||||
around the view's own axis, and the object always turns the same way
|
||||
your cursor does. Rotating always edits actual vertex positions around
|
||||
the selection center.
|
||||
[color=#4da3ff]Use case:[/color] select a wall, switch to the scale gizmo, and
|
||||
drag the Y cube to change its height without touching the plan size; or
|
||||
spin a prop 45 degrees on the ground plane with the rotate ring.
|
||||
|
||||
[h2]Shading: Flat or Smooth (per object)[/h2]
|
||||
Every object carries its own shading flag. The [b]Shading[/b] row
|
||||
([b]Flat | Smooth[/b]) lives in the right panel's Object group, and each
|
||||
hierarchy row shows a small toggle for it too. [b]Flat[/b] (default)
|
||||
keeps the hard faceted low-poly look - every face shades with its own
|
||||
normal. [b]Smooth[/b] averages the normals wherever faces share a
|
||||
vertex, so rounded shapes (spheres, cylinders, tori) shade continuously.
|
||||
The flag is undoable, saved in project files, and exported: .tres/.tscn
|
||||
meshes carry the smooth normals and OBJ exports write s on / s off per
|
||||
object.
|
||||
|
||||
[h2]Grid, Snapping & Views[/h2]
|
||||
[b]Snap (S)[/b] lands moves, shapes, gizmo drags and scale factors on the
|
||||
grid. The grid step is the plugin's world unit. [b]Grid (V)[/b] hides the
|
||||
grid lines but snapping keeps working. Every viewport has corner buttons:
|
||||
the 2D views (Top/Front/Side) have a [b]flip button[/b] showing the
|
||||
opposite view (Bottom/Back/Left) - picking and painting follow the flip
|
||||
automatically - and EVERY viewport (all four 3D-modeler views, the texture
|
||||
editor's 3D viewport and the texture canvas) has an [b]expand button[/b]
|
||||
(two outward arrows) right next to it: press it and that viewport alone
|
||||
fills the whole view area, press it again (or Space) to retract to the
|
||||
previous layout. Space still expands the focused view. Wheel zooms,
|
||||
right-drag pans, middle-drag (or Alt+drag) orbits the 3D view. The gear
|
||||
menu sets the 3D shading: Shaded + Wire, Shaded, or Wireframe.
|
||||
The three 2D views render the model with the SAME texture the 3D
|
||||
viewport samples: an unpainted model shows the checkerboard placeholder
|
||||
in every view, painted texels show through everywhere, so Top/Front/Side
|
||||
always match what the model actually looks like.
|
||||
[b]Contextual hints[/b] - every viewport shows a small muted hint line at
|
||||
its bottom edge that adapts to what you are doing: select a face and it
|
||||
says "Right-click: options (EXTRUDE faces, fill, delete and more)", start
|
||||
placing an image and the canvas says "Scroll: adjust scale · Right-click:
|
||||
rotate · Click: place · Esc: cancel". The editor teaches itself - no
|
||||
manual required. Prefer a clean viewport? Switch the hints off in the
|
||||
gear menu (Editor Settings > Viewport > Contextual Hints).
|
||||
|
||||
The three 2D views render by PHYSICAL depth, not by hierarchy order:
|
||||
whatever is genuinely in front in 3D space paints last in every ortho
|
||||
view (and two interpenetrating objects interleave per face). Selection
|
||||
outlines, vertex handles and the gizmo always draw above the scene.
|
||||
|
||||
[h2]Hierarchy Panel[/h2]
|
||||
The upper right panel lists every object with its vertex count. Click to
|
||||
select it - the 3D view selects the object and shows the gizmo.
|
||||
[b]Ctrl+click[/b] toggles rows on and off, [b]Shift+click[/b] selects a
|
||||
range - multi-selecting rows works exactly like the viewport, and every
|
||||
multi-selection made in a viewport shows as multiple highlighted rows
|
||||
here. Double-click (or click again) the name to rename. The [b]eye[/b]
|
||||
hides/shows an object (hiding auto-locks it so it can never be picked by
|
||||
accident; the auto-lock releases when you show it again). The
|
||||
[b]padlock[/b] manually locks/unlocks an object: locked objects render
|
||||
but ignore picking, editing and painting.
|
||||
The five [b]stars[/b] next to the Hierarchy title are the rating shortcut:
|
||||
if Polydoodle makes your days easier, click them - it opens the plugin's
|
||||
rating page, and it genuinely helps.
|
||||
|
||||
[h2]Texture Editor: Painting[/h2]
|
||||
Press the workspace pair's [b]Texture Editor[/b] half. The toolbar now
|
||||
shows the texture tools (Brush, Fill, Fill Object, Pixel, Eraser,
|
||||
Picker, Replace, Import Image); the right panel shows paint color, the
|
||||
palette, recent colors, resolution, filter mode and tool sizes.
|
||||
The lower canvas is the object's [b]texture atlas[/b]: every face owns
|
||||
one rectangular island outlined on it. The atlas starts EMPTY - the
|
||||
checkerboard you see is a generated placeholder shown UNDER the page,
|
||||
and the page itself is fully transparent until you paint: paint lands
|
||||
only where you put it and everything else stays see-through, with the
|
||||
checker and the texel grid visible underneath. What you paint on the
|
||||
canvas IS what renders on the 3D model (unpainted texels show the
|
||||
placeholder there too), and painting directly on the 3D model lands on
|
||||
the same texels. The brush ring (or the pixel square) follows
|
||||
the cursor in BOTH the 3D viewport and the canvas. Clicking a face on
|
||||
the 3D model or an island on the canvas also selects that face, so you
|
||||
always know which island you are on.
|
||||
[color=#4da3ff]Transparency workflow[/color] - the gear menu's [b]Show
|
||||
Checkerboard[/b] switch decides what unpainted texels look like: keep it
|
||||
ON for the classic checker placeholder, or switch it OFF and every
|
||||
unpainted texel becomes FULLY TRANSPARENT in the 3D view, the 2D views
|
||||
and the canvas (the see-through preview of a transparent export). The
|
||||
[b]Bake Into Export[/b] switch next to it forces the checkerboard into
|
||||
every exported texture (mesh, scene, OBJ PNGs) so the exported result is
|
||||
NEVER transparent where nothing was painted - handy for exports that
|
||||
should keep the playful placeholder look. With both switches off, an
|
||||
exported model keeps real alpha-0 holes where nothing was painted, and
|
||||
Render Both Sides keeps every surface two-sided.
|
||||
[color=#4da3ff]Use case:[/color] paint eyes onto a character's head island
|
||||
while watching the 3D model update live.
|
||||
|
||||
[h2]Brush, Fill & Pixel Tools[/h2]
|
||||
[color=#4da3ff]Brush[/color] - paints a round stamp whose size (world units)
|
||||
is set by the Brush size slider. Strokes are texel-precise: they follow
|
||||
the surface exactly, across face borders, on the model or the canvas.
|
||||
[color=#4da3ff]Fill[/color] - repaints EXACTLY the clicked face's island,
|
||||
edge to edge, at its CURRENT UV position (moved islands are repainted
|
||||
where they render now, not at their default spot). Never spreads to
|
||||
neighbors. Fills bleed a couple of texels past the island edge so no gap
|
||||
can appear between the paint and the face border.
|
||||
[color=#4da3ff]Fill Object[/color] - repaints every island of the object at
|
||||
once.
|
||||
[color=#4da3ff]Pixel[/color] - the [b]texel-perfect[/b] pixel-art brush: it
|
||||
paints exact N x N texel blocks aligned to the atlas grid (the Pixel
|
||||
size slider is in TEXELS - 1 paints single texels), with texel lines
|
||||
joining fast strokes so nothing gaps. Pair it with the PIXEL filter mode
|
||||
for crisp results. There is no anti-aliasing and no fake half-texels:
|
||||
what you see is exactly what is painted.
|
||||
[color=#4da3ff]Eraser[/color] - brush strokes that restore transparency
|
||||
(the unpainted look: the checker placeholder shows through again). Works on the model AND the canvas; the ring cursor
|
||||
shows the erase footprint. It uses the EXACT same size, opacity, edge
|
||||
smoothness and face-lock settings as the Brush. Right-click does not
|
||||
erase - erasing belongs to the dedicated Eraser tool.
|
||||
[color=#4da3ff]Opacity & Edge smoothness[/color] - the right panel's sliders
|
||||
(Brush or Eraser active). [b]Opacity[/b] is the stamp strength: 100%
|
||||
paints solid, lower values blend see-through strokes that build up along
|
||||
the path. [b]Edge smoothness[/b] is the airbrush falloff: 0 keeps a hard
|
||||
circle edge, 1 sprays a fully soft airbrush stamp - perfect for shading
|
||||
blush, gradients and smoke.
|
||||
[color=#4da3ff]Face lock[/color] - the padlock toggle in the right panel (Brush,
|
||||
Eraser or Pixel active). When ON, a stroke stays inside the face it
|
||||
STARTED on - in the 2D canvas AND on the 3D model. Like the fill system,
|
||||
the paint reaches slightly past the face's own edges (the same bleed
|
||||
margin the Fill tool uses) so its borders are fully covered, but it never
|
||||
paints any other face or any further into empty canvas. The status line
|
||||
confirms the lock when a locked stroke starts.
|
||||
[color=#4da3ff]Picker[/color] - the eyedropper: click any texel on the
|
||||
model or the canvas and its color becomes the paint color (added to the
|
||||
Recent row). Drag it around to sample continuously. Not an undo step.
|
||||
[color=#4da3ff]Replace[/color] - click a texel: every texel of THAT color
|
||||
inside the clicked island is swapped for the current paint color (a
|
||||
couple of bleed texels included, never crossing into other islands).
|
||||
Clicking an unpainted (transparent) texel recolors the island's whole
|
||||
unpainted area. Undoable - a drag across several islands undoes as one
|
||||
sweep.
|
||||
|
||||
[h[color=#4da3ff]Replace[/color] - click a texel and every texel of that
|
||||
color on the WHOLE canvas (all faces) becomes the paint color. The
|
||||
[color=#4da3ff]Tolerance[/color] slider (right panel, shown while the
|
||||
tool is active) widens the match: 0% replaces only the exact color,
|
||||
higher values also replace nearby shades - handy for swapping a hand-
|
||||
painted gradient. One undo step returns the whole swap.
|
||||
[h2]Smooth & Pixel Filter Modes[/h2]
|
||||
The right panel's Filter buttons switch how the texture is sampled:
|
||||
[b]Smooth[/b] - the texture is linearly filtered: soft, anti-aliased
|
||||
look on the model AND in the editor. Best with the normal Brush.
|
||||
[b]Pixel[/b] - filtering is OFF on the model AND the editor canvas:
|
||||
texels render razor sharp for pixel art. The pixel brush is the natural
|
||||
tool here (switching modes auto-swaps the default tool).
|
||||
[color=#4da3ff]Use case:[/color] paint a 32x32 pixel-art skin in Pixel mode,
|
||||
then flip to Smooth to preview how it reads with filtering.
|
||||
|
||||
[h2]Texture Resolution[/h2]
|
||||
The Resolution dropdown (right panel, Texture group) changes the active
|
||||
object's atlas to 64/128/256/512/1024 per side - or pick [b]Custom...[/b]
|
||||
and type any size between 16 and 1024 texels per side (slider or number
|
||||
entry) for non-standard targets like 300 x 300. The paint is resampled
|
||||
(nearest), islands, texel density and UV offsets all scale by the same
|
||||
factor, so every stroke stays exactly where it was - just sharper or
|
||||
softer. The change is undoable and is saved in project files. A warning:
|
||||
islands that no longer fit are re-packed automatically; when the model
|
||||
is very complex the editor may also grow the atlas on its own.
|
||||
|
||||
[h2]Import Images (Stickers)[/h2]
|
||||
The [b]Import Image[/b] button (Paint submode) opens a file dialog. The
|
||||
picture then floats on the canvas as a ghost:
|
||||
[list][*]Move the mouse - the ghost follows.
|
||||
[*][b]Wheel[/b] - scales it bigger/smaller.
|
||||
[*][b]Right-click[/b] - rotates it 90 degrees.
|
||||
[*][b]Click[/b] - places it (alpha-blended into the atlas, undoable).
|
||||
[*][b]Esc[/b] - cancels.[/list]
|
||||
Afterwards the placed image is just texels: paint over it, erase parts,
|
||||
fill it. Oversized imports are auto-fit into the atlas.
|
||||
[color=#4da3ff]Use case:[/color] import a logo, scale it with the wheel,
|
||||
rotate it upright with right-click, place it on a crate's side island,
|
||||
then rough it up with the eraser.
|
||||
|
||||
[h2]Texture Editor: Edit UV[/h2]
|
||||
The [b]Edit UV[/b] toolbar button switches the texture editor to UV
|
||||
editing - the right panel swaps its paint controls for the UV toolset
|
||||
(selection mode, snapping, island actions, the Rotate / Scale sliders).
|
||||
Clicking a face on the 3D model selects it and highlights its island on
|
||||
the canvas (and the other way around).
|
||||
[b]Select mode[/b] (right panel) decides what clicks and the rectangular
|
||||
selection grab: [b]Vertex[/b], [b]Edge[/b] or [b]Face[/b]. Selection
|
||||
rules in every mode:
|
||||
[list][*]A plain click selects ONE element (replacing the selection).
|
||||
[*][b]Ctrl or Shift + click[/b] adds an element to the selection.
|
||||
[*]Grabbing an element that is part of the selection moves the WHOLE
|
||||
selection - box-select corners, then drag any one of them.
|
||||
[*]A bare click on empty canvas deselects everything.
|
||||
[*]An empty-space DRAG box-selects the active element type.[/list]
|
||||
[b]Snap[/b] (toolbar) makes UV drags land PIXEL-PERFECT on the texel
|
||||
grid: with snapping on, the dragged corners land exactly on texel
|
||||
boundaries, so the island outline aligns edge to edge with the atlas
|
||||
pixels (even for islands whose corners sit at fractional texel positions
|
||||
after vertex edits). Hold Ctrl to drag sub-texel freely.
|
||||
[b]Right-click[/b] the canvas for the mesh menu: Rotate UV 90° CW / CCW,
|
||||
Detach Selected Face(s), Merge Vertices, Extrude Face / Edges, Fill /
|
||||
Clear, Delete Face(s)/Edge(s)/Vertex(es), Select All Islands, Deselect,
|
||||
Reset UVs. [b]Detach[/b] moves the selected islands to free atlas space
|
||||
so they can be laid out individually. The HUD line shows the mode, atlas
|
||||
size and zoom.
|
||||
|
||||
|
||||
[h2]Rotate & Scale UVs[/h2]
|
||||
Two toolbar toggles (Edit UV submode) transform the selected faces' UVs
|
||||
around the selection's center; exactly one is active at a time and
|
||||
clicking the active one again switches it off.
|
||||
[b]Rotate UVs:[/b] toggling it shows an [b]Angle[/b] row in the right
|
||||
panel - drag the slider or type a number from 0 to 360 degrees and the
|
||||
islands turn live. The angle is ABSOLUTE for the current selection:
|
||||
[b]0 is the position the face had when the rotation started[/b] and 360
|
||||
is one full turn - the slider always shows the face's real total angle
|
||||
and stays where you leave it (it does not snap back to 0). Rotations
|
||||
with the quick 90-degree actions feed the same value. Changing the
|
||||
selection or the tool starts a fresh chain at 0. The whole drag is ONE
|
||||
undo step (a typed run is one step too).
|
||||
[b]Scale UVs:[/b] toggling it shows a [b]Scale %[/b] row (10-400%), and
|
||||
on the canvas you can grab any corner of the selection and drag: away
|
||||
from the center grows, toward it shrinks - always UNIFORM, so the
|
||||
aspect ratio never changes. Both tools re-derive every corner from the
|
||||
frozen press-time positions, so long drags cannot drift.
|
||||
Quick actions stay: the canvas right-click menu offers [b]Rotate UV
|
||||
90° CW / CCW[/b], and on the canvas [b]R[/b] rotates clockwise,
|
||||
[b]Shift+R[/b] counter-clockwise. One face turns about its own center;
|
||||
several selected faces transform together as one rigid group, so the
|
||||
faces of an island stay glued to each other. With [b]Snap[/b] on the
|
||||
transformed corners land exactly on the texel grid - pixel-perfect,
|
||||
like drags. Rotating and scaling move the SAMPLING window over the
|
||||
atlas: the painted texels stay where they are and the face reads them
|
||||
from the new mapping.
|
||||
[color=#4da3ff]Use case:[/color] select a character face's island, press
|
||||
R until the eyes sit level, fine-tune with the Angle slider, then paint
|
||||
details with the island nicely aligned to the texel grid; use Scale to
|
||||
fit a logo island onto a slightly smaller panel without stretching it.
|
||||
|
||||
[h2]Undo, Save & Open[/h2]
|
||||
Everything meaningful is undoable (48 steps): modeling, UV edits,
|
||||
painting, resolution changes, renames, visibility/lock, deletes.
|
||||
Ctrl+Z undoes, Ctrl+Shift+Z (or Ctrl+Y) redoes. [b]Save[/b] writes a
|
||||
.pdoodle project (all objects, textures, UVs, paint colors and editor
|
||||
settings). [b]Open[/b] restores one. The files are plain text - they
|
||||
diff nicely in version control.
|
||||
[b]Session auto-save[/b] - Polydoodle also keeps your work safe on its
|
||||
own: a moment after every change the whole document (models, paint,
|
||||
textures, settings) is stored in the editor's user data, and when you
|
||||
close Godot it is flushed immediately. Reopen the editor and everything
|
||||
is exactly where you left it - no save dialog, nothing to do. Opening a
|
||||
.pdoodle project or deleting everything simply becomes the new session.
|
||||
|
||||
[h2]Import 3D Models[/h2]
|
||||
The [color=#4da3ff]Import Model[/color] button (arrow into a tray, next to
|
||||
Open) brings an existing model into the scene and keeps its textures.
|
||||
[b]Supported files[/b] - Wavefront OBJ (with its .mtl and texture maps),
|
||||
glTF / GLB, FBX, and Godot scenes or meshes that live inside the project
|
||||
(.tscn, .scn, .tres, .res, .mesh).
|
||||
[b]What happens to the model[/b] - duplicate vertices are welded, flat
|
||||
triangle pairs are merged into quads, and the model is scaled to fit a
|
||||
2-unit box and centered. Every mesh in the file becomes its own object, so
|
||||
you can edit, hide or export the parts separately. The whole import is a
|
||||
single undo step.
|
||||
[b]Textures[/b] - Polydoodle paints every face into its own island of one
|
||||
atlas, so the model's texture is [i]re-baked[/i] into those islands rather
|
||||
than copied. Materials without a texture import as flat colors, tiling UVs
|
||||
repeat as in the original, and several materials in one mesh are kept. The
|
||||
atlas resolution follows the source texture (256 / 512 / 1024); you can
|
||||
change it afterwards in the Texture Resolution setting.
|
||||
[b]Where from[/b] - the file picker browses your whole computer, not only
|
||||
the project, and offers an "All files" filter. Duplicate faces that some
|
||||
exporters write twice are removed so nothing z-fights.
|
||||
[b]Limits[/b] - up to 5000 faces after cleanup and 32 meshes per file.
|
||||
Above 1500 faces a note warns that painting and editing get slower; this
|
||||
is a low-poly tool, so lighter models always feel best.
|
||||
Large imports show their progress in the status bar and never freeze the
|
||||
editor. Anything that could not be imported (a missing texture file, a
|
||||
broken face) is listed in a notes dialog after the import.
|
||||
[b]Tips[/b] - for OBJ keep the .mtl and texture files next to the .obj (or at
|
||||
the paths the .mtl names). Skinned or animated models import in their rest
|
||||
pose; animation, rigs and normal / roughness maps are not imported.
|
||||
|
||||
[h2]Export for Godot[/h2]
|
||||
[color=#4da3ff]Mesh (.tres)[/color] - an ArrayMesh with the painted texture
|
||||
and correct UVs; assign it to any MeshInstance3D.
|
||||
[color=#4da3ff]Scene (.tscn)[/color] - a small scene wrapping the mesh.
|
||||
[color=#4da3ff]OBJ[/color] - a Wavefront OBJ with flat shading ("s off"), a
|
||||
companion .mtl and the atlas saved as PNG per textured object. Imports
|
||||
into Blender/Unity/Godot with the texture.
|
||||
[color=#4da3ff]Add to current scene[/color] - drops a PolydoodleModel
|
||||
MeshInstance3D into the edited scene, selected and ready. Exporting again
|
||||
LATER UPDATES that same node in place: the mesh, UVs and texture are
|
||||
swapped, while the position, rotation and scale you set in the Godot
|
||||
editor (and any children) stay untouched. With several Polydoodle models
|
||||
in one scene, select the one to update before exporting.
|
||||
|
||||
[h2]Keyboard & Mouse Map[/h2]
|
||||
[font_size=12][table=3]
|
||||
[cell]1 / 2 / 3 / 4[/cell][cell]Object / Vertex / Edge / Face mode[/cell][cell][/cell]
|
||||
[cell]5[/cell][cell]Draw mode[/cell][cell][/cell]
|
||||
[cell]6[/cell][cell]Toggle workspace (3D <-> Texture)[/cell][cell][/cell]
|
||||
[cell]G / S / R (3D)[/cell][cell]Move / Scale / Rotate gizmo (active key again = hide)[/cell][cell][/cell]
|
||||
[cell]T / V / B[/cell][cell]Snap / Grid visibility / Both sides[/cell][cell][/cell]
|
||||
[cell]Ctrl+Z, Ctrl+Shift+Z[/cell][cell]Undo / Redo[/cell][cell][/cell]
|
||||
[cell]Ctrl+D[/cell][cell]Duplicate selection[/cell][cell][/cell]
|
||||
[cell]Ctrl+A[/cell][cell]Select all[/cell][cell][/cell]
|
||||
[cell]Del / Backspace[/cell][cell]Delete selection[/cell][cell][/cell]
|
||||
[cell]F[/cell][cell]Frame selection[/cell][cell][/cell]
|
||||
[cell]Space[/cell][cell]Fullscreen the focused viewport[/cell][cell][/cell]
|
||||
[cell]Esc[/cell][cell]Deselect / cancel sticker[/cell][cell][/cell]
|
||||
[cell]Shift+Click[/cell][cell]Add to selection[/cell][cell][/cell]
|
||||
[cell]Ctrl+LMB drag (3D)[/cell][cell]Rectangle multi-select[/cell][cell][/cell]
|
||||
[cell]LMB / RMB / MMB[/cell][cell]Tool action / pan / orbit[/cell][cell][/cell]
|
||||
[cell]Alt+LMB[/cell][cell]Orbit while drawing or painting[/cell][cell][/cell]
|
||||
[cell]Wheel[/cell][cell]Zoom (scale stickers while importing)[/cell][cell][/cell]
|
||||
[cell]Right-click (sticker)[/cell][cell]Rotate the image 90 degrees[/cell][cell][/cell]
|
||||
[cell]R / Shift+R (UV canvas)[/cell][cell]Rotate UV selection 90 CW / CCW[/cell][cell][/cell]
|
||||
[cell]Rotate/Scale toolbar toggles[/cell][cell]Angle 0-360 / Scale 10-400% rows in the right panel; Scale also drag-to-scale any corner[/cell][cell][/cell]
|
||||
[cell]Right-click (canvas, Edit UV)[/cell][cell]Mesh ops menu[/cell][cell][/cell]
|
||||
[cell]Right-click (3D or 2D view, edit modes)[/cell][cell]Mesh ops menu[/cell][cell][/cell]
|
||||
[cell]Ctrl/Shift+click (hierarchy)[/cell][cell]Multi-select objects[/cell][cell][/cell]
|
||||
[/table][/font_size]
|
||||
|
||||
[h2]Use Cases & Workflows[/h2]
|
||||
[color=#4da3ff]A low-poly house:[/color] add a Cube, scale it with the Scale
|
||||
gizmo; add a Prism for the roof; select both and extrude nothing - just
|
||||
paint: switch to the Texture Editor, fill the walls island with cream,
|
||||
the roof island with red, draw windows with the Pixel brush in Pixel
|
||||
mode. Export as OBJ for a game jam or .tres to use directly.
|
||||
[color=#4da3ff]A character head:[/color] add a Sphere, merge the bottom
|
||||
vertices flat, extrude the top face twice for a hat. In Edit UV, detach
|
||||
the face island, place it on empty atlas space, rotate it upright with
|
||||
Rotate UV if needed, and paint the face with the brush (Smooth mode) -
|
||||
the islands stay exactly where you packed them.
|
||||
[color=#4da3ff]Pixel-art sprite on a plane:[/color] add a Plane, set
|
||||
resolution 64, filter PIXEL, and draw with the Pixel brush at size 1 -
|
||||
the plane IS your sprite sheet. Export .tres and use it in-game.
|
||||
[color=#4da3ff]Level grayboxing:[/color] draw rectangles on the ground in
|
||||
Draw mode, extrude the faces to wall height with the Face context menu,
|
||||
duplicate around, then add everything to the current scene.
|
||||
|
||||
[h2]Troubleshooting[/h2]
|
||||
[b]The canvas says "Select an object..."[/b] - the texture editor edits
|
||||
the ACTIVE object; add or select one first.
|
||||
[b]Painting does nothing on an object[/b] - it is locked or hidden
|
||||
(padlock/eye in the hierarchy). Unlock it.
|
||||
[b]UVs look scrambled after heavy vertex drags[/b] - the mapping
|
||||
re-derives from the new geometry on the next edit; use Reset UVs (Edit
|
||||
UV menu) or the toolbar button for a clean planar unwrap.
|
||||
[b]A fill landed on the "wrong" island[/b] - fills repaint the face's
|
||||
island at its CURRENT position; the island may simply overlap another
|
||||
one's area - detach it to free space.
|
||||
[b]Imported image invisible[/b] - the atlas may be much larger than the
|
||||
sticker at scale 1.0; wheel it up, or check that the active object is
|
||||
the one you imported onto.
|
||||
[b]A message appears at the top of the viewport[/b] - Polydoodle tells you
|
||||
why an action cannot run right now and what to do: no shape in the scene,
|
||||
nothing selected, the wrong mode (for example Extrude needs Face mode, key
|
||||
4), a locked or hidden shape, nothing to undo, or a doodle that was too
|
||||
small. The message fades by itself and never blocks the mouse.
|
||||
[b]Clicking a shape does nothing[/b] - it is probably locked (padlock icon
|
||||
in the hierarchy) or hidden (eye icon). A notice names the shape; unlock or
|
||||
show it to edit it.
|
||||
[b]The gizmo is not showing[/b] - nothing is selected, the selection is
|
||||
hidden, or the shape has no geometry. Select a shape (Object mode) or
|
||||
vertices / edges / faces, and the gizmo appears on the selection.
|
||||
[b]Export does nothing[/b] - the scene is empty or every shape is hidden;
|
||||
a notice says which.
|
||||
[b]Import says the model has too many faces[/b] - the limit is 5000 faces.
|
||||
Decimate or retopologize the model in your 3D software and import again.
|
||||
[b]An imported model is white or checkered[/b] - its texture file was not
|
||||
found (see the notes dialog after importing). For OBJ, keep the texture next
|
||||
to the .obj / .mtl; for glTF use a .glb or keep the image files beside the
|
||||
.gltf.
|
||||
[b]Import is not available for a file type[/b] - scenes and meshes (.tscn,
|
||||
.tres, ...) must be inside the project; OBJ, glTF / GLB and FBX can be
|
||||
anywhere on your computer.
|
||||
[b]Export OBJ looks smooth in another app[/b] - the OBJ is written with
|
||||
"s off" (flat); some importers override shading - re-import or disable
|
||||
smooth shading there.
|
||||
"""
|
||||
|
||||
|
||||
## Build (once) and show the documentation window. The caller parents the
|
||||
## window into the editor's base control and centers it on screen
|
||||
## (an unpositioned Window opens in the top-left corner).
|
||||
static func open(existing: Window) -> Window:
|
||||
if existing != null and is_instance_valid(existing):
|
||||
existing.show()
|
||||
existing.move_to_foreground()
|
||||
return existing
|
||||
var win := Window.new()
|
||||
win.title = "Polydoodle Documentation"
|
||||
win.min_size = Vector2i(760, 520)
|
||||
win.size = Vector2i(920, 640)
|
||||
var v := VBoxContainer.new()
|
||||
v.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
v.offset_left = 8
|
||||
v.offset_top = 8
|
||||
v.offset_right = -8
|
||||
v.offset_bottom = -8
|
||||
win.add_child(v)
|
||||
var head := HBoxContainer.new()
|
||||
head.add_theme_constant_override("separation", 8)
|
||||
v.add_child(head)
|
||||
var icon := TextureRect.new()
|
||||
icon.texture = PdIcons.get_icon("docs")
|
||||
icon.custom_minimum_size = Vector2(24, 24)
|
||||
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
head.add_child(icon)
|
||||
var title := Label.new()
|
||||
title.text = "Polydoodle Documentation"
|
||||
title.add_theme_font_size_override("font_size", 16)
|
||||
head.add_child(title)
|
||||
# top-line links (see the URL_* constants above): the plugin page, a
|
||||
# rate link and the author's other works - replace the URLs anytime
|
||||
var spacer := Control.new()
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
spacer.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
head.add_child(spacer)
|
||||
for pair in [["Godot Plugin", URL_PLUGIN],
|
||||
["Rate This Plugin", URL_RATE],
|
||||
["My Other Works", URL_OTHER]]:
|
||||
var lb := LinkButton.new()
|
||||
lb.text = pair[0]
|
||||
lb.uri = pair[1] # LinkButton opens the URI in the OS browser
|
||||
lb.add_theme_font_size_override("font_size", 13)
|
||||
lb.focus_mode = Control.FOCUS_NONE
|
||||
head.add_child(lb)
|
||||
var split := HSplitContainer.new()
|
||||
split.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
split.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
split.split_offset = 190
|
||||
v.add_child(split)
|
||||
var list := ItemList.new()
|
||||
list.custom_minimum_size = Vector2(180, 0)
|
||||
list.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
list.add_theme_font_size_override("font_size", 12)
|
||||
list.auto_height = false
|
||||
split.add_child(list)
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
split.add_child(scroll)
|
||||
var rt := RichTextLabel.new()
|
||||
rt.bbcode_enabled = true
|
||||
# fit_content would expand the label and hand scrolling to the outer
|
||||
# ScrollContainer - then scroll_to_line() (which drives the label's OWN
|
||||
# scrollbar) does nothing and clicking a section never moves the page.
|
||||
# The label must own the vertical scroll for section navigation to work.
|
||||
rt.fit_content = false
|
||||
rt.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
rt.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
# [h2] is not a supported tag in Godot 4.7 - render section headers
|
||||
# manually (same line structure, so the section->line map stays valid)
|
||||
# runtime link injection: the Welcome page opens with the same links
|
||||
# the window's top line carries, so first-time readers see them first
|
||||
var body: String = BODY.replace("[[RATE]]", URL_RATE) \
|
||||
.replace("[[PLUGIN]]", URL_PLUGIN).replace("[[OTHER]]", URL_OTHER)
|
||||
rt.text = body.replace("[h2]",
|
||||
"[b][color=#4da3ff][font_size=17]").replace("[/h2]",
|
||||
"[/font_size][/color][/b]")
|
||||
rt.add_theme_font_size_override("normal_font_size", 13)
|
||||
rt.add_theme_font_size_override("bold_font_size", 13)
|
||||
scroll.add_child(rt)
|
||||
# section -> first line in the bbcode body
|
||||
var lines := body.split("\n")
|
||||
for s in SECTIONS:
|
||||
list.add_item(s[0])
|
||||
var marker: String = "[h2]" + str(s[0])
|
||||
var ln := 0
|
||||
for i in lines.size():
|
||||
if lines[i].begins_with(marker):
|
||||
ln = i
|
||||
break
|
||||
list.set_item_metadata(list.item_count - 1, ln)
|
||||
list.item_selected.connect(func(idx: int):
|
||||
rt.scroll_to_line(int(list.get_item_metadata(idx))))
|
||||
rt.meta_clicked.connect(func(meta: Variant):
|
||||
OS.shell_open(str(meta)))
|
||||
list.select(0)
|
||||
win.close_requested.connect(func(): win.hide())
|
||||
return win
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
uid://dqq74eridolmo
|
||||
Executable
+964
@@ -0,0 +1,964 @@
|
||||
@tool
|
||||
class_name PdMain
|
||||
extends VBoxContainer
|
||||
## Polydoodle main screen: toolbar | quad views (Top/Persp/Side/Front) | panel.
|
||||
|
||||
const VIEW2D := preload("res://addons/polydoodle/editor/pd_view2d.gd")
|
||||
const VIEW3D := preload("res://addons/polydoodle/editor/pd_view3d.gd")
|
||||
const TOOLBAR := preload("res://addons/polydoodle/editor/pd_toolbar.gd")
|
||||
const PANEL := preload("res://addons/polydoodle/editor/pd_panel.gd")
|
||||
const UVCANVAS := preload("res://addons/polydoodle/editor/pd_uvcanvas.gd")
|
||||
|
||||
var doc: PdDocument
|
||||
var toolbar: PdToolbar
|
||||
var panel: PdPanel
|
||||
var view3d: PdView3D
|
||||
var views2d: Array = [] # [top, side, front]
|
||||
var status_label: Label
|
||||
var hint_label: Label
|
||||
|
||||
var view_holder: Control
|
||||
var _split: HSplitContainer # views | panel - width-clamped drags
|
||||
var _fullscreen_view: Control = null
|
||||
var _focused_view: Control = null
|
||||
var _dlg: EditorFileDialog
|
||||
var _file_dlg: EditorFileDialog # image import dialog
|
||||
var _expand_syncing := false # guard while pushing pressed states out
|
||||
|
||||
# Texture Paint mode: 3D viewport on top, UV canvas below. The tool
|
||||
# buttons live IN THE TOP TOOLBAR (the texture group replaces the
|
||||
# modeling buttons); sliders and deeper options live in the right panel.
|
||||
var uv_canvas: PdUVCanvas
|
||||
var _last_canvas_size := Vector2.ZERO
|
||||
var last_3d_mode: int = PdDocument.Mode.OBJECT # workspace memory
|
||||
|
||||
const PANEL_MIN_W := 240.0 # panel floor (also on the panel itself):
|
||||
# SplitContainer refuses to shrink it below
|
||||
const VIEW_MIN_W := 410.0 # hard floor for the quad views: must fit
|
||||
# TWO columns of view3d's own 200px minimum
|
||||
# width (+ gap) or view3d gets clamped wider
|
||||
# than its allotted half and visually spills
|
||||
# out of view_holder into the panel next to
|
||||
# it. Was 300 (only 150/column) - too small
|
||||
# for view3d's 200 floor, which is exactly
|
||||
# what caused the 3D viewport / panel
|
||||
# overlap when the panel was dragged wide.
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
doc = PdDocument.new()
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
add_theme_constant_override("separation", 4)
|
||||
_build_ui()
|
||||
doc.doc_changed.connect(_on_doc_changed)
|
||||
doc.sel_changed.connect(_on_doc_changed)
|
||||
doc.settings_changed.connect(_on_doc_changed)
|
||||
doc.undo.version_changed.connect(_on_doc_changed)
|
||||
doc.status_msg.connect(func(t: String): set_status(t))
|
||||
doc.warning_msg.connect(show_toast)
|
||||
_setup_autosave()
|
||||
set_status("Welcome to Polydoodle - add a shape or switch to Draw mode and doodle one!")
|
||||
hint_label.text = _hint_text()
|
||||
|
||||
|
||||
func _build_ui() -> void:
|
||||
toolbar = TOOLBAR.new()
|
||||
toolbar.setup(doc)
|
||||
toolbar.mode_requested.connect(_set_mode)
|
||||
# the two-half workspace switch: left = 3D editor (restore the last
|
||||
# 3D mode), right = texture editor
|
||||
toolbar.workspace_requested.connect(func(tex: bool):
|
||||
_set_mode(PdDocument.Mode.TEXTURE if tex else last_3d_mode))
|
||||
toolbar.toggle_gizmo.connect(func(v: bool):
|
||||
doc.set_gizmo(v)
|
||||
_sync()
|
||||
if v:
|
||||
_warn_gizmo_target())
|
||||
toolbar.toggle_snap.connect(func(v: bool): doc.set_snap(v))
|
||||
toolbar.toggle_grid.connect(func(v: bool): doc.set_grid_visible(v))
|
||||
toolbar.toggle_both_sides.connect(func(v: bool): doc.set_both_sides(v))
|
||||
toolbar.draw_kind.connect(func(k: String): doc.set_draw_kind(k))
|
||||
toolbar.add_shape.connect(func(kind: String):
|
||||
doc.add_primitive(kind)
|
||||
frame_selection())
|
||||
toolbar.duplicate_requested.connect(func(): doc.duplicate_selected())
|
||||
toolbar.delete_requested.connect(func(): doc.delete_selection())
|
||||
toolbar.undo_requested.connect(doc.do_undo)
|
||||
toolbar.redo_requested.connect(doc.do_redo)
|
||||
toolbar.save_requested.connect(_save_project)
|
||||
toolbar.load_requested.connect(_open_project)
|
||||
toolbar.import_model_requested.connect(_import_model)
|
||||
toolbar.export_requested.connect(_export)
|
||||
toolbar.bg_changed.connect(func(c: Color): doc.set_bg(c))
|
||||
# texture-editor toolbar group: submode + contextual tools
|
||||
toolbar.tex_submode.connect(func(edit: bool): doc.set_tex_edit(edit))
|
||||
toolbar.paint_tool_requested.connect(func(t: String): doc.set_paint_tool(t))
|
||||
toolbar.uv_snap_requested.connect(func(v: bool): doc.set_uv_snap(v))
|
||||
toolbar.rotate_uv_requested.connect(func(dir: int):
|
||||
doc.rotate_uv_selected(doc.active_obj, dir))
|
||||
toolbar.uv_tool_requested.connect(func(t: String):
|
||||
doc.set_uv_tool(t))
|
||||
toolbar.import_requested.connect(_import_image)
|
||||
toolbar.detach_requested.connect(func():
|
||||
doc.uv_detach_selected(doc.active_obj))
|
||||
toolbar.reset_uvs_requested.connect(func():
|
||||
doc.uv_reset_object(doc.active_obj))
|
||||
# Scroll wrap: the toolbar's own minimum width must never push
|
||||
# the layout wider than the main screen (that shoved the panel
|
||||
# off-screen and stretched the viewports on smaller windows).
|
||||
var tb_scroll := ScrollContainer.new()
|
||||
tb_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_AUTO
|
||||
tb_scroll.vertical_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
tb_scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
toolbar.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
tb_scroll.add_child(toolbar)
|
||||
add_child(tb_scroll)
|
||||
|
||||
var split := HSplitContainer.new()
|
||||
split.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
split.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
split.add_theme_constant_override("separation", 8)
|
||||
_split = split
|
||||
add_child(split)
|
||||
|
||||
# Classic quad view, same format as the earlier version:
|
||||
# TOP (top-left) | PERSPECTIVE (top-right)
|
||||
# SIDE (bottom-left) | FRONT (bottom-right)
|
||||
view_holder = Control.new()
|
||||
# engine-level floor: the splitter itself refuses to shrink the
|
||||
# views below this, so the panel can never be dragged over them
|
||||
view_holder.custom_minimum_size = Vector2(VIEW_MIN_W, 0)
|
||||
view_holder.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
view_holder.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
# belt-and-braces: even if some child ever reports a minimum size
|
||||
# wider than its allotted quadrant, clip it here instead of letting
|
||||
# it bleed into the panel next door.
|
||||
view_holder.clip_contents = true
|
||||
split.add_child(view_holder)
|
||||
|
||||
var v_top: PdView2D = VIEW2D.new()
|
||||
v_top.setup(doc, self, 0)
|
||||
view_holder.add_child(v_top)
|
||||
views2d.append(v_top)
|
||||
|
||||
view3d = VIEW3D.new()
|
||||
view3d.setup(doc, self)
|
||||
view3d.custom_minimum_size = Vector2(200, 150)
|
||||
view_holder.add_child(view3d)
|
||||
|
||||
var v_side: PdView2D = VIEW2D.new()
|
||||
v_side.setup(doc, self, 2)
|
||||
view_holder.add_child(v_side)
|
||||
views2d.append(v_side)
|
||||
|
||||
var v_front: PdView2D = VIEW2D.new()
|
||||
v_front.setup(doc, self, 1)
|
||||
view_holder.add_child(v_front)
|
||||
views2d.append(v_front)
|
||||
|
||||
for v in all_views():
|
||||
v.focus_entered.connect(func(): _focused_view = v)
|
||||
view_holder.resized.connect(_relayout_views)
|
||||
|
||||
# Texture-mode canvas (hidden until Texture mode). Its tools live
|
||||
# in the toolbar; its settings live in the right panel.
|
||||
uv_canvas = UVCANVAS.new()
|
||||
uv_canvas.setup(doc, self)
|
||||
view_holder.add_child(uv_canvas)
|
||||
uv_canvas.visible = false
|
||||
uv_canvas.focus_entered.connect(func(): _focused_view = uv_canvas)
|
||||
|
||||
panel = PANEL.new()
|
||||
panel.setup(doc, self)
|
||||
panel.custom_minimum_size = Vector2(240, 0)
|
||||
split.add_child(panel)
|
||||
|
||||
var status := HBoxContainer.new()
|
||||
status.add_theme_constant_override("separation", 10)
|
||||
add_child(status)
|
||||
hint_label = Label.new()
|
||||
hint_label.text = ""
|
||||
hint_label.add_theme_font_size_override("font_size", 11)
|
||||
hint_label.add_theme_color_override("font_color", Color(1, 1, 1, 0.4))
|
||||
hint_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
hint_label.clip_text = true
|
||||
status.add_child(hint_label)
|
||||
status_label = Label.new()
|
||||
status_label.text = ""
|
||||
status_label.add_theme_font_size_override("font_size", 11)
|
||||
status_label.add_theme_color_override("font_color", Color(1, 1, 1, 0.55))
|
||||
status_label.clip_text = true # long status text must not force width
|
||||
status.add_child(status_label)
|
||||
|
||||
split.split_offset = -250
|
||||
split.collapsed = false
|
||||
_relayout_views.call_deferred()
|
||||
_build_toast()
|
||||
|
||||
|
||||
# -------------------------------------------------------------- toast ---
|
||||
## A short notice that floats over the top of the main screen. It is a raised
|
||||
## card in the plugin's own style (flat dark fill, darker bottom edge) and is
|
||||
## sized from the real text metrics - no auto-wrapping label - so its height
|
||||
## can never drift away from its content.
|
||||
var _toast: PanelContainer
|
||||
var _toast_label: Label
|
||||
var _toast_tween: Tween
|
||||
const TOAST_SECONDS := 3.8
|
||||
const TOAST_FONT := 12
|
||||
const TOAST_MAX_WIDTH := 560.0
|
||||
const TOAST_MAX_LINES := 4
|
||||
const TOAST_PAD_X := 14.0
|
||||
|
||||
|
||||
func _build_toast() -> void:
|
||||
_toast = PanelContainer.new()
|
||||
_toast.top_level = true # floats over the layout
|
||||
_toast.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_toast.clip_contents = true
|
||||
_toast.z_index = 100
|
||||
_toast.visible = false
|
||||
var sb := StyleBoxFlat.new()
|
||||
sb.bg_color = Color(0.215, 0.235, 0.285)
|
||||
sb.set_corner_radius_all(5)
|
||||
sb.border_width_bottom = 3 # darker lower edge: raised look
|
||||
sb.border_color = Color(0.105, 0.115, 0.145)
|
||||
sb.content_margin_left = TOAST_PAD_X
|
||||
sb.content_margin_right = TOAST_PAD_X
|
||||
sb.content_margin_top = 7
|
||||
sb.content_margin_bottom = 10 # 7 of padding + the 3 px lower edge
|
||||
_toast.add_theme_stylebox_override("panel", sb)
|
||||
_toast_label = Label.new()
|
||||
_toast_label.add_theme_font_size_override("font_size", TOAST_FONT)
|
||||
_toast_label.add_theme_color_override("font_color", Color(1, 1, 1, 0.92))
|
||||
_toast_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
# the editor theme pads labels; the card does its own padding
|
||||
_toast_label.add_theme_stylebox_override("normal", StyleBoxEmpty.new())
|
||||
_toast.add_child(_toast_label)
|
||||
add_child(_toast)
|
||||
resized.connect(_place_toast)
|
||||
visibility_changed.connect(func():
|
||||
if not is_visible_in_tree() and _toast != null:
|
||||
_toast.visible = false)
|
||||
|
||||
|
||||
## Greedy word wrap using the font's real metrics. A word that cannot fit on
|
||||
## a line by itself (a long file path, say) is broken across lines. At most
|
||||
## `max_lines` lines are returned; the last one ends in "..." when cut.
|
||||
func _wrap_text(text: String, font: Font, font_size: int, max_w: float,
|
||||
max_lines := 1000) -> PackedStringArray:
|
||||
var lines := PackedStringArray()
|
||||
var cur := ""
|
||||
for token in text.split(" ", false):
|
||||
var word: String = token
|
||||
while word.length() > 1 and font.get_string_size(word,
|
||||
HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x > max_w:
|
||||
var n := word.length()
|
||||
while n > 1 and font.get_string_size(word.substr(0, n),
|
||||
HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x > max_w:
|
||||
n -= 1
|
||||
if not cur.is_empty():
|
||||
lines.append(cur)
|
||||
cur = ""
|
||||
lines.append(word.substr(0, n))
|
||||
word = word.substr(n)
|
||||
var cand: String = word if cur.is_empty() else cur + " " + word
|
||||
if cur.is_empty() or font.get_string_size(cand,
|
||||
HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x <= max_w:
|
||||
cur = cand
|
||||
else:
|
||||
lines.append(cur)
|
||||
cur = word
|
||||
if not cur.is_empty():
|
||||
lines.append(cur)
|
||||
if lines.size() > max_lines:
|
||||
lines.resize(max_lines)
|
||||
var last := lines[max_lines - 1]
|
||||
while last.length() > 1 and font.get_string_size(last + "...",
|
||||
HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x > max_w:
|
||||
last = last.substr(0, last.length() - 1)
|
||||
lines[max_lines - 1] = last + "..."
|
||||
return lines
|
||||
|
||||
|
||||
func _place_toast() -> void:
|
||||
if _toast == null or not _toast.visible:
|
||||
return
|
||||
var top := (toolbar.size.y if toolbar != null else 40.0) + 10.0
|
||||
var x := clampf((size.x - _toast.size.x) * 0.5, 8.0,
|
||||
maxf(8.0, size.x - _toast.size.x - 8.0))
|
||||
_toast.global_position = global_position + Vector2(x, top)
|
||||
|
||||
|
||||
## Show a notice. Replaces the previous one; fades out by itself.
|
||||
func show_toast(text: String) -> void:
|
||||
if _toast == null or text.is_empty() or not is_visible_in_tree():
|
||||
return
|
||||
var font := _toast_label.get_theme_font("font")
|
||||
var card_w := clampf(size.x - 48.0, 200.0, TOAST_MAX_WIDTH)
|
||||
var lines := _wrap_text(text, font, TOAST_FONT,
|
||||
card_w - TOAST_PAD_X * 2.0, TOAST_MAX_LINES)
|
||||
_toast_label.text = "\n".join(lines)
|
||||
# explicit size from the text metrics: widest line + padding, one text
|
||||
# row per line - the label never wraps by itself
|
||||
var widest := 0.0
|
||||
for l in lines:
|
||||
widest = maxf(widest, font.get_string_size(l,
|
||||
HORIZONTAL_ALIGNMENT_LEFT, -1, TOAST_FONT).x)
|
||||
var sb := _toast.get_theme_stylebox("panel") as StyleBoxFlat
|
||||
var gap := float(_toast_label.get_theme_constant("line_spacing"))
|
||||
var card := Vector2(
|
||||
minf(widest + TOAST_PAD_X * 2.0 + 2.0, card_w),
|
||||
lines.size() * font.get_height(TOAST_FONT) + (lines.size() - 1) * gap
|
||||
+ sb.content_margin_top + sb.content_margin_bottom)
|
||||
_toast.custom_minimum_size = card
|
||||
_toast.size = card
|
||||
_toast.visible = true
|
||||
_place_toast()
|
||||
_toast.modulate.a = 1.0
|
||||
if _toast_tween != null and _toast_tween.is_valid():
|
||||
_toast_tween.kill()
|
||||
_toast_tween = create_tween()
|
||||
_toast_tween.tween_interval(TOAST_SECONDS)
|
||||
_toast_tween.tween_property(_toast, "modulate:a", 0.0, 0.45)
|
||||
_toast_tween.tween_callback(func(): _toast.visible = false)
|
||||
|
||||
|
||||
# ------------------------------------------------------------- status ---
|
||||
func set_status(text: String) -> void:
|
||||
if status_label:
|
||||
status_label.text = text
|
||||
|
||||
|
||||
func _on_doc_changed() -> void:
|
||||
_sync()
|
||||
|
||||
|
||||
func _sync() -> void:
|
||||
toolbar.sync_from_doc()
|
||||
hint_label.text = _hint_text()
|
||||
|
||||
|
||||
func _hint_text() -> String:
|
||||
if not doc.hints_enabled:
|
||||
return ""
|
||||
return MODE_HINTS.get(doc.mode, "") + HINT_TAIL
|
||||
|
||||
|
||||
func all_views() -> Array:
|
||||
return [views2d[0], view3d, views2d[1], views2d[2]]
|
||||
|
||||
|
||||
# ------------------------------------------------------ session ---
|
||||
## SAVE SYSTEM: the document autosaves to user:// (debounced) and is
|
||||
## restored when the editor reopens, so closing Godot and coming back
|
||||
## brings the models back exactly as they were left.
|
||||
var _autosave: Timer
|
||||
|
||||
|
||||
func _setup_autosave() -> void:
|
||||
_autosave = Timer.new()
|
||||
_autosave.one_shot = true
|
||||
_autosave.wait_time = 2.0
|
||||
_autosave.timeout.connect(_autosave_now)
|
||||
add_child(_autosave)
|
||||
doc.doc_changed.connect(_kick_autosave)
|
||||
doc.settings_changed.connect(_kick_autosave)
|
||||
|
||||
|
||||
func _kick_autosave() -> void:
|
||||
if _autosave != null:
|
||||
_autosave.start()
|
||||
|
||||
|
||||
func _autosave_now() -> void:
|
||||
# never serialize from inside a live gesture: the pause that lets
|
||||
# the timer fire would stall the drag mid-stroke. Retry when the
|
||||
# gesture ends; skip entirely when nothing changed since last time.
|
||||
if doc.gesture_depth > 0:
|
||||
_autosave.start()
|
||||
return
|
||||
if not doc.session_dirty:
|
||||
return
|
||||
var err := PdIo.save_session(doc)
|
||||
if err == OK:
|
||||
doc.session_dirty = false
|
||||
|
||||
|
||||
## Immediate flush (editor quit / plugin disable). Called by the plugin
|
||||
## BEFORE the screen is freed.
|
||||
func persist_session() -> void:
|
||||
if _autosave != null and not _autosave.is_stopped():
|
||||
_autosave.stop()
|
||||
if not doc.session_dirty:
|
||||
return
|
||||
var err := PdIo.save_session(doc)
|
||||
if err != OK:
|
||||
push_warning("Polydoodle: session save failed: %s"
|
||||
% error_string(err))
|
||||
else:
|
||||
doc.session_dirty = false
|
||||
|
||||
|
||||
## Load the saved session (if any) into the fresh document at startup.
|
||||
## Missing / corrupt file = silently start empty.
|
||||
func restore_session() -> void:
|
||||
var d := PdIo.load_session()
|
||||
if d.is_empty():
|
||||
return
|
||||
var n := PdIo.apply_session(doc, d)
|
||||
if n < 0:
|
||||
return
|
||||
var m := int(d.get("mode", PdDocument.Mode.OBJECT))
|
||||
if m < 0 or m > PdDocument.Mode.TEXTURE:
|
||||
m = PdDocument.Mode.OBJECT
|
||||
if m == PdDocument.Mode.TEXTURE:
|
||||
doc.set_tex_edit(bool(d.get("tex_edit", false)))
|
||||
_set_mode(m)
|
||||
doc.notify_doc()
|
||||
doc.settings_changed.emit()
|
||||
set_status("Session restored - %d object(s), right where you left them" % n)
|
||||
frame_selection()
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_EXIT_TREE:
|
||||
persist_session()
|
||||
elif what == NOTIFICATION_PREDELETE:
|
||||
if doc != null:
|
||||
doc.release()
|
||||
|
||||
|
||||
# ------------------------------------------------- in-viewport hints ---
|
||||
## One-line contextual hints drawn INSIDE each viewport (small muted text
|
||||
## at the bottom), so the editor teaches itself without reading the docs:
|
||||
## with a face or vertex selected the viewport says "Right-click: options
|
||||
## (extrude, delete...)", the texture canvas announces "wheel: scale ·
|
||||
## right-click: rotate" while an image is being placed, and so on.
|
||||
## kind: "3d" (perspective view), "2d" (orthographic views), "canvas"
|
||||
## (texture canvas). The sticker hint itself is drawn by PdUVCanvas.
|
||||
static func context_hint(doc: PdDocument, kind: String) -> String:
|
||||
if doc == null or not doc.hints_enabled:
|
||||
return ""
|
||||
var empty_3d := "Ctrl+drag: rectangle select" if kind == "3d" \
|
||||
else "drag empty space: box-select"
|
||||
match doc.mode:
|
||||
PdDocument.Mode.OBJECT:
|
||||
if doc.sel_objs.is_empty():
|
||||
return "Click a shape to select it · Shift+click: add · %s" % empty_3d
|
||||
return "Drag: move · Right-click: options (duplicate, delete and more) · Ctrl+drag: rectangle select · Del: delete"
|
||||
PdDocument.Mode.VERTEX:
|
||||
if doc.sel_verts.is_empty():
|
||||
return "Click a vertex to select it (Shift adds) · %s" % empty_3d
|
||||
return "Drag: move · Right-click: options (merge, delete and more) · Del: delete"
|
||||
PdDocument.Mode.EDGE:
|
||||
if doc.sel_edges.is_empty():
|
||||
return "Click an edge to select it (Shift adds) · %s" % empty_3d
|
||||
return "Drag: move · Right-click: options (EXTRUDE edges, delete and more) · Del: delete"
|
||||
PdDocument.Mode.FACE:
|
||||
if doc.sel_faces.is_empty():
|
||||
return "Click inside a face to select it (Shift adds) · %s" % empty_3d
|
||||
return "Drag: move · Right-click: options (EXTRUDE faces, fill, delete and more) · Del: delete"
|
||||
PdDocument.Mode.DRAW:
|
||||
return "Drag to sketch a shape · Shift: square/circle · Right-click: cancel · pick the shape on the Draw button"
|
||||
PdDocument.Mode.TEXTURE:
|
||||
if kind == "canvas":
|
||||
if doc.tex_edit:
|
||||
return "Drag islands/edges/corners to move · Right-click: options (extrude, merge, delete and more) · Wheel: zoom · MMB: pan"
|
||||
return "Drag: paint · Click an island to select it · Wheel: zoom · MMB: pan"
|
||||
if doc.tex_edit:
|
||||
return "Click a face to select it · Drag empty space: orbit"
|
||||
return "Drag on the model: paint · the Eraser tool removes paint · Wheel: zoom"
|
||||
return ""
|
||||
|
||||
|
||||
# ------------------------------------------------------ texture strip ---
|
||||
## Layout note: the texture tools live IN THE TOP TOOLBAR - the texture
|
||||
## group replaces the modeling buttons when the texture editor is active,
|
||||
## and the sliders/settings live in the right panel, so the canvas gets
|
||||
## the full lower area.
|
||||
|
||||
|
||||
func _relayout_views() -> void:
|
||||
if view_holder == null:
|
||||
return
|
||||
var r := Rect2(Vector2.ZERO, view_holder.size)
|
||||
var gap := 2.0
|
||||
# ---- Texture Paint layout: 3D on top, texture canvas below (the
|
||||
# canvas owns the full lower area - the tools live in the
|
||||
# top toolbar)
|
||||
if doc != null and doc.mode == PdDocument.Mode.TEXTURE \
|
||||
and _fullscreen_view == null:
|
||||
var gap2 := gap * 2.0
|
||||
var avail := maxf(160.0, r.size.y - gap2)
|
||||
var top_h := avail * 0.52
|
||||
top_h = clampf(top_h, 90.0, avail - 90.0)
|
||||
for v in views2d:
|
||||
v.visible = false
|
||||
view3d.visible = true
|
||||
view3d.position = r.position
|
||||
view3d.size = Vector2(r.size.x, top_h)
|
||||
uv_canvas.visible = true
|
||||
uv_canvas.position = Vector2(0, top_h + gap)
|
||||
uv_canvas.size = Vector2(r.size.x, avail - top_h)
|
||||
# refit the canvas when the layout resized it (a stale zoom
|
||||
# made the atlas appear cut off after workspace switches)
|
||||
_refit_canvas_if_resized()
|
||||
return
|
||||
if uv_canvas != null:
|
||||
uv_canvas.visible = false
|
||||
var half := (r.size - Vector2.ONE * gap) * 0.5
|
||||
var vs := all_views()
|
||||
if _fullscreen_view != null:
|
||||
# one view alone fills the area. In the texture editor the
|
||||
# expanded view can be the canvas itself.
|
||||
var fsvs := vs.duplicate()
|
||||
if doc != null and doc.mode == PdDocument.Mode.TEXTURE:
|
||||
fsvs.append(uv_canvas)
|
||||
for v in fsvs:
|
||||
v.visible = v == _fullscreen_view
|
||||
v.position = r.position
|
||||
v.size = r.size
|
||||
if _fullscreen_view == uv_canvas:
|
||||
_refit_canvas_if_resized()
|
||||
return
|
||||
var pos := [Vector2.ZERO,
|
||||
Vector2(r.size.x * 0.5 + gap * 0.5, 0.0),
|
||||
Vector2(0.0, r.size.y * 0.5 + gap * 0.5),
|
||||
Vector2(r.size.x * 0.5 + gap * 0.5, r.size.y * 0.5 + gap * 0.5)]
|
||||
for i in vs.size():
|
||||
vs[i].visible = true
|
||||
vs[i].position = pos[i]
|
||||
vs[i].size = half
|
||||
|
||||
|
||||
## Re-fit the canvas zoom when the layout changed its size (shared by the
|
||||
## normal texture layout and the expanded-canvas layout).
|
||||
func _refit_canvas_if_resized() -> void:
|
||||
if uv_canvas == null or not uv_canvas.visible:
|
||||
return
|
||||
if uv_canvas.size.distance_squared_to(_last_canvas_size) > 1.0:
|
||||
_last_canvas_size = uv_canvas.size
|
||||
uv_canvas.fit_view.call_deferred()
|
||||
|
||||
|
||||
func _toggle_view_fullscreen() -> void:
|
||||
if view_holder == null or views2d.size() < 3:
|
||||
return
|
||||
_toggle_expand(_focused_view if _focused_view != null else view3d)
|
||||
|
||||
|
||||
## Expand/retract ONE viewport (corner button or Space): the
|
||||
## expanded view alone fills the whole view area, pressing again retracts
|
||||
## to the previous layout. Works for all six views: Top/Side/Front, the
|
||||
## perspective 3D view and the texture canvas.
|
||||
func _toggle_expand(v: Control) -> void:
|
||||
if view_holder == null or v == null:
|
||||
return
|
||||
_fullscreen_view = null if _fullscreen_view == v else v
|
||||
if _fullscreen_view == null:
|
||||
set_status("View restored")
|
||||
else:
|
||||
set_status("View expanded - press the button again (or Space) to show all views")
|
||||
_relayout_views()
|
||||
_sync_expand_btns()
|
||||
|
||||
|
||||
## Mirror the expanded state on every view's corner toggle button.
|
||||
func _sync_expand_btns() -> void:
|
||||
if _expand_syncing:
|
||||
return
|
||||
_expand_syncing = true
|
||||
var all: Array = all_views()
|
||||
if uv_canvas != null:
|
||||
all.append(uv_canvas)
|
||||
for v in all:
|
||||
if v != null and "expand_btn" in v \
|
||||
and v.expand_btn != null \
|
||||
and is_instance_valid(v.expand_btn):
|
||||
v.expand_btn.set_pressed_no_signal(
|
||||
_fullscreen_view == v)
|
||||
_expand_syncing = false
|
||||
|
||||
|
||||
const HINT_TAIL := " · Space: expand focused view"
|
||||
|
||||
const MODE_HINTS := {
|
||||
PdDocument.Mode.OBJECT: "Click: select · Drag: move · Shift+Click: multi-select · 2D: drag empty = box-select · 3D: drag empty = orbit · Ctrl+drag: rectangle multi-select · right-click: object menu · Ctrl+D: duplicate",
|
||||
PdDocument.Mode.VERTEX: "Drag a vertex to move it · Shift+Click: add · 2D: drag empty = box-select · 3D: Ctrl+drag: rectangle select · right-click: merge / delete menu · Del: delete",
|
||||
PdDocument.Mode.EDGE: "Click an edge, drag to move · Shift+Click: add · 3D: right-click: EXTRUDE edges / delete · Del: delete",
|
||||
PdDocument.Mode.FACE: "Click inside a face, drag to move · Shift+Click: add · 3D: right-click: EXTRUDE face(s) / fill / delete · Del: delete",
|
||||
PdDocument.Mode.DRAW: "Drag in ANY viewport to sketch - pick the shape from the dropdown on the Draw button · Shift: square/circle · Right-drag: pan · MMB or Alt+drag: orbit · Right-click: cancel",
|
||||
PdDocument.Mode.TEXTURE: "Texture editor · tools: TOP TOOLBAR · sizes, color, resolution: RIGHT PANEL · full guide: the book button",
|
||||
}
|
||||
|
||||
|
||||
func _set_mode(m: int) -> void:
|
||||
# workspace memory: remember the last 3D mode so the Texture
|
||||
# Editor button and KEY_6 can toggle back to where the user was
|
||||
if m != PdDocument.Mode.TEXTURE:
|
||||
last_3d_mode = m
|
||||
else:
|
||||
_fullscreen_view = null
|
||||
_sync_expand_btns()
|
||||
doc.set_mode(m)
|
||||
hint_label.text = _hint_text()
|
||||
_relayout_views()
|
||||
_sync()
|
||||
|
||||
|
||||
## Toggle between the two workspaces (the toolbar split button, KEY_6).
|
||||
func toggle_workspace() -> void:
|
||||
if doc.mode == PdDocument.Mode.TEXTURE:
|
||||
_set_mode(last_3d_mode)
|
||||
else:
|
||||
_set_mode(PdDocument.Mode.TEXTURE)
|
||||
|
||||
|
||||
func frame_selection() -> void:
|
||||
if doc.objects.is_empty():
|
||||
doc.warn("Nothing to frame. The scene is empty - add a shape first.")
|
||||
return
|
||||
view3d.frame_selection()
|
||||
|
||||
|
||||
# ---------------------------------------------------------- shortcuts ---
|
||||
## G / S / R pick the Move / Scale / Rotate gizmo, Blender-style. The key
|
||||
## for the kind that is ALREADY active hides the gizmo again - the exact
|
||||
## semantics of the toolbar's [Move] [Scale] [Rotate] toggles.
|
||||
func _gizmo_shortcut(kind: int) -> void:
|
||||
if doc.gizmo_on and doc.gizmo_kind == kind:
|
||||
doc.set_gizmo(false)
|
||||
else:
|
||||
doc.set_gizmo_kind(kind)
|
||||
doc.set_gizmo(true)
|
||||
_warn_gizmo_target()
|
||||
|
||||
|
||||
func _warn_gizmo_target() -> void:
|
||||
var hint := doc.gizmo_hint()
|
||||
if hint != "":
|
||||
doc.warn(hint)
|
||||
|
||||
|
||||
func _shortcut_input(event: InputEvent) -> void:
|
||||
if not visible:
|
||||
return
|
||||
var k := event as InputEventKey
|
||||
if k == null or not k.pressed or k.echo:
|
||||
return
|
||||
var fo := get_viewport().gui_get_focus_owner()
|
||||
if fo is LineEdit or fo is TextEdit or fo is SpinBox:
|
||||
return
|
||||
var ctrl := k.ctrl_pressed or k.meta_pressed
|
||||
match k.keycode:
|
||||
KEY_1: _set_mode(PdDocument.Mode.OBJECT); get_viewport().set_input_as_handled()
|
||||
KEY_2: _set_mode(PdDocument.Mode.VERTEX); get_viewport().set_input_as_handled()
|
||||
KEY_3: _set_mode(PdDocument.Mode.EDGE); get_viewport().set_input_as_handled()
|
||||
KEY_4: _set_mode(PdDocument.Mode.FACE); get_viewport().set_input_as_handled()
|
||||
KEY_5: _set_mode(PdDocument.Mode.DRAW); get_viewport().set_input_as_handled()
|
||||
KEY_6: toggle_workspace(); get_viewport().set_input_as_handled()
|
||||
KEY_G:
|
||||
# 3D workspace: G/S/R pick the Move/Scale/Rotate
|
||||
# gizmo (pressing the active kind's key hides the
|
||||
# gizmo, same as the toolbar toggles). Texture
|
||||
# workspace keeps G = gizmo visibility toggle.
|
||||
if doc.mode == PdDocument.Mode.TEXTURE:
|
||||
doc.set_gizmo(not doc.gizmo_on)
|
||||
else:
|
||||
_gizmo_shortcut(0)
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_S:
|
||||
# 3D workspace: S = Scale gizmo; texture workspace
|
||||
# keeps the snap toggle (T toggles snap everywhere).
|
||||
if doc.mode == PdDocument.Mode.TEXTURE:
|
||||
doc.set_snap(not doc.snap_enabled)
|
||||
else:
|
||||
_gizmo_shortcut(1)
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_T:
|
||||
doc.set_snap(not doc.snap_enabled)
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_V:
|
||||
doc.set_grid_visible(not doc.grid_visible)
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_B:
|
||||
doc.set_both_sides(not doc.both_sides)
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_Z:
|
||||
if ctrl:
|
||||
if event.shift_pressed:
|
||||
doc.do_redo()
|
||||
else:
|
||||
doc.do_undo()
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_Y:
|
||||
if ctrl:
|
||||
doc.do_redo()
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_D:
|
||||
if ctrl:
|
||||
doc.duplicate_selected()
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_A:
|
||||
if ctrl:
|
||||
doc.select_all()
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_DELETE, KEY_BACKSPACE:
|
||||
doc.delete_selection()
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_F:
|
||||
frame_selection()
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_R:
|
||||
if doc.mode == PdDocument.Mode.TEXTURE and doc.tex_edit:
|
||||
# UV editor: rotate the selected faces' UVs 90
|
||||
# degrees (Shift = counter-clockwise)
|
||||
doc.rotate_uv_selected(doc.active_obj,
|
||||
-1 if k.shift_pressed else 1)
|
||||
else:
|
||||
# 3D workspace: R = Rotate gizmo
|
||||
_gizmo_shortcut(2)
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_SPACE:
|
||||
_toggle_view_fullscreen()
|
||||
get_viewport().set_input_as_handled()
|
||||
KEY_ESCAPE:
|
||||
doc.clear_all_sel()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _make_input_handled() -> void:
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
# ------------------------------------------------------------- export ---
|
||||
func _file_dialog(save: bool, filters: PackedStringArray, cb: Callable, title: String,
|
||||
access := EditorFileDialog.ACCESS_RESOURCES, start_dir := "res://") -> void:
|
||||
if _dlg and is_instance_valid(_dlg):
|
||||
_dlg.queue_free()
|
||||
_dlg = EditorFileDialog.new()
|
||||
_dlg.access = access
|
||||
_dlg.file_mode = EditorFileDialog.FILE_MODE_SAVE_FILE if save \
|
||||
else EditorFileDialog.FILE_MODE_OPEN_FILE
|
||||
_dlg.filters = filters
|
||||
_dlg.current_dir = start_dir
|
||||
_dlg.title = title
|
||||
_dlg.ok_button_text = "Save" if save else "Open"
|
||||
EditorInterface.get_base_control().add_child(_dlg)
|
||||
_dlg.file_selected.connect(cb)
|
||||
_dlg.canceled.connect(func():
|
||||
_dlg.queue_free()
|
||||
_dlg = null)
|
||||
_dlg.popup_centered(Vector2i(760, 460))
|
||||
|
||||
|
||||
func _refresh_filesystem() -> void:
|
||||
EditorInterface.get_resource_filesystem().scan()
|
||||
|
||||
|
||||
func _save_project() -> void:
|
||||
_file_dialog(true,
|
||||
PackedStringArray(["*.pdoodle ; Polydoodle Project"]),
|
||||
func(path: String):
|
||||
var err := PdIo.save_project(doc, path)
|
||||
if err == OK:
|
||||
_refresh_filesystem()
|
||||
set_status("Saved project to %s" % path if err == OK
|
||||
else "Save failed: %s" % error_string(err)),
|
||||
"Save Polydoodle Project")
|
||||
|
||||
|
||||
var _importing := false
|
||||
var _last_import_dir := ""
|
||||
var _import_dlg: AcceptDialog = null
|
||||
|
||||
|
||||
func _import_model() -> void:
|
||||
if _importing:
|
||||
set_status("A model import is already running")
|
||||
return
|
||||
var start := _last_import_dir
|
||||
if start.is_empty() or not DirAccess.dir_exists_absolute(start):
|
||||
start = ProjectSettings.globalize_path("res://")
|
||||
_file_dialog(false, PdImport.dialog_filters(),
|
||||
func(path: String):
|
||||
_last_import_dir = path.get_base_dir()
|
||||
_run_import(path),
|
||||
"Import 3D Model", EditorFileDialog.ACCESS_FILESYSTEM, start)
|
||||
|
||||
|
||||
func _run_import(path: String) -> void:
|
||||
if _importing:
|
||||
set_status("A model import is already running")
|
||||
return
|
||||
_importing = true
|
||||
path = ProjectSettings.localize_path(path)
|
||||
var opts := {"textures": true, "merge": true, "fit": true}
|
||||
var progress := func(f: float, text: String):
|
||||
set_status("%s... %d%%" % [text, int(f * 100.0)])
|
||||
var model: Dictionary = await PdImport.load_model(path, opts, self,
|
||||
progress)
|
||||
if not is_instance_valid(self) or not is_inside_tree():
|
||||
return
|
||||
if not model["ok"]:
|
||||
_importing = false
|
||||
_import_report("Import failed", String(model["error"]), [])
|
||||
return
|
||||
var res: Dictionary = await PdImport.build(model, opts, self, progress)
|
||||
if not is_instance_valid(self) or not is_inside_tree():
|
||||
return
|
||||
_importing = false
|
||||
if not res["ok"]:
|
||||
_import_report("Import failed", String(res["error"]), [])
|
||||
return
|
||||
var objs: Array = res["objects"]
|
||||
doc.add_imported_objects(objs, path.get_file().get_basename())
|
||||
frame_selection()
|
||||
set_status("Imported %s: %d objects, %d faces" % [
|
||||
path.get_file(), objs.size(), int(res["faces"])])
|
||||
var notes: Array = res["warnings"]
|
||||
if not notes.is_empty():
|
||||
_import_report("Import notes",
|
||||
"%s was imported with notes:" % path.get_file(), notes)
|
||||
|
||||
|
||||
func _import_report(title: String, text: String, notes: Array) -> void:
|
||||
set_status(text)
|
||||
var font := get_theme_font("font", "Label")
|
||||
var fsize := get_theme_font_size("font_size", "Label")
|
||||
var win := get_window().size
|
||||
# the dialog never takes more than ~70% of the editor window; the text
|
||||
# is trimmed to the lines that fit so nothing is ever clipped
|
||||
var max_w := clampf(win.x * 0.6, 300.0, 520.0)
|
||||
var max_h := int(win.y * 0.7)
|
||||
var line_h := font.get_height(fsize) + 3.0
|
||||
var capacity := maxi(4, int((max_h - 110.0) / line_h))
|
||||
var out := PackedStringArray()
|
||||
out.append_array(_wrap_text(text, font, fsize, max_w, mini(4, capacity)))
|
||||
var shown := 0
|
||||
for n in notes:
|
||||
var item := _wrap_text(String(n), font, fsize, max_w - 14.0, 2)
|
||||
if out.size() + item.size() >= capacity:
|
||||
out.append("- ... and %d more" % (notes.size() - shown))
|
||||
break
|
||||
for k in item.size():
|
||||
out.append(("- " if k == 0 else " ") + item[k])
|
||||
shown += 1
|
||||
if is_instance_valid(_import_dlg):
|
||||
_import_dlg.queue_free()
|
||||
var dlg := AcceptDialog.new()
|
||||
dlg.title = title
|
||||
dlg.dialog_text = "\n".join(out)
|
||||
dlg.dialog_autowrap = false # wrapped above, so the size is exact
|
||||
dlg.exclusive = false
|
||||
dlg.min_size = Vector2i(320, 0)
|
||||
dlg.max_size = Vector2i(int(max_w) + 90, max_h)
|
||||
dlg.confirmed.connect(dlg.queue_free)
|
||||
dlg.canceled.connect(dlg.queue_free)
|
||||
_import_dlg = dlg
|
||||
add_child(dlg)
|
||||
dlg.popup_centered()
|
||||
|
||||
|
||||
## Image import for the texture editor: the picked image floats on the
|
||||
## canvas as a sticker (move / wheel-scale / click places). Placement is
|
||||
## alpha-blended into the atlas and undoable; afterwards the texels can
|
||||
## be painted over or erased like any other paint.
|
||||
func _import_image() -> void:
|
||||
if doc.active() == null:
|
||||
doc.warn("Select a shape first, then import an image onto its texture.")
|
||||
return
|
||||
_file_dialog(false,
|
||||
PackedStringArray(["*.png,*.jpg,*.jpeg,*.webp,*.bmp,*.tga ; Images"]),
|
||||
func(path: String):
|
||||
var img := Image.load_from_file(path)
|
||||
if img == null or img.is_empty():
|
||||
doc.warn("Could not load image: %s" % path)
|
||||
return
|
||||
uv_canvas.begin_sticker(img),
|
||||
"Import Image to Texture")
|
||||
|
||||
|
||||
func _open_project() -> void:
|
||||
_file_dialog(false,
|
||||
PackedStringArray(["*.pdoodle ; Polydoodle Project"]),
|
||||
func(path: String):
|
||||
var d := PdIo.load_project(path)
|
||||
if d == null:
|
||||
set_status("Could not open %s" % path)
|
||||
return
|
||||
# copy loaded doc contents into our live doc
|
||||
doc.restore_snapshot(d.snapshot())
|
||||
doc.bg_color = d.bg_color
|
||||
doc.grid_size = d.grid_size
|
||||
doc.grid_visible = d.grid_visible
|
||||
doc.snap_enabled = d.snap_enabled
|
||||
doc.gizmo_on = d.gizmo_on
|
||||
doc.draw_free = d.draw_free
|
||||
doc.draw_kind = d.draw_kind
|
||||
doc.paint_color = d.paint_color
|
||||
doc.paint_tool = d.paint_tool
|
||||
doc.brush_size = d.brush_size
|
||||
doc.pixel_size = d.pixel_size
|
||||
doc.recent_colors = d.recent_colors
|
||||
doc.both_sides = d.both_sides
|
||||
doc.view_shading = d.view_shading
|
||||
doc.uv_snap = d.uv_snap
|
||||
doc.tex_filter = d.tex_filter
|
||||
doc.pixel_px = d.pixel_px
|
||||
doc.gizmo_kind = d.gizmo_kind
|
||||
doc.brush_opacity = d.brush_opacity
|
||||
doc.brush_smooth = d.brush_smooth
|
||||
doc.face_lock = d.face_lock
|
||||
doc.inset_dist = d.inset_dist
|
||||
doc.hints_enabled = d.hints_enabled
|
||||
doc.show_checker = d.show_checker
|
||||
doc.export_checker = d.export_checker
|
||||
d.release()
|
||||
doc.notify_doc()
|
||||
doc.settings_changed.emit()
|
||||
set_status("Opened %s" % path)
|
||||
frame_selection(),
|
||||
"Open Polydoodle Project")
|
||||
|
||||
|
||||
func _export_result(err: Error, ok_text: String) -> void:
|
||||
if err == OK:
|
||||
_refresh_filesystem()
|
||||
set_status(ok_text)
|
||||
else:
|
||||
doc.warn("Export failed: %s. Check that the folder is writable." % error_string(err))
|
||||
|
||||
|
||||
func _export(kind: String) -> void:
|
||||
if doc.exportable_count() == 0:
|
||||
if doc.objects.is_empty():
|
||||
doc.warn("Nothing to export. The scene is empty - add a shape first.")
|
||||
else:
|
||||
doc.warn("Nothing to export. Every shape is hidden - show one (eye icon in the hierarchy).")
|
||||
return
|
||||
match kind:
|
||||
"tres":
|
||||
_file_dialog(true, PackedStringArray(["*.tres ; Godot Mesh"]),
|
||||
func(path: String):
|
||||
_export_result(PdIo.save_mesh_tres(doc, path), "Exported mesh to %s" % path),
|
||||
"Export Mesh (.tres)")
|
||||
"tscn":
|
||||
_file_dialog(true, PackedStringArray(["*.tscn ; Godot Scene"]),
|
||||
func(path: String):
|
||||
_export_result(PdIo.save_scene_tscn(doc, path), "Exported scene to %s" % path),
|
||||
"Export Scene (.tscn)")
|
||||
"obj":
|
||||
_file_dialog(true, PackedStringArray(["*.obj ; Wavefront OBJ"]),
|
||||
func(path: String):
|
||||
_export_result(PdIo.write_obj(doc, path), "Exported OBJ to %s" % path),
|
||||
"Export OBJ")
|
||||
"scene":
|
||||
var msg := PdIo.add_to_scene(doc)
|
||||
if msg.begins_with("Open or") or msg.begins_with("Nothing"):
|
||||
doc.warn(msg)
|
||||
else:
|
||||
set_status(msg)
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
uid://cisosn6furd2b
|
||||
Executable
+1208
File diff suppressed because it is too large
Load Diff
Executable
+1
@@ -0,0 +1 @@
|
||||
uid://dsvliouk8p40v
|
||||
Executable
+849
@@ -0,0 +1,849 @@
|
||||
@tool
|
||||
class_name PdToolbar
|
||||
extends HBoxContainer
|
||||
## Top toolbar: icon-only buttons grouped by category, with tooltips.
|
||||
## The FIRST button is the two-half WORKSPACE switch
|
||||
## [ 3D Editor | Texture Editor ] - exactly one half is always active.
|
||||
## The toolbar then shows the CONTEXTUAL group of the active workspace:
|
||||
## - MODEL group: selection modes, Draw split, view toggles, mesh edits
|
||||
## - TEXTURE group: [Paint | Edit UV] submode + that submode's tools
|
||||
## Exactly one group is visible - texture tools REPLACE the modeling
|
||||
## buttons when the texture editor is active. Sliders and deeper settings
|
||||
## live in the right panel.
|
||||
## Draw stays a SPLIT BUTTON: the main half shows the current shape icon
|
||||
## and activates that mode, the attached arrow half opens the shape menu.
|
||||
## The gizmo button is a split too: main toggles the gizmo, the arrow menu
|
||||
## picks Move or Scale.
|
||||
|
||||
signal mode_requested(m: int)
|
||||
signal workspace_requested(tex: bool)
|
||||
signal toggle_gizmo(v: bool)
|
||||
signal gizmo_kind_requested(k: int)
|
||||
signal toggle_snap(v: bool)
|
||||
signal toggle_grid(v: bool)
|
||||
signal toggle_both_sides(v: bool)
|
||||
signal draw_kind(k: String)
|
||||
signal add_shape(kind: String)
|
||||
signal duplicate_requested
|
||||
signal delete_requested
|
||||
signal undo_requested
|
||||
signal redo_requested
|
||||
signal save_requested
|
||||
signal load_requested
|
||||
signal import_model_requested
|
||||
signal export_requested(kind: String)
|
||||
signal bg_changed(c: Color)
|
||||
signal tex_submode(edit: bool)
|
||||
signal paint_tool_requested(t: String)
|
||||
signal uv_snap_requested(v: bool)
|
||||
signal rotate_uv_requested(dir: int)
|
||||
signal uv_tool_requested(t: String)
|
||||
signal import_requested
|
||||
signal detach_requested
|
||||
signal reset_uvs_requested
|
||||
|
||||
var doc: PdDocument
|
||||
|
||||
var _ws_3d: Button
|
||||
var _ws_tex: Button
|
||||
var _mode_buttons := {}
|
||||
var _mode_group := ButtonGroup.new()
|
||||
# Side-by-side gizmo pair: [Move] [Scale] - the active kind is pressed
|
||||
# while the gizmo is ON; clicking the pressed one again turns it off.
|
||||
var _btn_gizmo_move: Button
|
||||
var _btn_gizmo_scale: Button
|
||||
var _btn_gizmo_rotate: Button
|
||||
var _btn_snap: Button
|
||||
var _btn_grid: Button
|
||||
var _btn_sides: Button
|
||||
var _draw_main: Button
|
||||
var _draw_arrow: Button
|
||||
var _draw_popup: PopupMenu
|
||||
var _btn_undo: Button
|
||||
var _btn_redo: Button
|
||||
var _bg_pick: ColorPickerButton
|
||||
var _btn_settings: Button
|
||||
var _btn_docs: Button
|
||||
var _settings_popup: PopupPanel
|
||||
var _shade_btns: Array = []
|
||||
var _grid_btn: Button
|
||||
var _hints_btn: Button
|
||||
var _checker_btn: Button
|
||||
var _bake_btn: Button
|
||||
var _docs_win: Window
|
||||
|
||||
# contextual groups: exactly one is visible at a time
|
||||
var _model_box: HBoxContainer
|
||||
var _tex_box: HBoxContainer
|
||||
var _tex_paint_box: HBoxContainer
|
||||
var _tex_uv_box: HBoxContainer
|
||||
var _tex_paint: Button
|
||||
var _tex_edituv: Button
|
||||
var _tex_tool_btns := {}
|
||||
var _tex_uv_snap: Button
|
||||
var _tex_uv_rotate: Button
|
||||
var _tex_uv_scale: Button
|
||||
var _uv_tool_group: ButtonGroup
|
||||
|
||||
const ICONS := preload("res://addons/polydoodle/core/pd_icons.gd")
|
||||
const ACCENT := PdDocument.ACCENT
|
||||
const ACCENT_DARK := PdDocument.ACCENT_DARK # bottom bevel of active buttons
|
||||
|
||||
const DRAW_ICONS := {
|
||||
"Freehand": "tool_freehand",
|
||||
"Rectangle": "tool_rect",
|
||||
"Circle": "tool_circle",
|
||||
"Triangle": "tool_triangle",
|
||||
"Pentagon": "tool_pentagon",
|
||||
"Hexagon": "tool_hexagon",
|
||||
"Star": "tool_star",
|
||||
"Torus": "tool_torus",
|
||||
}
|
||||
|
||||
|
||||
func _icon(n: String) -> Texture2D:
|
||||
return ICONS.get_icon(n.trim_suffix(".svg"))
|
||||
|
||||
|
||||
# ------------------------------------------------------------ styling ---
|
||||
## TACTILE button states - reserved for the workspace split button, the
|
||||
## right panel and the settings popup. Idle is flat dark, hover lifts
|
||||
## slightly, and the ACTIVE (pressed) state is a SOLID accent fill - no
|
||||
## transparency - with a darker bottom edge (2px bevel) that gives the
|
||||
## button a physical 3D look, like a key sitting lower on its base. A
|
||||
## lighter top border adds a subtle rim light from above.
|
||||
func _box(corners := Vector4(4, 4, 4, 4)) -> StyleBoxFlat:
|
||||
var sb := StyleBoxFlat.new()
|
||||
sb.bg_color = Color(1, 1, 1, 0.04)
|
||||
sb.set_corner_radius_all(0)
|
||||
sb.corner_radius_top_left = int(corners.x)
|
||||
sb.corner_radius_bottom_left = int(corners.y)
|
||||
sb.corner_radius_top_right = int(corners.z)
|
||||
sb.corner_radius_bottom_right = int(corners.w)
|
||||
sb.content_margin_left = 5
|
||||
sb.content_margin_right = 5
|
||||
sb.content_margin_top = 3
|
||||
sb.content_margin_bottom = 3
|
||||
return sb
|
||||
|
||||
|
||||
func _bevel(sb: StyleBoxFlat, bottom_px: int) -> StyleBoxFlat:
|
||||
sb.border_width_bottom = bottom_px
|
||||
sb.border_color = ACCENT_DARK
|
||||
return sb
|
||||
|
||||
|
||||
func _paint_states(b: Button, base: StyleBoxFlat) -> void:
|
||||
var hover := base.duplicate()
|
||||
hover.bg_color = Color(1, 1, 1, 0.10)
|
||||
# ACTIVE: solid accent (opaque), darker bottom bevel = 3D look
|
||||
var pressed := base.duplicate()
|
||||
pressed.bg_color = ACCENT
|
||||
_bevel(pressed, 3)
|
||||
pressed.content_margin_top = 4
|
||||
pressed.content_margin_bottom = 2
|
||||
# active + hovered: same solid fill, slightly lifted top rim
|
||||
var hover_pressed := base.duplicate()
|
||||
hover_pressed.bg_color = ACCENT.lightened(0.08)
|
||||
_bevel(hover_pressed, 3)
|
||||
hover_pressed.content_margin_top = 4
|
||||
hover_pressed.content_margin_bottom = 2
|
||||
var disabled := base.duplicate()
|
||||
disabled.bg_color = Color(1, 1, 1, 0.015)
|
||||
b.add_theme_stylebox_override("normal", base)
|
||||
b.add_theme_stylebox_override("hover", hover)
|
||||
b.add_theme_stylebox_override("pressed", pressed)
|
||||
b.add_theme_stylebox_override("hover_pressed", hover_pressed)
|
||||
b.add_theme_stylebox_override("disabled", disabled)
|
||||
b.add_theme_stylebox_override("focus", StyleBoxEmpty.new())
|
||||
# Pin EVERY icon state to white. Without icon_hover_pressed_color the
|
||||
# editor theme's fallback tints the icon blue while the active half of
|
||||
# the workspace split is hovered - blue on blue.
|
||||
b.add_theme_color_override("icon_pressed_color", Color(1, 1, 1, 1))
|
||||
b.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.82))
|
||||
b.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 1))
|
||||
b.add_theme_color_override("icon_hover_pressed_color", Color(1, 1, 1, 1))
|
||||
b.add_theme_color_override("icon_focus_color", Color(1, 1, 1, 1))
|
||||
b.add_theme_color_override("icon_disabled_color", Color(1, 1, 1, 0.3))
|
||||
|
||||
|
||||
func _style_tactile(b: Button) -> void:
|
||||
_paint_states(b, _box())
|
||||
|
||||
|
||||
## FLAT toolbar states - the Godot-default look for every top-toolbar
|
||||
## button EXCEPT the workspace split. At rest the button is invisible:
|
||||
## only the icon shows. Hovering washes the background slightly lighter.
|
||||
## The ACTIVE (toggled) state colors the ICON with the theme accent - no
|
||||
## solid fill, no bevel.
|
||||
## Geometry: every button is a SQUARE chip with rounded
|
||||
## corners like Godot's own toolbar - symmetric margins, a fixed 28x28
|
||||
## minimum size and shrink-center so the highlight can never stretch
|
||||
## into a portrait rectangle.
|
||||
const TB_CHIP := 28.0 # square side of a toolbar button
|
||||
const TB_RADIUS := 5 # corner radius of the highlight
|
||||
|
||||
func _style_flat(b: Button) -> void:
|
||||
var normal := StyleBoxFlat.new()
|
||||
normal.bg_color = Color(1, 1, 1, 0)
|
||||
normal.set_corner_radius_all(TB_RADIUS)
|
||||
normal.content_margin_left = 6
|
||||
normal.content_margin_right = 6
|
||||
normal.content_margin_top = 6
|
||||
normal.content_margin_bottom = 6
|
||||
var hover := normal.duplicate()
|
||||
hover.bg_color = Color(1, 1, 1, 0.07)
|
||||
var pressed := normal.duplicate()
|
||||
pressed.bg_color = Color(1, 1, 1, 0.045)
|
||||
var hover_pressed := normal.duplicate()
|
||||
hover_pressed.bg_color = Color(1, 1, 1, 0.09)
|
||||
var disabled := normal.duplicate()
|
||||
b.add_theme_stylebox_override("normal", normal)
|
||||
b.add_theme_stylebox_override("hover", hover)
|
||||
b.add_theme_stylebox_override("pressed", pressed)
|
||||
b.add_theme_stylebox_override("hover_pressed", hover_pressed)
|
||||
b.add_theme_stylebox_override("disabled", disabled)
|
||||
b.add_theme_stylebox_override("focus", StyleBoxEmpty.new())
|
||||
b.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.78))
|
||||
b.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 1))
|
||||
b.add_theme_color_override("icon_pressed_color", ACCENT)
|
||||
b.add_theme_color_override("icon_disabled_color", Color(1, 1, 1, 0.28))
|
||||
b.custom_minimum_size = Vector2(TB_CHIP, TB_CHIP)
|
||||
b.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
|
||||
|
||||
func _style(b: Button) -> void:
|
||||
# default for toolbar buttons: flat Godot-like states. The workspace
|
||||
# split and the settings popup explicitly ask for _style_tactile.
|
||||
_style_flat(b)
|
||||
|
||||
|
||||
func _button(icon: String, tip: String) -> Button:
|
||||
var b := Button.new()
|
||||
b.icon = _icon(icon)
|
||||
b.text = ""
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.tooltip_text = tip
|
||||
b.add_theme_constant_override("icon_max_width", 16)
|
||||
_style(b)
|
||||
return b
|
||||
|
||||
|
||||
func _toggle(icon: String, tip: String, group: ButtonGroup = null) -> Button:
|
||||
var b := _button(icon, tip)
|
||||
b.toggle_mode = true
|
||||
b.button_group = group
|
||||
return b
|
||||
|
||||
|
||||
func _sep() -> VSeparator:
|
||||
return VSeparator.new()
|
||||
|
||||
|
||||
func _gap(px: float) -> Control:
|
||||
var c := Control.new()
|
||||
c.custom_minimum_size = Vector2(px, 0)
|
||||
return c
|
||||
|
||||
|
||||
## A joined pair [main | arrow]: the main half activates the mode and
|
||||
## shows the current tool icon; the arrow half opens the tool menu. The
|
||||
## arrow carries a visible chevron icon so the dropdown affordance reads
|
||||
## at a glance. `tactile` keeps the 3D key look - used by the workspace
|
||||
## switch only; every other split is flat.
|
||||
func _split(main_tip: String, arrow_tip: String, tactile := false) -> Array:
|
||||
var box := HBoxContainer.new()
|
||||
box.add_theme_constant_override("separation", 0)
|
||||
var main := Button.new()
|
||||
main.toggle_mode = true
|
||||
main.focus_mode = Control.FOCUS_NONE
|
||||
main.tooltip_text = main_tip
|
||||
main.add_theme_constant_override("icon_max_width", 16)
|
||||
if tactile:
|
||||
_paint_states(main, _box(Vector4(4, 4, 0, 0)))
|
||||
else:
|
||||
_style_flat(main)
|
||||
# joined pill: outer corners rounded, inner corners square so the
|
||||
# two square chips read as one control
|
||||
_join_split_corners(main, true)
|
||||
var arrow := Button.new()
|
||||
arrow.focus_mode = Control.FOCUS_NONE
|
||||
arrow.tooltip_text = arrow_tip
|
||||
arrow.icon = _icon("arrow_down") # the dropdown indicator
|
||||
arrow.custom_minimum_size = Vector2(20, TB_CHIP)
|
||||
arrow.add_theme_constant_override("icon_max_width", 12)
|
||||
if tactile:
|
||||
_paint_states(arrow, _box(Vector4(0, 0, 4, 4)))
|
||||
else:
|
||||
_style_flat(arrow)
|
||||
_join_split_corners(arrow, false)
|
||||
if not tactile:
|
||||
arrow.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.5))
|
||||
arrow.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 0.95))
|
||||
arrow.add_theme_color_override("icon_pressed_color", ACCENT)
|
||||
else:
|
||||
arrow.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.55))
|
||||
arrow.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 0.95))
|
||||
box.add_child(main)
|
||||
box.add_child(arrow)
|
||||
return [box, main, arrow]
|
||||
|
||||
|
||||
## Reroute the corner radii of a flat split half: the OUTER corners stay
|
||||
## rounded (the chip look), the INNER corners (where the two halves meet)
|
||||
## square. `is_main` picks which side is outer.
|
||||
func _join_split_corners(b: Button, is_main: bool) -> void:
|
||||
for state in ["normal", "hover", "pressed", "hover_pressed", "disabled"]:
|
||||
var sb := b.get_theme_stylebox(state) as StyleBoxFlat
|
||||
if sb == null:
|
||||
continue
|
||||
var s := sb.duplicate()
|
||||
s.corner_radius_top_left = TB_RADIUS if is_main else 0
|
||||
s.corner_radius_bottom_left = TB_RADIUS if is_main else 0
|
||||
s.corner_radius_top_right = 0 if is_main else TB_RADIUS
|
||||
s.corner_radius_bottom_right = 0 if is_main else TB_RADIUS
|
||||
b.add_theme_stylebox_override(state, s)
|
||||
|
||||
|
||||
func _open_popup(pm: PopupMenu, at: Control) -> void:
|
||||
var gp := at.get_global_rect()
|
||||
pm.position = Vector2i(int(gp.position.x), int(gp.end.y) + 2)
|
||||
pm.popup()
|
||||
|
||||
|
||||
func setup(d: PdDocument) -> void:
|
||||
doc = d
|
||||
add_theme_constant_override("separation", 3)
|
||||
|
||||
# --- WORKSPACE switch (first buttons): 3D Editor | Texture Editor
|
||||
# A joined pair where EXACTLY ONE half is always pressed: the left
|
||||
# half is the 3D modeler (quad view + mesh tools), the right half
|
||||
# the texture editor (3D viewport + texture canvas + tool strip).
|
||||
# The ONLY tactile control on the toolbar: the 3D key look marks
|
||||
# it as the master switch of the whole editor.
|
||||
var wsp := _split("3D Editor\nQuad view: Top / Perspective / Side / Front with all modeling tools (1-5)",
|
||||
"Texture Editor\n3D viewport over the texture canvas: paint and edit UVs (6)", true)
|
||||
_ws_3d = wsp[1]
|
||||
_ws_tex = wsp[2]
|
||||
# the right half is a mode, not a dropdown arrow: a dedicated
|
||||
# checkered-cube icon (distinct from the Edit-UV submode button's)
|
||||
# inside a shared button group, so exactly one half reads as
|
||||
# active at a time.
|
||||
_ws_3d.icon = _icon("ws_3d")
|
||||
_ws_tex.icon = _icon("ws_uv")
|
||||
_ws_tex.toggle_mode = true # the arrow half is not a toggle by default
|
||||
_ws_tex.add_theme_constant_override("icon_max_width", 16)
|
||||
var wsgrp := ButtonGroup.new()
|
||||
_ws_3d.button_group = wsgrp
|
||||
_ws_tex.button_group = wsgrp
|
||||
_ws_3d.pressed.connect(func(): workspace_requested.emit(false))
|
||||
_ws_tex.pressed.connect(func(): workspace_requested.emit(true))
|
||||
add_child(wsp[0])
|
||||
|
||||
add_child(_gap(8))
|
||||
|
||||
# ================================================== MODEL group ==
|
||||
# All 3D-modeling buttons. Hidden while the texture editor is
|
||||
# active - the TEXTURE group replaces it in place.
|
||||
_model_box = HBoxContainer.new()
|
||||
_model_box.add_theme_constant_override("separation", 3)
|
||||
add_child(_model_box)
|
||||
|
||||
# --- ADD MODELS: front of the toolbar group, directly after the
|
||||
# workspace switch - the quickest way to start a scene
|
||||
var add := _menu("add", "Add a primitive shape")
|
||||
var am := add.get_popup()
|
||||
am.add_theme_font_size_override("font_size", 12)
|
||||
am.add_item("Cube", 0)
|
||||
am.add_item("Plane", 1)
|
||||
am.add_item("Cylinder", 2)
|
||||
am.add_item("Sphere", 3)
|
||||
am.add_item("Prism", 4)
|
||||
am.add_item("Torus", 5)
|
||||
am.id_pressed.connect(func(id: int):
|
||||
add_shape.emit(["Cube", "Plane", "Cylinder", "Sphere", "Prism", "Torus"][id]))
|
||||
_model_box.add_child(add)
|
||||
_model_box.add_child(_gap(6))
|
||||
|
||||
# --- selection modes (category 1) ---
|
||||
var modes := [
|
||||
[PdDocument.Mode.OBJECT, "mode_object", "Object mode (1)\nSelect and move whole shapes"],
|
||||
[PdDocument.Mode.VERTEX, "mode_vertex", "Vertex mode (2)\nSelect and drag vertices"],
|
||||
[PdDocument.Mode.EDGE, "mode_edge", "Edge mode (3)\nSelect and drag edges"],
|
||||
[PdDocument.Mode.FACE, "mode_face", "Face mode (4)\nSelect and move faces"],
|
||||
]
|
||||
for m in modes:
|
||||
var b := _toggle(m[1], m[2], _mode_group)
|
||||
b.pressed.connect(func(): mode_requested.emit(m[0]))
|
||||
_mode_buttons[m[0]] = b
|
||||
_model_box.add_child(b)
|
||||
|
||||
# --- draw (category 2, set slightly apart) ---
|
||||
_model_box.add_child(_gap(10))
|
||||
|
||||
# Draw: split button - main shows the current shape, arrow opens
|
||||
# the shapes menu; picking a shape enters Draw mode with it.
|
||||
var dsp := _split("Draw mode (5)\nSketch shapes in any viewport - current shape: Rectangle",
|
||||
"Choose a shape to draw")
|
||||
_draw_main = dsp[1]
|
||||
_draw_arrow = dsp[2]
|
||||
_draw_main.pressed.connect(func(): mode_requested.emit(PdDocument.Mode.DRAW))
|
||||
_mode_buttons[PdDocument.Mode.DRAW] = _draw_main
|
||||
_draw_popup = PopupMenu.new()
|
||||
_draw_popup.add_theme_font_size_override("font_size", 12)
|
||||
# match every other icon in the UI (16px) - PopupMenu draws item
|
||||
# icons at native texture size unless capped, and our source PNGs
|
||||
# are 32px, so without this the shape list looked twice as big as
|
||||
# the toolbar buttons that open it.
|
||||
_draw_popup.add_theme_constant_override("icon_max_width", 16)
|
||||
for i in PdDocument.DRAW_KINDS.size():
|
||||
_draw_popup.add_radio_check_item(PdDocument.DRAW_KINDS[i], i)
|
||||
_draw_popup.set_item_icon(i, _icon(DRAW_ICONS.get(
|
||||
PdDocument.DRAW_KINDS[i], "tool_rect")))
|
||||
_draw_popup.id_pressed.connect(func(id: int):
|
||||
draw_kind.emit(PdDocument.DRAW_KINDS[id])
|
||||
mode_requested.emit(PdDocument.Mode.DRAW))
|
||||
_draw_arrow.pressed.connect(func(): _open_popup(_draw_popup, _draw_arrow))
|
||||
_model_box.add_child(dsp[0])
|
||||
_model_box.add_child(_draw_popup)
|
||||
|
||||
_model_box.add_child(_gap(4))
|
||||
_model_box.add_child(_sep())
|
||||
|
||||
# --- view toggles. The gizmo controls are a SIDE-BY-SIDE pair:
|
||||
# [Move] [Scale]. The active kind is pressed while the gizmo is
|
||||
# on; clicking the pressed half again hides the gizmo.
|
||||
_btn_gizmo_move = _toggle("gizmo_move", "Move Gizmo (G)\nShow the 3-axis move arrows on the selection.\nClick again to hide the gizmo. G/S/R pick Move/Scale/Rotate.\nDirect dragging always works too.")
|
||||
_btn_gizmo_move.pressed.connect(func(): _gizmo_pair(0))
|
||||
_model_box.add_child(_btn_gizmo_move)
|
||||
_btn_gizmo_scale = _toggle("gizmo_scale", "Scale Gizmo (S)\nShow the scale handles on the selection: axis cubes scale one axis,\nthe center cube scales uniformly.\nClick again to hide the gizmo.")
|
||||
_btn_gizmo_scale.pressed.connect(func(): _gizmo_pair(1))
|
||||
_model_box.add_child(_btn_gizmo_scale)
|
||||
_btn_gizmo_rotate = _toggle("gizmo_rotate", "Rotate Gizmo (R)\nShow the rotation rings on the selection: drag a ring to rotate\naround that axis. In the 2D views this is a single ring around the\nview's own axis.\nClick again to hide the gizmo.")
|
||||
_btn_gizmo_rotate.pressed.connect(func(): _gizmo_pair(2))
|
||||
_model_box.add_child(_btn_gizmo_rotate)
|
||||
_btn_snap = _toggle("snap", "Grid snapping (T)\nMoves and shapes land on the grid.\nWorks even when the grid is hidden.")
|
||||
_btn_snap.pressed.connect(func(): toggle_snap.emit(_btn_snap.button_pressed))
|
||||
_model_box.add_child(_btn_snap)
|
||||
_btn_grid = _toggle("grid", "Grid visibility (V)\nHide the grid but keep snapping.")
|
||||
_btn_grid.pressed.connect(func(): toggle_grid.emit(_btn_grid.button_pressed))
|
||||
_model_box.add_child(_btn_grid)
|
||||
_btn_sides = _toggle("doubleside", "Render both sides (B)\nShow backfaces - no culling. On by default.")
|
||||
_btn_sides.pressed.connect(func(): toggle_both_sides.emit(_btn_sides.button_pressed))
|
||||
_model_box.add_child(_btn_sides)
|
||||
_model_box.add_child(_sep())
|
||||
|
||||
# --- edit ---
|
||||
var dup := _button("duplicate", "Duplicate selected object (Ctrl+D)")
|
||||
dup.pressed.connect(func(): duplicate_requested.emit())
|
||||
_model_box.add_child(dup)
|
||||
var del := _button("delete", "Delete selection (Del)")
|
||||
# destructive action = red icon
|
||||
del.add_theme_color_override("icon_normal_color",
|
||||
Color(0.94, 0.44, 0.44, 0.9))
|
||||
del.add_theme_color_override("icon_hover_color", Color(1, 0.52, 0.52))
|
||||
del.pressed.connect(func(): delete_requested.emit())
|
||||
_model_box.add_child(del)
|
||||
|
||||
# ================================================ TEXTURE group ==
|
||||
# Replaces the modeling buttons while the texture editor is
|
||||
# active: the [Paint | Edit UV] submode buttons followed by the
|
||||
# contextual toolset of the active submode. Sizes and colors live
|
||||
# in the right panel.
|
||||
_tex_box = HBoxContainer.new()
|
||||
_tex_box.add_theme_constant_override("separation", 3)
|
||||
_tex_box.visible = false
|
||||
add_child(_tex_box)
|
||||
|
||||
var tgrp := ButtonGroup.new()
|
||||
# own icon (mode_paint), distinct from tool_brush - the submode
|
||||
# button and the individual Brush TOOL button below must not read
|
||||
# as the same control
|
||||
_tex_paint = _toggle("mode_paint",
|
||||
"Paint\nBrush, fill and pixel tools paint the texture directly", tgrp)
|
||||
_tex_paint.pressed.connect(func(): tex_submode.emit(false))
|
||||
_tex_edituv = _toggle("tool_uv",
|
||||
"Edit UV\nDrag island corners, edges or whole islands to re-map UVs.\nClick a face in the 3D view to select it - its island highlights here.\nRight-click: detach / merge / extrude / fill / delete menu", tgrp)
|
||||
_tex_edituv.pressed.connect(func(): tex_submode.emit(true))
|
||||
_tex_box.add_child(_tex_paint)
|
||||
_tex_box.add_child(_tex_edituv)
|
||||
_tex_box.add_child(_sep())
|
||||
|
||||
# ---- PAINT submode tools (visible only in Paint submode)
|
||||
var pgrp := ButtonGroup.new()
|
||||
var tools := [["Brush", "tool_brush", "Brush - paint smooth round strokes"],
|
||||
["Fill", "tool_fill", "Fill - repaint exactly one face's texture island"],
|
||||
["Fill Object", "tool_fillobject", "Fill Object - repaint the whole object's texture"],
|
||||
["Pixel", "tool_pixel", "Pixel - texel-perfect pixel-art brush"],
|
||||
["Eraser", "tool_eraser", "Eraser - restore blank with brush strokes (works on the model and the canvas)"],
|
||||
["Picker", "tool_picker", "Color Picker - click the model or the canvas to make that texel's color the paint color"],
|
||||
["Replace", "tool_replace", "Replace Color - click a texel: its color is swapped for the paint color across the WHOLE canvas (all faces); the Tolerance slider in the right panel widens the color match"]]
|
||||
_tex_paint_box = HBoxContainer.new()
|
||||
_tex_paint_box.add_theme_constant_override("separation", 3)
|
||||
_tex_box.add_child(_tex_paint_box)
|
||||
for t in tools:
|
||||
var b := _toggle(t[1], t[2], pgrp)
|
||||
b.pressed.connect(func(): paint_tool_requested.emit(t[0]))
|
||||
_tex_tool_btns[t[0]] = b
|
||||
_tex_paint_box.add_child(b)
|
||||
var imp := _button("image",
|
||||
"Import Image\nPlace a picture onto the texture: move it, wheel-scales,\nclick places it - then paint over it or erase it")
|
||||
imp.pressed.connect(func(): import_requested.emit())
|
||||
_tex_paint_box.add_child(imp)
|
||||
|
||||
# ---- EDIT UV submode tools (visible only in Edit UV submode)
|
||||
_tex_uv_box = HBoxContainer.new()
|
||||
_tex_uv_box.add_theme_constant_override("separation", 3)
|
||||
_tex_uv_box.visible = false
|
||||
_tex_box.add_child(_tex_uv_box)
|
||||
_tex_uv_snap = _toggle("snap", "UV snapping (texel grid)\nUV drags land on whole texels. Hold Ctrl to drag freely.")
|
||||
_tex_uv_snap.pressed.connect(func(): uv_snap_requested.emit(_tex_uv_snap.button_pressed))
|
||||
var det := _button("detach",
|
||||
"Detach selected face(s)\nMove the selected islands to free texture space so they can\nbe moved individually. Select faces, then press.")
|
||||
det.pressed.connect(func(): detach_requested.emit())
|
||||
var ruv := _button("uv_reset", "Reset UVs\nRe-unwrap every face of the object to its planar projection")
|
||||
ruv.pressed.connect(func(): reset_uvs_requested.emit())
|
||||
# Rotate / Scale: a mutually exclusive toggle pair (the active one
|
||||
# can be clicked again to switch off). The rotate tool shows the
|
||||
# 0..360 angle slider in the right panel; the scale tool turns
|
||||
# every corner drag of the selection into a uniform scale and shows
|
||||
# the percent slider. Quick 90-degree actions stay available via
|
||||
# R / Shift+R and the canvas right-click menu.
|
||||
_uv_tool_group = ButtonGroup.new()
|
||||
_uv_tool_group.allow_unpress = true
|
||||
_tex_uv_rotate = _toggle("rotate",
|
||||
"Rotate UVs\nToggle the rotate tool: an Angle slider (0-360\ndegrees, or type a number) appears in the right panel and\nrotates the selected faces' texture islands around their center.\nR / Shift+R rotate 90 degrees quickly.",
|
||||
_uv_tool_group)
|
||||
_tex_uv_rotate.pressed.connect(func():
|
||||
uv_tool_requested.emit(
|
||||
"rotate" if _tex_uv_rotate.button_pressed else "none"))
|
||||
_tex_uv_scale = _toggle("gizmo_scale",
|
||||
"Scale UVs\nToggle the scale tool: drag any corner of the selected\nisland(s) to scale them uniformly (aspect ratio preserved).\nA Scale slider (10-400%) also appears in the right panel.",
|
||||
_uv_tool_group)
|
||||
_tex_uv_scale.pressed.connect(func():
|
||||
uv_tool_requested.emit(
|
||||
"scale" if _tex_uv_scale.button_pressed else "none"))
|
||||
_tex_uv_box.add_child(_tex_uv_snap)
|
||||
_tex_uv_box.add_child(_tex_uv_rotate)
|
||||
_tex_uv_box.add_child(_tex_uv_scale)
|
||||
_tex_uv_box.add_child(det)
|
||||
_tex_uv_box.add_child(ruv)
|
||||
|
||||
add_child(_sep())
|
||||
|
||||
# --- history ---
|
||||
_btn_undo = _button("undo", "Undo (Ctrl+Z)")
|
||||
_btn_undo.pressed.connect(func(): undo_requested.emit())
|
||||
add_child(_btn_undo)
|
||||
_btn_redo = _button("redo", "Redo (Ctrl+Shift+Z)")
|
||||
_btn_redo.pressed.connect(func(): redo_requested.emit())
|
||||
add_child(_btn_redo)
|
||||
add_child(_sep())
|
||||
|
||||
# --- file ---
|
||||
var save := _button("save", "Save project as .pdoodle")
|
||||
save.pressed.connect(func(): save_requested.emit())
|
||||
add_child(save)
|
||||
var open := _button("open", "Open a .pdoodle project")
|
||||
open.pressed.connect(func(): load_requested.emit())
|
||||
add_child(open)
|
||||
var import_model := _button("import_model",
|
||||
"Import a 3D model (OBJ, glTF, FBX) with its textures")
|
||||
import_model.pressed.connect(func(): import_model_requested.emit())
|
||||
add_child(import_model)
|
||||
|
||||
var export := _menu("export", "Export for use directly in Godot")
|
||||
var em := export.get_popup()
|
||||
em.add_theme_font_size_override("font_size", 12)
|
||||
em.add_item("Mesh (.tres)", 0)
|
||||
em.add_item("Scene (.tscn)", 1)
|
||||
em.add_item("OBJ (.obj + texture)", 2)
|
||||
em.add_item("Add to current scene", 3)
|
||||
em.id_pressed.connect(func(id: int):
|
||||
export_requested.emit(["tres", "tscn", "obj", "scene"][id]))
|
||||
add_child(export)
|
||||
|
||||
var spacer := Control.new()
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
add_child(spacer)
|
||||
|
||||
_bg_pick = ColorPickerButton.new()
|
||||
_bg_pick.custom_minimum_size = Vector2(34, 24)
|
||||
_bg_pick.focus_mode = Control.FOCUS_NONE
|
||||
_bg_pick.color = doc.bg_color
|
||||
_bg_pick.tooltip_text = "Background color"
|
||||
_bg_pick.color_changed.connect(func(c: Color): bg_changed.emit(c))
|
||||
add_child(_bg_pick)
|
||||
|
||||
# --- editor settings (gear): shading mode buttons, grid toggle ---
|
||||
_btn_settings = _button("gear", "Editor settings\n3D shading mode, grid and contextual hints")
|
||||
_btn_settings.pressed.connect(_open_settings)
|
||||
add_child(_btn_settings)
|
||||
_build_settings_popup()
|
||||
|
||||
# --- documentation (book): every button, tool and feature explained
|
||||
_btn_docs = _button("docs", "Documentation\nEvery button, tool and feature of the plugin, with how-tos\nand use cases")
|
||||
_btn_docs.pressed.connect(_open_docs)
|
||||
add_child(_btn_docs)
|
||||
|
||||
sync_from_doc()
|
||||
|
||||
|
||||
func _menu(icon: String, tip: String) -> MenuButton:
|
||||
var m := MenuButton.new()
|
||||
m.icon = _icon(icon)
|
||||
m.text = ""
|
||||
m.focus_mode = Control.FOCUS_NONE
|
||||
m.tooltip_text = tip
|
||||
m.add_theme_constant_override("icon_max_width", 16)
|
||||
m.flat = false
|
||||
_style(m)
|
||||
return m
|
||||
|
||||
|
||||
# -------------------------------------------------------- settings UI ---
|
||||
## Editor settings: tactile BUTTONS (pressed = active, one button in a
|
||||
## group is always pressed) instead of on/off switches - a shading mode
|
||||
## is a choice, not a switch, and a pressed button clearly shows state.
|
||||
func _build_settings_popup() -> void:
|
||||
_settings_popup = PopupPanel.new()
|
||||
var v := VBoxContainer.new()
|
||||
v.add_theme_constant_override("separation", 8)
|
||||
v.custom_minimum_size = Vector2(252, 0)
|
||||
_settings_popup.add_child(v)
|
||||
|
||||
var head := Label.new()
|
||||
head.text = "Editor Settings"
|
||||
head.add_theme_font_size_override("font_size", 14)
|
||||
v.add_child(head)
|
||||
|
||||
var sh := Label.new()
|
||||
sh.text = "3D shading"
|
||||
sh.add_theme_font_size_override("font_size", 11)
|
||||
sh.modulate = Color(1, 1, 1, 0.6)
|
||||
v.add_child(sh)
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 4)
|
||||
v.add_child(row)
|
||||
var grp := ButtonGroup.new()
|
||||
var modes := [[0, "Shaded + Wire", "Solid model with an x-ray wireframe overlay"],
|
||||
[1, "Shaded", "Solid model only - no wireframe"],
|
||||
[2, "Wireframe", "Wireframe only - no solid surfaces"]]
|
||||
for md in modes:
|
||||
var b := Button.new()
|
||||
b.text = md[1]
|
||||
b.toggle_mode = true
|
||||
b.button_group = grp
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.tooltip_text = md[2]
|
||||
b.add_theme_font_size_override("font_size", 12)
|
||||
b.custom_minimum_size = Vector2(0, 26)
|
||||
_style_tactile(b)
|
||||
var want: int = md[0]
|
||||
b.pressed.connect(func():
|
||||
doc.set_view_shading(want)
|
||||
_sync_settings())
|
||||
_shade_btns.append([b, want])
|
||||
row.add_child(b)
|
||||
|
||||
var gh := Label.new()
|
||||
gh.text = "Viewport"
|
||||
gh.add_theme_font_size_override("font_size", 11)
|
||||
gh.modulate = Color(1, 1, 1, 0.6)
|
||||
v.add_child(gh)
|
||||
_grid_btn = Button.new()
|
||||
_grid_btn.text = "Show Grid"
|
||||
_grid_btn.toggle_mode = true
|
||||
_grid_btn.focus_mode = Control.FOCUS_NONE
|
||||
_grid_btn.tooltip_text = "Show or hide the grid (V)\nSnapping keeps working while the grid is hidden"
|
||||
_grid_btn.add_theme_font_size_override("font_size", 12)
|
||||
_grid_btn.custom_minimum_size = Vector2(0, 26)
|
||||
_style_tactile(_grid_btn)
|
||||
_grid_btn.pressed.connect(func():
|
||||
doc.set_grid_visible(_grid_btn.button_pressed)
|
||||
_sync_settings())
|
||||
v.add_child(_grid_btn)
|
||||
_hints_btn = Button.new()
|
||||
_hints_btn.text = "Contextual Hints"
|
||||
_hints_btn.toggle_mode = true
|
||||
_hints_btn.focus_mode = Control.FOCUS_NONE
|
||||
_hints_btn.tooltip_text = "Show or hide the in-viewport tip lines\n(the small help text at the bottom of each view)"
|
||||
_hints_btn.add_theme_font_size_override("font_size", 12)
|
||||
_hints_btn.custom_minimum_size = Vector2(0, 26)
|
||||
_style_tactile(_hints_btn)
|
||||
_hints_btn.pressed.connect(func():
|
||||
doc.set_hints(_hints_btn.button_pressed)
|
||||
_sync_settings())
|
||||
v.add_child(_hints_btn)
|
||||
|
||||
var ch := Label.new()
|
||||
ch.text = "Checkerboard"
|
||||
ch.add_theme_font_size_override("font_size", 11)
|
||||
ch.modulate = Color(1, 1, 1, 0.6)
|
||||
v.add_child(ch)
|
||||
_checker_btn = Button.new()
|
||||
_checker_btn.text = "Show Checkerboard"
|
||||
_checker_btn.toggle_mode = true
|
||||
_checker_btn.focus_mode = Control.FOCUS_NONE
|
||||
_checker_btn.tooltip_text = "Show or hide the checkerboard under unpainted texels\n\nON: unpainted areas show the checker placeholder (the classic look).\nOFF: unpainted areas are FULLY TRANSPARENT in every view - and they\nexport transparent (alpha 0), so the model gets real holes there."
|
||||
_checker_btn.add_theme_font_size_override("font_size", 12)
|
||||
_checker_btn.custom_minimum_size = Vector2(0, 26)
|
||||
_style_tactile(_checker_btn)
|
||||
_checker_btn.pressed.connect(func():
|
||||
doc.set_show_checker(_checker_btn.button_pressed)
|
||||
_sync_settings())
|
||||
v.add_child(_checker_btn)
|
||||
_bake_btn = Button.new()
|
||||
_bake_btn.text = "Bake Into Export"
|
||||
_bake_btn.toggle_mode = true
|
||||
_bake_btn.focus_mode = Control.FOCUS_NONE
|
||||
_bake_btn.tooltip_text = "Bake the checkerboard into every exported texture\n\nON: exported textures (mesh, scene, OBJ PNGs) carry the checker -\nnothing is transparent where nothing was painted.\nOFF: the export follows the Show Checkerboard switch - hidden checker\nexports transparent, visible checker exports baked.\nRender Both Sides always applies to the exported material."
|
||||
_bake_btn.add_theme_font_size_override("font_size", 12)
|
||||
_bake_btn.custom_minimum_size = Vector2(0, 26)
|
||||
_style_tactile(_bake_btn)
|
||||
_bake_btn.pressed.connect(func():
|
||||
doc.set_export_checker(_bake_btn.button_pressed)
|
||||
_sync_settings())
|
||||
v.add_child(_bake_btn)
|
||||
|
||||
add_child(_settings_popup)
|
||||
|
||||
|
||||
func _open_settings() -> void:
|
||||
_sync_settings()
|
||||
_settings_popup.reset_size()
|
||||
_place_settings_popup()
|
||||
_settings_popup.popup()
|
||||
# embedded popups can be re-fitted by the windowing system on
|
||||
# show: re-place once the REAL size is known
|
||||
_place_settings_popup.call_deferred()
|
||||
|
||||
|
||||
## Position the settings popup on the RIGHT side, right-aligned under the
|
||||
## gear, clamped INSIDE the plugin tab area so it can never spill over
|
||||
## the editor docks. Falls back to the editor base-control rect when the
|
||||
## main screen reports a degenerate (headless / not-yet-laid-out) rect.
|
||||
func _place_settings_popup() -> void:
|
||||
if _settings_popup == null or not is_instance_valid(_settings_popup):
|
||||
return
|
||||
var gear := _btn_settings.get_global_rect()
|
||||
var ps := Vector2(_settings_popup.size)
|
||||
if ps.x <= 1.0 or ps.y <= 1.0:
|
||||
ps = _settings_popup.get_contents_minimum_size() \
|
||||
+ Vector2(8, 8)
|
||||
var main := EditorInterface.get_editor_main_screen().get_global_rect()
|
||||
if main.size.x < 50.0 or main.size.y < 50.0:
|
||||
main = EditorInterface.get_base_control().get_global_rect()
|
||||
var margin := 4.0
|
||||
var pos := Vector2(gear.end.x - ps.x, gear.end.y + 2.0)
|
||||
pos.x = clampf(pos.x, main.position.x + margin,
|
||||
maxf(main.position.x + margin, main.end.x - ps.x - margin))
|
||||
pos.y = clampf(pos.y, main.position.y + margin,
|
||||
maxf(main.position.y + margin, main.end.y - ps.y - margin))
|
||||
_settings_popup.position = Vector2i(int(pos.x), int(pos.y))
|
||||
|
||||
|
||||
func _sync_settings() -> void:
|
||||
if _settings_popup == null:
|
||||
return
|
||||
for pair in _shade_btns:
|
||||
var b: Button = pair[0]
|
||||
b.set_pressed_no_signal(doc.view_shading == int(pair[1]))
|
||||
_grid_btn.set_pressed_no_signal(doc.grid_visible)
|
||||
if _hints_btn != null:
|
||||
_hints_btn.set_pressed_no_signal(doc.hints_enabled)
|
||||
if _checker_btn != null:
|
||||
_checker_btn.set_pressed_no_signal(doc.show_checker)
|
||||
if _bake_btn != null:
|
||||
_bake_btn.set_pressed_no_signal(doc.export_checker)
|
||||
|
||||
|
||||
# --------------------------------------------------------- gizmo pair ---
|
||||
## One of the three gizmo buttons was pressed: select that kind and show
|
||||
## the gizmo, or hide the gizmo when the active kind is clicked again.
|
||||
func _gizmo_pair(kind: int) -> void:
|
||||
if doc.gizmo_on and doc.gizmo_kind == kind:
|
||||
doc.set_gizmo(false)
|
||||
toggle_gizmo.emit(false)
|
||||
else:
|
||||
doc.set_gizmo(true)
|
||||
toggle_gizmo.emit(true)
|
||||
if doc.gizmo_kind != kind:
|
||||
gizmo_kind_requested.emit(kind)
|
||||
doc.set_gizmo_kind(kind)
|
||||
sync_from_doc()
|
||||
|
||||
|
||||
# -------------------------------------------------------------- docs ---
|
||||
## Open (or raise) the documentation window next to the settings gear.
|
||||
## The Window must be parented into the editor's base control or it will
|
||||
## never be shown.
|
||||
func _open_docs() -> void:
|
||||
if _docs_win != null and is_instance_valid(_docs_win):
|
||||
_docs_win.show()
|
||||
_docs_win.move_to_foreground()
|
||||
else:
|
||||
_docs_win = PdDocs.open(null)
|
||||
EditorInterface.get_base_control().add_child(_docs_win)
|
||||
# CENTER the window on the editor: an unpositioned editor
|
||||
# Window opens in the top-left corner. Computed from the
|
||||
# base control's rect (popup_centered mis-centers when the
|
||||
# host screen reports a degenerate size) and clamped so a
|
||||
# degenerate rect can never push it off-screen.
|
||||
var bc := EditorInterface.get_base_control()
|
||||
var br := bc.get_global_rect()
|
||||
var cp := br.position + ((br.size - Vector2(_docs_win.size))
|
||||
* 0.5).floor()
|
||||
_docs_win.position = Vector2i(
|
||||
maxi(0, int(cp.x)), maxi(0, int(cp.y)))
|
||||
|
||||
|
||||
func sync_from_doc() -> void:
|
||||
if doc == null:
|
||||
return
|
||||
# workspace switch: exactly one half active, and the contextual
|
||||
# group swaps in place - texture tools REPLACE the modeling tools
|
||||
var tex := doc.mode == PdDocument.Mode.TEXTURE
|
||||
_ws_3d.button_pressed = not tex
|
||||
_ws_tex.button_pressed = tex
|
||||
if _model_box != null:
|
||||
_model_box.visible = not tex
|
||||
if _tex_box != null:
|
||||
_tex_box.visible = tex
|
||||
for m in _mode_buttons:
|
||||
_mode_buttons[m].button_pressed = m == doc.mode
|
||||
# side-by-side gizmo pair mirrors on/off AND the active kind
|
||||
_btn_gizmo_move.set_pressed_no_signal(doc.gizmo_on and doc.gizmo_kind == 0)
|
||||
_btn_gizmo_scale.set_pressed_no_signal(doc.gizmo_on and doc.gizmo_kind == 1)
|
||||
_btn_gizmo_rotate.set_pressed_no_signal(doc.gizmo_on and doc.gizmo_kind == 2)
|
||||
_btn_snap.button_pressed = doc.snap_enabled
|
||||
_btn_grid.button_pressed = doc.grid_visible
|
||||
_btn_sides.button_pressed = doc.both_sides
|
||||
# draw split button: main icon always mirrors the active shape
|
||||
_draw_main.icon = _icon(DRAW_ICONS.get(doc.draw_kind, "tool_rect"))
|
||||
_draw_main.tooltip_text = "Draw mode (5)\nSketch shapes in any viewport - current shape: %s" % doc.draw_kind
|
||||
for i in PdDocument.DRAW_KINDS.size():
|
||||
_draw_popup.set_item_checked(i, PdDocument.DRAW_KINDS[i] == doc.draw_kind)
|
||||
# texture group state (contextual: paint tools OR uv tools)
|
||||
_tex_paint.set_pressed_no_signal(not doc.tex_edit)
|
||||
_tex_edituv.set_pressed_no_signal(doc.tex_edit)
|
||||
if _tex_paint_box != null:
|
||||
_tex_paint_box.visible = not doc.tex_edit
|
||||
if _tex_uv_box != null:
|
||||
_tex_uv_box.visible = doc.tex_edit
|
||||
for t in _tex_tool_btns:
|
||||
_tex_tool_btns[t].set_pressed_no_signal(t == doc.paint_tool)
|
||||
_tex_uv_snap.set_pressed_no_signal(doc.uv_snap)
|
||||
if _tex_uv_rotate != null:
|
||||
_tex_uv_rotate.set_pressed_no_signal(doc.uv_tool == "rotate")
|
||||
if _tex_uv_scale != null:
|
||||
_tex_uv_scale.set_pressed_no_signal(doc.uv_tool == "scale")
|
||||
_btn_undo.disabled = not doc.undo.has_undo()
|
||||
_btn_redo.disabled = not doc.undo.has_redo()
|
||||
if _bg_pick:
|
||||
_bg_pick.set_deferred("color", doc.bg_color)
|
||||
|
||||
|
||||
func set_bg_silent(c: Color) -> void:
|
||||
if _bg_pick:
|
||||
_bg_pick.set_deferred("color", c)
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
uid://umnlo32jihmq
|
||||
Executable
+1338
File diff suppressed because it is too large
Load Diff
Executable
+1
@@ -0,0 +1 @@
|
||||
uid://c2uvcanvas7r4d1
|
||||
Executable
+1666
File diff suppressed because it is too large
Load Diff
Executable
+1
@@ -0,0 +1 @@
|
||||
uid://buqp3y4nf5nc2
|
||||
Executable
+2261
File diff suppressed because it is too large
Load Diff
Executable
+1
@@ -0,0 +1 @@
|
||||
uid://cex0nabkdfiek
|
||||
Reference in New Issue
Block a user