mybpy: Easy Modeling
Today, Let's introduce how can easy modling by mybpy.
You can copy the following codes to the Blender Text Editor of Scripting Page:
#========Link to mybpy===============
import sys;sys.path.append(r'd:\mybpy')
import importlib as imp;import m;imp.reload(m);from m import *
#=======Initial==========================
clearAll() # when you create a model and edit it many times by scripting you can use this clearAll, to avoid many more models create in the scence.
#====My Catoon Cow Modeling===============
#-------------Head-----------------
cube(3);sz(1.2);sy(0.95);name('head_up'); #head upper part
cube(3);sx(1.3);sy(1.1);sz(0.8);gz(-0.4);name('head_down'); #head down part
#-----------------------horn------------------------------
cube(2);s(0.3);sx(0.8);sz(1.8);gx(+0.7);gz(0.9);ry(+45);name('horn_right')
cube(2);s(0.3);sx(0.8);sz(1.8);gx(-0.7);gz(0.9);ry(-45);name('horn_left')
#--------------------ears------------------------------------
cube(1);s(0.2);sx(1);gx(+0.7);gz(0.5);ry(+45);nm('ear_right')
cube(1);s(0.2);sx(1);gx(-0.7);gz(0.5);ry(-45);nm('ear_left')
#-----------------eyes-------------------------------------
sphere();sm();s(0.2);g(( 0.3,-0.68,0.3));nm('eye_right')
sphere();sm();s(0.2);g((-0.3,-0.68,0.3));nm('eye_left')
#-------------Mouth----------------
cube(3);s(0.2);sx(2.5);gy(-0.78);gz(-0.47);name('mouth');
#-------------Body------------------
cube(3);s(0.4);gz(-1.1);ap();name('neck')
cube(3);sm();sz(1.5);gz(-2.3);name('body')
#--------------arms--------------------------
cube(3);s(0.4);sx(2.8);gx(+1.3);gz(-1.5);name('arm_right')
cube(3);s(0.4);sx(2.8);gx(-1.3);gz(-1.5);name('arm_left')
cube(3);s(0.4);sx(2.3);gx(+0.4);gz(-4);ry(90);name('leg_right')
cube(3);s(0.4);sx(2.3);gx(-0.4);gz(-4);ry(90);name('leg_left')
cube(3);s(0.4);sx(0.5);sy(1.4);sz(0.8);gx(+0.4);gy(-0.21);gz(-4.7);ry(90);name('foot_right');
cube(3);s(0.4);sx(0.5);sy(1.4);sz(0.8);gx(-0.4);gy(-0.21);gz(-4.7);ry(90);name('foot_left');
cube(3);s(0.4);sx(1);gx(+2.3);gz(-1.5);name('hand_right')
cube(3);s(0.4);sx(1);gx(-2.3);gz(-1.5);name('hand_left')
#=======Add Camera and light===============
ca()
#========End of Script======================
The above is the script wrote based on mybpy to make a catoon cow simple model. If you are Blender user, it's quite easy to understand for you. let explain it more:
cube(3) = cube(); ctr3();smooth()
is to simplized defination to create a cube, the argument 3 means not only add cube but also add the modifier of subsurface in level 3 and smooth. you can also write: cube(); ctr3();smooth() in the script to instead of cube(3) also.
s(0.4) : scale, the argument is 0.4
sx(0.4): along x axis to scale, the argument is 0.4
gx(1) : go 1 unit along x axis
ry(90): rotate along y axis 90 degree
See, it's quite simple and same with Blender short quick command. It's quite usefual to the user of Blender. Easy enough and can help you to rember how to making the model.
You can copy them to many script files and edit the argmument to re-model it to be the cartoon Bear, Rabit, dog, cars, budlings... and just drag the script txt file to the little window of Text Editor in Blender and press Alt+P to quick build your simple modle at the beginning of you detailed art works. In the future, I will try to let it possible to model the more complex even the completed model by typing the easy script words.
Let's continue to explain more about the words in the script:
clearAll() : you can delete after you complete the script when you just want to add your new simple modle.However, It's useful when you tring to writing the script and pressing Alt+P to show the result of Running. without this clearAll() command, you will get more and more models in the scene. The simple re-define this word is cl(), you can also type cl() in the console to clean everything.
ca(): means to add camera and light. because you have clearAll() at the beginning of the script, you need to add camera and light at the end of the script if you want to render to show the result.
sm(): smooth() , it's the short def of smooth.
you can look for the word defination in m.py file, when you find sm(), you will see the defination words paragraph like this:
#-------shade smooth-----------------------------------
def shadeSmooth():
if modeI!=0:m0()
bpy.ops.object.shade_smooth()
def smooth():shadeSmooth()
def smth():shadeSmooth()
def sm():shadeSmooth()
all the words are same command, whatever you write smooth(), smth(),sm(), it's same to shadeSmooth() which link to the bpy command bpy.ops.object.shade_smooth().
(In m.py one line def words is the re-define in normal. The more detailed the define is at the above of the simple re-define words in normal. You can check by youself)
More important: you can re-define them use your own language just type like what I do at the bottom of m.py file.
You will see the Chinese def samples for most useful command def. You can re-def them using your own language, Frech, Spanish, Detch.....
Even you are writing yourself Script, you can re-definting the m.py file at the same time. for example, you need def smooth() to be the smoo() or in own langue, you can just add the def words at the bottom of m.py
def smoo(): smooth()
Now, you can use smoo() instead of smooth(). It's active right now. NOT NEED To Close and Re-open Blender. Why?
The scecret is the linking words to mybpy:
import sys;sys.path.append(r'd:\mybpy')
import importlib as imp;import m;imp.reload(m);from m import *
In the above linking words, these words (the following) will re-load m.py immediately when you change definations in m.py :
import importlib as imp;import m;imp.reload(m);
If you negelect these words, it's Ok, just not imidieate reload m.py when you re-define m.py . You just need close blender and re-open it when you change any def in m.py .
so you can write the linking words at the begining of script like this :
import sys;sys.path.append(r'd:\mybpy')
from m import *
It's quite simple.even you can write in one line,just add symbol " ; " like this:
import sys;sys.path.append(r'd:\mybpy');from m import *
Another tip: When you write script, you can add three " or ', to make the paragraph of codes are disabled, even you can add command exec(StringVariableOfCodes) to run your disabled words,for example, you can re-write the above script like this:
#========Link to mybpy===============
import sys;sys.path.append(r'd:\mybpy')
import importlib as imp;import m;imp.reload(m);from m import *
#=======Initial==========================
clearAll() # when you create a model and edit it many times by scripting you can use this clearAll, to avoid many more models create in the scence.
#====My Catoon Cow Modeling===============
#-------------Head-----------------
head='''
cube(3);sz(1.2);sy(0.95);name('head_up'); #head upper part
cube(3);sx(1.3);sy(1.1);sz(0.8);gz(-0.4);name('head_down'); #head down part
#-----------------------horn------------------------------
cube(2);s(0.3);sx(0.8);sz(1.8);gx(+0.7);gz(0.9);ry(+45);name('horn_right')
cube(2);s(0.3);sx(0.8);sz(1.8);gx(-0.7);gz(0.9);ry(-45);name('horn_left')
#--------------------ears------------------------------------
cube(1);s(0.2);sx(1);gx(+0.7);gz(0.5);ry(+45);nm('ear_right')
cube(1);s(0.2);sx(1);gx(-0.7);gz(0.5);ry(-45);nm('ear_left')
#-----------------eyes-------------------------------------
sphere();sm();s(0.2);g(( 0.3,-0.68,0.3));nm('eye_right')
sphere();sm();s(0.2);g((-0.3,-0.68,0.3));nm('eye_left')
#-------------Mouth----------------
cube(3);s(0.2);sx(2.5);gy(-0.78);gz(-0.47);name('mouth');
'''
exec(head)
#-------------Body------------------
body="""
cube(3);s(0.4);gz(-1.1);ap();name('neck')
cube(3);sm();sz(1.5);gz(-2.3);name('body')
"""
exec(body)
#--------------arms--------------------------
arms='''
cube(3);s(0.4);sx(2.8);gx(+1.3);gz(-1.5);name('arm_right')
cube(3);s(0.4);sx(2.8);gx(-1.3);gz(-1.5);name('arm_left')
cube(3);s(0.4);sx(2.3);gx(+0.4);gz(-4);ry(90);name('leg_right')
cube(3);s(0.4);sx(2.3);gx(-0.4);gz(-4);ry(90);name('leg_left')
cube(3);s(0.4);sx(0.5);sy(1.4);sz(0.8);gx(+0.4);gy(-0.21);gz(-4.7);ry(90);name('foot_right');
cube(3);s(0.4);sx(0.5);sy(1.4);sz(0.8);gx(-0.4);gy(-0.21);gz(-4.7);ry(90);name('foot_left');
cube(3);s(0.4);sx(1);gx(+2.3);gz(-1.5);name('hand_right')
cube(3);s(0.4);sx(1);gx(-2.3);gz(-1.5);name('hand_left')
'''
exec(arms)
#=======Add Camera and light===============
ca()
#========End of Script======================
Above is re-writing the string paragraph format of the script. You can define the paragraph of codes just use three ' or " at the begining of the paragraph and end of paragraph, and can give a varible name like head, body, arms... , if you want neglect body and arms, just #exec(body) #exec(arms), there's no body and arms,only head. it's easy for you to focus on the part of model.
somes it's quite long and take space to write "if " or "for" sentence in py script, you can just use my string quick def function sq() to easy write 'if' and 'for' sentecen in one line, because, sq() function will change ` to new line , ~ will change to tab space. example like this: In normal you should write 'if' sentenc like this:
if a==1:
(tab spaces) b=2
(tab spaces) c=3
use sq(), you can execute like this:
exec(sq('if a==1:`~b=2;`~c=3'))
It's make your script short and simple and not easy to error because of tab space.
The attatched Image is the modle created by the script wroten based on mybpy, It's have colored command which I will introduce in the future (To be simple, I negelect in the sample script today)
Please download and try mybpy. Your comment will be highly appreciated.
The codes download github address:
If you are Chinese, please visit the BBS in Baidu: tieba.baidu.com/p/7393914011
There are more information in Chinese introduction.
You also can download full dictories from Baidu Cloud (including history versions dictories and using examples in the future I will provide):
pan.baidu.com/s/1lWWFsxZ4_7tTxTuYmi2z2A
Getting Code : mbpy
Hope get your comments, I 'll develop and update it better...
Best Regards
cn2000 in China. (Email: caonan2000@163.com)