[Addon] LDK_DrawBox Beta v0.1

I made this addon to speed up my level prototyping phase. It allows the user to quickly create new geo, all snapped to a world space grid. I’m certain there are bugs and it might crash Blender, so save early and often when using this. The script is a bit of a mess. I’ll clean it up as I get feedback and add new features to it.

In Object mode it always creates a new object, and in Edit mode it adds the new geometry to the active object. If the face normal is World Axis aligned (or no face was found), the grid will be BLUE, otherwise it will be GREEN. When the closest edge length is used for grid size, the grid will be RED. Doesn’t currently play nice with a mesh that doesn’t have rotation and scale applied.

The settings for the addon can be found in the T-Panel (in Object or Edit mode) under “LDK_DrawBox”.

If your existing geometry isn’t snapped to a world space grid, you might want to enable the “Force to face” checkbox in the settings panel. If you don’t the grid will be always slightly off.

SHORTCUTS:

D - Activate addon. Creates a grid on the closest face under the mouse. If no face is found, it creates the grid on the 3d cursor location (snapped to world space).

While the addon is active:
D - Create the grid on the face under the mouse. If face normal has a different axis than before, drawn boxes are erased. If the face normal is not World Axis aligned, works the same as ‘F’.
F - Force the grid on the face under the mouse, and use the closest edge as the grid basis (you can check the “Force to face” in the T-Panel to make this the default behaviour when pressing ‘D’).
F (TWICE) - Same as before, but uses the closest edge length as the grid size. Pressing F again after this will revert the grid back.

LMB - Two click method for creating a box. You can pan and move around with this method.
LMB (HOLD) - Drag and release method for creating a box
ALT + LMB - Create the first vertext of an ngon. Subsequent LMB (without ALT) clicks then add vertices to the ngon.
SHIFT (HOLD) - Activate the 0.1 step grid (works with all of the above)
C - Delete the last box, or ngon vertex.
S - Snap to grid On/Off (also in T-Panel)

CTRL + LMB + DRAG MOUSE LEFT OR RIGHT - Adjust the extrude amount (+ SHIFT to adjust by 0.1)
E - Flip the extrude direction
0 - Set extrude amount to 0

CTRL + MOUSE WHEEL - Move the grid along its normal (+ SHIFT to move by 0.1)
PAGE UP, PAGE DOWN - Move the grid along its normal (+ SHIFT to move by 0.1)
X, Y, Z - Change the grid axis

    • Increase grid size
    • Decrease grid size

SPACE - Finish
ESC - Cancel

If you find any bugs, please report them here with the repro steps and the error message from the console. If you have any feature requests, don’t be afraid to ask.

Attachments

ldk_drawbox.zip (8.79 KB)

Wow, really nice addon! Thanks for sharing

Great visual side to this addon. Works like in the video.

Issue:
-It seems to align to hidden objects as well.

Issue:
-It seems to align to hidden objects as well.

Duh! Totally forgot about hidden objects. Will fix, thanks for the heads up.

Awesome addon! :wink: Keep work to finish Beta!

Great tool stry! I waited since you posted first topic and this fulfilled my expectations. :slight_smile: Few suggestions below.

  1. I think setting drawing scale factor in toolbar panel will bring this thing to another level. It is worth to allow user to specify scale by setting desired decimal precision. By default we operate on 1 unit width grid that can be divided (by holding Shift) to 0.1 unit width squares. Imagine if we set scale factor to level 2 and then operate on 0.1 unit width grid that can be divided to 0.01 width squares. I Hope I explain this well.

  2. In terms of decimal precision. Extrude slider is to precise, clicking on arrows sets values with second decimal number (eg 0.24). This makes no sense with all this world grid thing. This slider have to jump only on tenths values.

  3. Cursor snapping have strange behavior. It snaps to whole integers on X and Y axes and value with one decimal number (eg. 3.2) on Z axis.

  4. Slicing geometry by grid when confirm editing. This can be fun optional feature to have. Think about scale factor! Handy for games with tillable texture sets, baking light to vertex colors and more.

  1. Imho before drawing you need to test if mouse cursor is in viewport. I placed many unwanted boxes trying to change some options (extrude value to be specific).

  2. I got concern about ngon option hotkey. In blender when third mouse button emulation is enabled ALT+LMB behave like MMB. People with that setup cannot create ngons, this combination is only for rotating view. :frowning: Maybe change it to A key + LMB, its close to original hotkey.

  3. Grid size slider can be set to infinite or negative values. I think limiting slider range from 0 to 100 fill be enough. Just be sure to allow keyborad input if somebody wants huge grids.

  4. Sometimes it f**k up line drawing of blender interface. Almost all lines are 2 pixels thick. :frowning:

  5. What exactly “Grid at Cursor” option is for? For me it just ignore face normal and set grid to Z axis.

  6. I tried snap to subsurfed cube and it snaps only to original data geometry, not to actual faces.

  7. Consider allowing for view numpad keys. They are handy in designing levels. :slight_smile:

  8. Some people may don’t want to change cursor position after drawing boxes. Will be great to store cursor placement before all the snapping and editing and then set it again to original position. On the other hand this snapping can be useful so this storing function need checkbox in toolbar panel. :wink:

  9. Do you have paypal? :slight_smile:

wow nice addons

Monio, Great feedback, thanks!

  1. I’ve been meaning to do Cell Size setting for the T-Panel, where you can specify the grid cell size in blender units.

  2. Will fix.

  3. Yeah, this might seem like a strange thing to do, but I wanted it to work like, if I drew a 1x1 box on the grid, that it would always match the grid if you picked the same surface, but on a different spot. Might not be necessary, going to think it over.

  4. Neat idea. Will see what I can do :slight_smile:

  5. Even I do this sometimes. Will fix.

  6. Will change the shortcut.

  7. Will fix.

  8. Something went wrong with the script! If this happens, open the Window-> Toggle System Console, and grab the first Error Message with its line number. There’s probably always going to be multiple error messages, but I just need the very first one (reading from up to down). You might have to scroll up a bit to find the first one. Also, it’ll help if you can tell me what you were doing at the time this happened.

  9. Doesn’t work yet, sorry.

  10. Will look into this.

  11. Good catch. Will fix.

  12. Agreed. Will do.

Hi stry, Great Thanks for your very good tool.
For the french people, I have translated your explanations:

J’ai fait cet addon pour accélérer ma phase de prototypage d’étage. Il permet à l’ utilisateur de créer rapidement de nouvelles geométries, orientées sur le repère du monde . Je suis certain qu’il y a des bugs et qu’il pourrait faire crasher Blender , donc enregistrez souvent en l’utilisant. Le script est un peu en désordre . Je vais le nettoyer quans je reçevrais des commentaires et ajouterais de nouvelles fonctionnalités.

En mode “objet”, il crée toujours un nouvel objet, et en mode “Edit” , il ajoute la nouvelle géométrie à l’objet actif.

Si les normales de la face sont alignées aux axes du Monde (ou aucune face n’a été trouvée ) , la grille sera bleu , sinon elle sera vert .

Lorsque la longueur de la bordure la plus rapprochée est utilisé pour la taille de la grille , la grille sera rouge . Ne fonctionne pas actuellement avec un maillage sur lequel on n’aurait pas initialisé la rotation et l’échelle (faites ctrl + A pour appliquer l’orientation et l’echelle).

Les paramètres de l’addon peuvent être trouvés dans le panneau Tools sous la rubrique “LDK_DrawBox”( en mode “objet” ou “Edit”) .
Si votre géométrie existante n’est pas orientée sur le repère du monde, vous pouvez activer la case à cocher “Force to face” dans le panneau de configuration . Si ca ne marche pas, la grille restera toujours grisée.

RACCOURCIS CLAVIER:

D - Active l’addon. Crée une grille sur la face la plus proche sous la souris. Si aucune face n’est détectée, il crée la grille sur la position du curseur 3D (orienté sur le repère du monde).

Lorsque l’addon est actif:
D - Crée la grille sur la face sous la souris. Si la normale de la face a un axe différent qu’avant, la boite dessinée est effacée. Si la normale de la face n’est pas alignée sur l’Axe du Monde, fonctionne comme ‘F’.

F - Force la grille sur la face sous la souris et utilise la bordure la plus rapprochée pour la base de la grille (vous pouvez cocher la case “Force to face” dans le panneau Tool pour faire de ce comportement par défaut lorsque vous appuyez ‘D’).
F (double fois) - Même qu’avant, mais utilise la longueur de la bordure la plus rapprochée pour la taille de la grille. En appuyant de nouveau sur F après, reviendra à la grille d’avant.

LMB - Methode des deux clics pour créer une boite. Vous pouvez vous déplacer autour de l’objet avec cette methode.
LMB (Tenu) - Methode du cliquer-glisser-lacher pour créer une boite
ALT + LMB - Crée le premier point d’un ngon. Ensuite les clics LMB (sans ALT) ajoutent les autres points au ngon.
SHIFT (Tenu) - Active le pas de la grille à 0.1 (fonctionne avec tout ce qui se trouve avant)
C - Efface la dernière boite, ou point d’un ngon.
S - Active ou desactive le magnétisme de la grille (aussi dans le panneau Tools)

CTRL + LMB + GLISSER de droite ou gauche la souris - Adjuste la taille d’extrusion (+ SHIFT pour ajuster plus précisément de 0.1)
E - Inverse la direction d’extrusion.
0 - Règle l’extrusion à 0

CTRL + ROULETTE DE LA SOURIS - Déplace la grille le long de sa normale (+ SHIFT pour déplacer plus précisément de 0.1)
PAGE UP, PAGE DOWN - Déplace la grille le long de sa normale (+ SHIFT pour déplacer plus précisément de 0.1)
X, Y, Z -> Change les axes de la grille

  • Augmente la taille de la grille.
  • Diminue la taille de la grille.

SPACE - Fin
ESC - Annuler

I encountered this line bug but now I can reproduce it. This occur when I press D having cursor on object that have Boolean Modifier or many other modifiers. Also this objects can be on hiden Layers.
Console output for you. I changed File locations strings to “\” for clarity. They normally work fine.

Traceback (most recent call last):
  File "\\\ldk_drawbox.py", line 1173, in invoke
    SetGridPosition(self, context, event, self.force_to_face)
  File "\\\ldk_drawbox.py", line 785, in SetGridPosition
    normal, face_index, obj = GetClosestFace(self, context, event, force_fn)
  File "\\\ldk_drawbox.py", line 755, in GetClosestFace
    hit, n, fi = obj.ray_cast(matrix.inverted() * ray_origin, matrix.inverted()
* ray_target)
RuntimeError: Error: Object 'Base01.002' has no mesh data to be used for ray casting

Then after error prompt when we move view lines get thicker. This set of tracebacks repeat all over to while moving view. This effect stay even if I load another blend file. Only restarting application helps.

Traceback (most recent call last):
  File "\\\ldk_drawbox.py", line 459, in Draw_WorldSpace
    DrawGrid(self, context)
  File "\\\ldk_drawbox.py", line 71, in DrawGrid
    lift = GetLift(self)
  File "\\\ldk_drawbox.py", line 63, in GetLift
    dot_value = self.grid_normal.dot(result_vector.normalized())
  File "\\\\modules\bpy_types.py", line 580, in __getattribute__
    properties = StructRNA.path_resolve(self, "properties")
ReferenceError: StructRNA of type LDKDrawBox has been removed

Traceback (most recent call last):
  File "\\\ldk_drawbox.py", line 450, in Draw_ScreenSpace
    DrawText(self, context)
  File "\\\ldk_drawbox.py", line 48, in DrawText
    blf.draw(font_id, "GRID AXIS = " + str(self.axis))
  File "\\\\modules\bpy_types.py", line 580, in __getattribute__
    properties = StructRNA.path_resolve(self, "properties")
ReferenceError: StructRNA of type LDKDrawBox has been removed

I think you have to made this operator aware about active layer and for now just ignore objects with some modifiers. I will play with this on weekend.

It was working really well, but today I keep on getting this bug


That what I need! - thanks for addon and hope you don,t stop and do more like in Sketchup - it’s very useful…

Thanks for this, I really Appreciate it.

Hey, could you please prepare your add-on for 2.70? Here are the instructions - http://wiki.blender.org/index.php/Dev:Doc/Projects/UI/Tab_Guidelines

Thanks

Hey ho,

found this addon today and tried at on a old blender release on my laptop and was really impressed. Then I wanted to install it in Blender 2.71 on my desktop and it doesn’t work. Please update the addon! This is really awesome work and I would appreciate working with it on my dekstop. BTW switching the releases is an option but I don’t like it. Update it please :smiley:

My god this addon looks amazing 0___0. Id love to see a version of this more suited to drawing geometry. I’m tempted to try and get it working in 2.71, maybe if I have enough time i’ll have a look.

What a cool little thing man! TO bad it has quite some bugs in 2.78