Page MenuHome

TranspRef0.71.py

TranspRef0.71.py

#!BPY
# """
# Name: '_Transp reference'
# Blender: 248
# Group: 'Image'
# Tooltip: 'Use plane as transp reference.'
# """
#
#
# version 0.71
# march 25, 2005
# by Gert De Roost http://users.telenet.be/EWOCprojects
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# If you have Internet access, you can find the license text at
# http://www.gnu.org/licenses/gpl.txt,
# if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
__author__ = 'Gert De Roost'
__version__ = '0.71 march 26, 2005'
__url__ = ["EWOCprojects, http://users.telenet.be/EWOCprojects"]
__email__ = ["Gert De Roost, ewocprojects@yahoo.com"]
__bpydoc__ = """\
This plugin fills in another gap in the Blender modelling experience. It provides a means of
setting up an unlimited amount of "background images", or to be more precise "reference images".
These planes can be positioned/scaled to your liking and will seemingly appear behind your
transparently rendered geometry. In fact the reference planes are transparent
themselves and drawn on top of the geometry. This means it is possible to use the planes for
both sides of your geometry (front/back, right/left, top/bottom), whatever way you look at them,
they will always be drawn transparently on top of the geometry, only appearing to be in a certain
3 dimensional position.
Documentation
First you must add a standard plane and position it behind your geometry
(positioning is done so you have some frame of reference when setting transparency;
don't worry, you can adjust transparency later on also).
Select the plane and invoke the plugin (do note the script appears in the "Object" submenu,
so exit EditMode or start the script from a script window). A fileselector will open,
now select an image and click on "LOAD REFERENCE IMAGE". The image will be loaded into the plane.
Now press and hold any mouse button and drag to the left or the right to decrease/increase the transparency value.
The resulting reference plane can be transformed as required. You may also tweak individual corner vertices,
but note that this will only affect the image after exiting EditMode.
If you want to adjust the transparency value later on, select the reference plane and re-invoke the plugin;
you can then adjust transparency as described above. If you want to change the reference image,
you will need to set up a new reference plane. You delete the plane by pressing DEL.
NOTE: you can create as many reference planes as needed.
HINT: you can use the reference planes from both sides.
I recommend to model in orthogonal mode (which is a good idea anyhow) if you want this to work correctly.
BEWARE: if you save and reload a scene with reference images, the planes will still exist,
but the the images will not. You'll have to use the script to set up the planes again...
"""
import Blender
from math import sqrt
from Blender.Mathutils import *
from Blender.BGL import *
from Blender import Window, Object, NMesh, Text, Image, Scene, Draw
#lobo_nz
def savenewplane(newplane,newtransp,newpath):
try:
#load the saved data
txt = Text.Get("savedrefplanes")
evallist = txt.asLines()
save_planelist = eval(evallist[0])
save_transplist = eval(evallist[1])
save_pathlist = eval(evallist[2])
#clear out the old saved data
Text.unlink(txt)
except:
save_planelist = []
save_transplist = []
save_pathlist = []
#create new text
txt = Text.New("savedrefplanes")
#append new plane info
save_planelist.append(newplane.name)
save_transplist.append(newtransp)
save_pathlist.append(newpath)
#write save_planelist to text object
txt.write("[")
for i in range(len(save_planelist)):
if i != 0:
txt.write(", ")
txt.write("'"+save_planelist[i]+"'")
txt.write("]\n")
#write save_transplist to text object
txt.write("[")
for i in range(len(save_transplist)):
if i != 0:
txt.write(", ")
txt.write(str(save_transplist[i]))
txt.write("]\n")
#write save_pathlist to text object
txt.write("[")
for i in range(len(save_pathlist)):
if i != 0:
txt.write(", ")
txt.write("'"+save_pathlist[i]+"'")
txt.write("]\n")
#lobo_nz
def loadimage(filename):
buttonarea = Window.GetScreenInfo(Window.Types.SCRIPT)[0]
Window.QHandle(buttonarea.get("id"))
image = Image.Load(filename)
scene = Scene.GetCurrent()
# Store currently running scriptlinks.
framechangedlist = scene.getScriptLinks("FrameChanged")
onloadlist = scene.getScriptLinks("OnLoad")
onsavelist = scene.getScriptLinks("OnSave")
redrawlist = scene.getScriptLinks("Redraw")
if redrawlist != None:
if "referencetag.py" in redrawlist:
redrawlist.pop(redrawlist.index("referencetag.py"))
scene.clearScriptLinks()
scene.update()
scene.addScriptLink("referencetag.py", "Redraw")
scene.addScriptLink("transprefreload.py", "OnLoad")
# Restore other scriptlinks.
if framechangedlist != None:
for script in framechangedlist:
scene.addScriptLink(script, "FrameChanged")
if onloadlist != None:
for script in onloadlist:
scene.addScriptLink(script, "OnLoad")
if onsavelist != None:
for script in onsavelist:
scene.addScriptLink(script, "OnSave")
if redrawlist != None:
for script in redrawlist:
scene.addScriptLink(script, "Redraw")
try:
dummy = Blender.planelist[0]
except:
Blender.imagelist = []
Blender.planelist = []
Blender.transplist = []
Blender.imagelist.insert(0, image)
Blender.planelist.insert(0, obj)
Blender.transplist.insert(0, 0.5)
Window.EditMode(0)
Window.Redraw(Window.Types.VIEW3D)
gettransparency()
#lobo_nz
savenewplane(obj,0.5,filename)
#lobo_nz
def setupreferenceimage():
Window.FileSelector(loadimage, "LOAD REFERENCE IMAGE")
def gettransparency(position=0):
while Window.GetMouseButtons() == 0:
pass
xbase = Window.GetMouseCoords()[0]
while Window.GetMouseButtons():
mx, dummy = Window.GetMouseCoords()
if mx > (xbase + 100):
xbase = mx - 100
elif mx < (xbase - 100):
xbase = mx + 100
Blender.transplist[position] = ((mx - xbase) / 200.0) + 0.5
Window.Redraw(Window.Types.VIEW3D)
while Window.GetMouseButtons():
pass
while 1:
# Test if "referencetag.py" is already loaded and if it is present in the scripts dir at all.
# Load it.
try:
txt = Text.Get("referencetag.py")
Text.unlink(txt) # always reload in case user installed new version
#lobo_nz
txt2 = Text.Get("transprefreload.py")
Text.unlink(txt2) # always reload in case user installed new version
#lobo_nz
except:
pass
failed = 0
if Blender.Get("scriptsdir") != None:
try:
Text.Load("".join([Blender.Get("scriptsdir"), "/referencetag.py"]))
#lobo_nz
Text.Load("".join([Blender.Get("scriptsdir"), "/transprefreload.py"]))
#lobo_nz
except:
failed = 1
else: failed = 1
if Blender.Get("uscriptsdir") != None:
try:
Text.Load("".join([Blender.Get("uscriptsdir"), "/referencetag.py"]))
#lobo_nz
Text.Load("".join([Blender.Get("uscriptsdir"), "/transprefreload.py"]))
#lobo_nz
except:
failed = 2
elif failed == 1:
failed = 2
if failed == 2:
Draw.PupMenu("Script 'referencetag.py' or 'transprefreload.py' not installed correctly. Install all scripts.")
break
# Test if selection is already reference plane.
obj = Object.GetSelected()
obj = obj[0]
try:
if obj in Blender.planelist:
gettransparency(Blender.planelist.index(obj))
break
except:
pass
# Test if selection is exactly one non-subdivided plane.
if obj == None:
Draw.PupMenu("You must select exactly one non-subdivided plane.")
break
mesh = obj.getData()
if (len(mesh.faces) > 1) or (len(mesh.faces[0].v) == 3):
Draw.PupMenu("You must select exactly one non-subdivided plane.")
break
Window.FileSelector(loadimage, "LOAD REFERENCE IMAGE")
break

File Metadata

Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
53/22/24cc6201512f90afbf5f45f2e97d

Event Timeline