This is an initial commit for inserting a text file as one 3d text object per line. The function for making the objects aligned to the screen needs to be added, since right now it is aligning rotation to the screen but translation is not right since I am adding an offset to the non-viewport location of the objects. That offset just needs to be translated to screen first.
This commit is contained in:
@@ -108,6 +108,9 @@ void do_view3d_buttons(short event);
|
||||
|
||||
void do_headerbuttons(short event);
|
||||
|
||||
/* header_text.c */
|
||||
void do_text_editmenu_to3dmenu(void *arg, int event);
|
||||
|
||||
/* header_info.c */
|
||||
void do_info_add_meshmenu(void *arg, int event);
|
||||
void do_info_add_curvemenu(void *arg, int event);
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "DNA_vfont_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_text_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_font.h"
|
||||
@@ -312,6 +313,72 @@ void txt_export_to_object(struct Text *text)
|
||||
}
|
||||
|
||||
|
||||
void txt_export_to_objects(struct Text *text)
|
||||
{
|
||||
ID *id;
|
||||
Curve *cu;
|
||||
struct TextLine *tmp, *curline;
|
||||
int nchars;
|
||||
int linNum = 0;
|
||||
|
||||
if(!text) return;
|
||||
|
||||
id = (ID *)text;
|
||||
|
||||
if (G.obedit && G.obedit->type==OB_FONT) return;
|
||||
check_editmode(OB_FONT);
|
||||
|
||||
curline = text->lines.first;
|
||||
while(curline){
|
||||
/*skip lines with no text, but still make space for them*/
|
||||
if(curline->line[0] == '\0'){
|
||||
linNum++;
|
||||
curline = curline->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
nchars = 0;
|
||||
add_object(OB_FONT);
|
||||
|
||||
base_init_from_view3d(BASACT, G.vd);
|
||||
G.obedit= BASACT->object;
|
||||
where_is_object(G.obedit);
|
||||
|
||||
|
||||
/* Do the translation */
|
||||
|
||||
G.obedit->loc[1] -= linNum;
|
||||
|
||||
/* End Translation */
|
||||
|
||||
|
||||
cu= G.obedit->data;
|
||||
|
||||
cu->vfont= get_builtin_font();
|
||||
cu->vfont->id.us++;
|
||||
|
||||
nchars = strlen(curline->line) + 1;
|
||||
|
||||
if(cu->str) MEM_freeN(cu->str);
|
||||
|
||||
cu->str= MEM_mallocN(nchars+4, "str");
|
||||
|
||||
strcpy(cu->str, curline->line);
|
||||
cu->len= strlen(curline->line);
|
||||
cu->pos= cu->len;
|
||||
|
||||
|
||||
make_editText();
|
||||
exit_editmode(1);
|
||||
|
||||
linNum++;
|
||||
curline = curline->next;
|
||||
}
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
|
||||
|
||||
void do_textedit(unsigned short event, short val, char _ascii)
|
||||
{
|
||||
Curve *cu;
|
||||
|
||||
@@ -272,9 +272,6 @@ static void do_text_editmenu(void *arg, int event)
|
||||
case 9:
|
||||
txt_find_panel(st,0);
|
||||
break;
|
||||
case 10:
|
||||
txt_export_to_object(text);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -456,6 +453,38 @@ static uiBlock *text_formatmenu(void *arg_unused)
|
||||
return block;
|
||||
}
|
||||
|
||||
|
||||
/* action executed after clicking in Object to 3d Sub Menu */
|
||||
void do_text_editmenu_to3dmenu(void *arg, int event)
|
||||
{
|
||||
SpaceText *st= curarea->spacedata.first;
|
||||
Text *text= st->text;
|
||||
|
||||
switch(event) {
|
||||
case 1: txt_export_to_object(text); break;
|
||||
case 2: txt_export_to_objects(text); break;
|
||||
}
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
|
||||
/* Object to 3d Sub Menu */
|
||||
static uiBlock *text_editmenu_to3dmenu(void *arg_unused)
|
||||
{
|
||||
uiBlock *block;
|
||||
short yco = 20, menuwidth = 120;
|
||||
|
||||
block= uiNewBlock(&curarea->uiblocks, "do_text_editmenu_to3dmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
|
||||
uiBlockSetButmFunc(block, do_text_editmenu_to3dmenu, NULL);
|
||||
|
||||
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "One Object | Alt-M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
|
||||
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "One Object Per Line", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
|
||||
|
||||
uiBlockSetDirection(block, UI_RIGHT);
|
||||
uiTextBoundsBlock(block, 60);
|
||||
return block;
|
||||
}
|
||||
|
||||
|
||||
/* Edit menu */
|
||||
static uiBlock *text_editmenu(void *arg_unused)
|
||||
{
|
||||
@@ -480,7 +509,7 @@ static uiBlock *text_editmenu(void *arg_unused)
|
||||
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find...|Alt Ctrl F", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
|
||||
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find Again|Alt F", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
|
||||
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
|
||||
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Convert to 3D Text|Alt M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, "");
|
||||
uiDefIconTextBlockBut(block, text_editmenu_to3dmenu, NULL, ICON_RIGHTARROW_THIN, "Text to 3d Object", 0, yco-=20, 120, 19, "");
|
||||
|
||||
if(curarea->headertype==HEADERTOP) {
|
||||
uiBlockSetDirection(block, UI_DOWN);
|
||||
|
||||
Reference in New Issue
Block a user