|
este plugin genera pasto o grass ( en ingles ) es free de una pagina japonesa lo copias al bloq de notas y lo guardas como : fur_en_v1_2.rb
## Name : fur_en.rb
## Description : Make Fur( Grass )
## Auther : TAK2HATA ( http://onigiriburning.so.land.to/ )
##Since : 2010-04-21--- v0.0
##Rev : 2010-05-05-- v0.1
## speedup
## add component --
## add menu for mac -- v0.3
##Rev : 2010-05-06 -- v1.0
## Because I did a big change, this plugin might have the problem.
## use to be carefully. Especially, about saving file.
## menu named "Fur!(MAC)" change to "Fur v1_0!(InputBox)"
## menu named "Fur!(EN)" change to "Fur v1_0!(WebDialog)"
## Type select to Name
## fix problem:when length too small,it create also 50.mm
## add Type for Box option
## add fur model from Select Component option
## Change Extra Upper force strength
## add keep fur parameter.
## add save & load preset.
## How to save preset
## Webdialog::Press "Save New Preset" button, and input preset name.
## InputBox ::Select "Add" in "Select Preset"(listbox), and press "OK".
## How to Load preset
## Webdialog::Select Preset_name in "Select Preset"(listbox) and press load_preset button ,then update parameter in dialog.
## InputBox ::Select Preset_name in "Select Preset"(listbox). and press OK to opdate parameter in dialog.
## About Make_By_ComponentInstance(listbox)
## "no" to make furs by mesh.it parts each 800 polgyon.
## "yes" to make furs by component_instance.it is in one group.component_name is "fur_instance"
## If ComponentDefinition is exist in model, then component_names are include in listbox.
## (problem::please don't select component that always face to camera.)
##Rev : 2010-05-07
## operation go faster works on only sketchup7 upper.
##Rev : 2010-05-08
## Add "Assign to Material"
##Rev : 2010-05-09 --- v1.2
## Add get_furmesh_by_mat( face , mat , ret_furmesh = [> ) for any exporters.
## webdialog refresh method changed.
require 'sketchup.rb'
class FUR_EN
FUR_DIC_PREFIX = "FUR_DIC"
FUR_PRESET_FILE = "fur_param.ini"
def get_dialogitems
dlg = [>
dlg.push ["Density(Num/m2)","200","","fdensity">#0
dlg.push ["MaxNumber(/Face)","200","","maxnum">#1
dlg.push ["Length(m)","0.2","","flength">#2
dlg.push ["RootWidth(m)","0.04","","frootw">#3
dlg.push ["Stiffness(m)","8","","fstrong">#4
dlg.push ["TopJitter(%)","40","","fljitter">#5
dlg.push ["WidthJitter(%)","25","","fwjitter">#6
dlg.push ["StiffnessJitter(%)","50","","fsjitter">#7
dlg.push ["Divide","3","","fdivs">#8
dlg.push ["Valid Distance(m)","0","","fvradius">#9
#dlg.push ["Type(1-4)","2","1|2|3|4","ftype">#10
dlg.push ["Type","Arch","Linear|Arch|Leaf|Rectanguler|Box","ftype">#10
defs = Sketchup.active_model.definitions
dfnames = [>
defs.each{|df|
dfnames.push df.name if df.group? == false and df.name != "fur_instance"
}
alist = "yes|no|fur_instance"
alist = alist + "|" + dfnames.join("|") if dfnames.length > 0
dlg.push ["Make by ComponentInstance","no",alist,"instance">#11
return dlg
end
def get_param( ent , idns )
#model = Sketchup.active_model
#fdic = model.attribute_dictionary FUR_DIC_PREFIX
fdic = ent.attribute_dictionary FUR_DIC_PREFIX
return nil if fdic == nil
answer = [>
idns.keys.each{|id|
a = fdic[ idns[id> >
if a != nil
answer[id> = a
end
}
return nil if answer.length <= 0
return answer
end
def put_param( ent ,results,idns )
#model=Sketchup.active_model
attrdict = ent.attribute_dictionary( FUR_DIC_PREFIX , true )
id = 0
results.each{|res|
#UI.messagebox idns[id>.to_s + "n" + res
attrdict[ idns[id>.to_s > = res if idns[id>.to_s != ""
id += 1
}
end
def del_param_from_scene( )
model = Sketchup.active_model
fdics = model.attribute_dictionaries
return nil if fdics == nil
fdics.delete FUR_DIC_PREFIX
end
def save_preset( results , presetname )
return if results == nil
saveline = presetname.to_s + "," + results.join(",")
thisdir = File.dirname(File.expand_path(__FILE__))
path = thisdir + "/#{FUR_PRESET_FILE}"
ini_file=File.new(path,"a")##append mode
ini_file.puts saveline
ini_file.close
end
def load_preset( presetname ,defaults )
return if presetname == nil or presetname == ""
params = [>
thisdir = File.dirname(File.expand_path(__FILE__))
path = thisdir + "/#{FUR_PRESET_FILE}"
if FileTest.exist?(path)
ini_file=File.new(path,"r")##read mode
ini_file.each{|line|
if line != ""
splt = ( line.chomp ).split(/,/)
if splt[0> == presetname
splt.each_with_index{|pr , id|
params.push pr if id != 0 and id <= ( defaults.size )
}
end
end
}
ini_file.close
return nil if params.length <= 0
return params
else
return nil
end
end
def get_presetnames
presetnames = ""
thisdir = File.dirname(File.expand_path(__FILE__))
path = thisdir + "/#{FUR_PRESET_FILE}"
if FileTest.exist?(path)
ini_file=File.new(path,"r")##read mode
ini_file.each{|line|
pname = (line.chomp).split(/,/)
presetnames = presetnames + "|" + pname[0> if pname[0> != ""
}
ini_file.close
return presetnames
else
return nil
end
end
def fur_inputbox
dlg = get_dialogitems
prompts = [>
defaults = [>
lists = [>
idns = Hash.new
id = 0
dlg.each{|prp,dfl,lst,idn|
prompts.push prp
defaults.push dfl
lists.push lst
idns[id> = idn
id += 1
}
params = get_param( Sketchup.active_model ,idns )
defaults1 = defaults.map{|prp| prp }
if params != nil
( 0..(params.size-1) ).each{|id|
defaults1[id> = params[id> if defaults1.length > id
}
end
fdensity = ""
maxnum = ""
flength = ""
frootw = ""
fdivs = ""
fstrong = ""
fj = ""
fwjitter = ""
fsjitter = ""
fdivs = ""
fvradius = ""
ftype = ""
finstance = ""
save_preset = ""
results = [>
reload = ""
title = "Fur settings."
title1 = "Fur settings."
is_df_exist = false
while( fdensity.to_f == 0 or maxnum.to_f == 0 or flength.to_f == 0 or frootw.to_f == 0 or fdivs.to_f == 0 or fstrong.to_f == 0 or reload == "" or is_df_exist == false)
prompts2 = prompts.map{|prp| prp }
prompts2.push "SELECT PRESET(BLANK to Start Fur)"
defaults2 = defaults1.map{|prp| prp }
defaults2.push ""
lists2 = lists.map{|prp| prp }
presetnames = get_presetnames
if presetnames != nil
lists2.push "|default|add|assign_material|get_from_material" + presetnames
else
lists2.push "|default|add|assign_material|get_from_material"
end
results = UI.inputbox prompts2 , defaults2, lists2, title1
return if results == false or results == nil
fdensity = results[0>
maxnum = results[1>
flength = results[2>
frootw = results[3>
fstrong = results[4>
fj = results[5>
fwjitter = results[6>
fsjitter = results[7>
fdivs = results[8>
fvradius = results[9>
ftype = results[10>
finstance = results[11>
save_preset = results[12>
is_df_exist = false
if finstance != "yes" and finstance != "no" and finstance != "fur_instance"
Sketchup.active_model.definitions.each{|df|
is_df_exist = true if df.name == finstance and df.group? == false
}
else
is_df_exist = true
end
if save_preset == ""
reload = "continue"
elsif save_preset == "add"
presetname = UI.inputbox ["PRESET_NAME">, ["">, "Input preset name"
if presetname == false or presetname == nil or presetname[0> == ""
else
save_preset results , presetname[0>
results[12> = ""
defaults1 = results.map{|prp| prp }
reload = ""
title1 = title + "--" + presetname[0>
end
elsif save_preset == "default"
defaults1 = defaults.map{|prp| prp }
reload = ""
title1 = title + "--default"
elsif save_preset == "assign_material"
defaults1 = results.map{|prp| prp }
cmat = Sketchup.active_model.materials.current
put_param cmat , results , idns if cmat != nil
reload = ""
title1 = title + cmat.name
elsif save_preset == "get_from_material"
cmat = Sketchup.active_model.materials.current
if cmat != nil
params = get_param( cmat , idns )
defaults1 = defaults.map{|prp| prp }
if params != nil
( 0..(params.size-1) ).each{|id|
defaults1[id> = params[id> if defaults1.length > id
}
reload = ""
title1 = title + cmat.name
end
end
else
prvalue = load_preset( save_preset , defaults )
defaults1 = prvalue.map{|prp| prp } if prvalue != nil
reload = ""
title1 = title + "--" + save_preset
end
end
put_param Sketchup.active_model , results,idns
@fdensity = fdensity.to_f
@maxnum = maxnum.to_i
@flength = flength.to_f.m
@frootw = frootw.to_f.m
@fstrong = fstrong.to_f
@fj = fj.to_f / 100
flj = @fj.to_f * @flength.to_m.to_f
@fljitter = Geom::Vector3d.new( @fj * @flength , @fj * @flength , @fj * @flength )
@fwjitter = fwjitter.to_f * @frootw.to_m.to_f / 100
@fsjitter = fsjitter.to_f * @fstrong.to_f / 100
@fdivs = fdivs.to_i
@fvradius = fvradius.to_f.m
@ftype = ftype.to_s
@finstance = finstance.to_s
glowup
end
def show_webdialog( prompts2 , defaults2 , lists2 , idns, title1 , defaults1 , defaults ,prompts ,lists, title )
prompts2 = prompts.map{|prp| prp }
prompts2.push "PRESET?"
defaults2 = defaults1.map{|prp| prp }
defaults2.push ""
lists2 = lists.map{|prp| prp }
presetnames = get_presetnames
if presetnames != nil
lists2.push "|default" + presetnames
else
lists2.push "|default"
end
icount = prompts2.length - 1
dlg2 = (0..icount).map{|i| [ prompts2[i>.to_s , defaults2[i>.to_s , lists2[i>.to_s , idns[i>.to_s > }
cr = "n"
shtm = '<html lang="en"><head><meta http-equiv="content-type" content="text/html; charset=SHIFT-JIS" />'
shtm = shtm + "</head><body scroll=yes><basefont size='2'>" + cr
shtm = shtm + "<script type='text/javascript'>"+ cr
shtm = shtm + "function start_fur(obj) {"+ cr
shtm = shtm + " window.location='skp:start_fur';"+ cr
shtm = shtm + "}"+ cr
shtm = shtm + "function save_new_preset(obj) {"+ cr
shtm = shtm + " window.location='skp:save_new_preset';"+ cr
shtm = shtm + "}"+ cr
shtm = shtm + "function load_preset(obj) {"+ cr
shtm = shtm + " window.location='skp:load_preset';"+ cr
shtm = shtm + "}"+ cr
shtm = shtm + "function assign_to_mat(obj) {"+ cr
shtm = shtm + " window.location='skp:assign_to_mat';"+ cr
shtm = shtm + "}"+ cr
shtm = shtm + "function get_from_mat(obj) {"+ cr
shtm = shtm + " window.location='skp:get_from_mat';"+ cr
shtm = shtm + "}"+ cr
shtm = shtm + "--></script>" + cr
cnt = 0
dlg2.each{|prp,dfl,lst,idn|
if lst == ""
shtm = shtm + prp + "<BR><input type='text' name='#{idn}' id='#{idn}' value='#{dfl}' style='width:150'><BR>"+cr
else
shtm = shtm + prp + "<br>" + cr
shtm = shtm + "<select name='#{idn}' id='#{idn}' style='width:150'>"+cr
lst.split("|").each{|item|
if item == dfl
shtm = shtm + "<OPTION selected value='#{item}'>#{item}</OPTION>"+cr
else
shtm = shtm + "<OPTION value='#{item}'>#{item}</OPTION>"+cr
end
}
shtm = shtm + "</select><BR>"+cr
end
}
shtm = shtm + "<input type='button' name='Load Preset' value='Load Preset' onClick='load_preset(this)' style='width:150'><BR>"+cr
shtm = shtm + "<input type='button' name='Save NewPreset' value='Save NewPreset' onClick='save_new_preset(this)' style='width:150'><BR>"+cr
shtm = shtm + "<input type='button' name='Assign to Current Material' value='Assign to Current Material' onClick='assign_to_mat(this)' style='width:150'><BR>"+cr
shtm = shtm + "<input type='button' name='Get From Current Material' value='Get From Current Material' onClick='get_from_mat(this)' style='width:150'><BR>"+cr
shtm = shtm + "<input type='button' name='Make Fur' value='Make Fur' onClick='start_fur(this)' style='width:150'><BR>"+cr
shtm = shtm + "</body></html>"
@wdlg = UI::WebDialog.new( title1, true, "Units Picker", 100, 100, 150, 150, true)
@wdlg.set_html(shtm)
@wdlg.add_action_callback("save_new_preset"){|d,p|
fdensity = @wdlg.get_element_value("fdensity")
maxnum = @wdlg.get_element_value("maxnum")
flength = @wdlg.get_element_value("flength")
frootw = @wdlg.get_element_value("frootw")
fj = @wdlg.get_element_value("fljitter")
fwjitter = @wdlg.get_element_value("fwjitter")
fdivs = @wdlg.get_element_value("fdivs")
fvradius = @wdlg.get_element_value("fvradius")
fstrong = @wdlg.get_element_value("fstrong")
fsjitter = @wdlg.get_element_value("fsjitter")
ftype = @wdlg.get_element_value("ftype")
finstance = @wdlg.get_element_value("instance")
save_preset = @wdlg.get_element_value("save_preset")
results = [fdensity,maxnum ,flength,frootw,fstrong,fj,fwjitter,fsjitter,fdivs,fvradius,ftype,finstance,save_preset>
if fdensity.to_f == 0 or maxnum.to_f == 0 or flength.to_f == 0 or frootw.to_f == 0 or fdivs.to_f == 0 or fstrong.to_f == 0
else
presetname = UI.inputbox ["PRESET_NAME">, ["">, "Input preset name"
if presetname == false or presetname == nil or presetname[0> == ""
else
save_preset results , presetname[0>
results[12> = ""
defaults1 = results.map{|prp| prp }
reload = ""
title1 = title + "--" + presetname[0>
@wdlg.execute_script( "document.getElementById('save_preset').options[document.getElementById('save_preset').length> = new Option('#{presetname[0>}','#{presetname[0>}')" )
#@wdlg.close
#show_webdialog prompts2 , defaults1 , lists2 , idns, title1 , defaults1 , defaults ,prompts ,lists, title
end
end
}
@wdlg.add_action_callback("load_preset"){|d,p|
save_preset = @wdlg.get_element_value("save_preset")
if save_preset == "default"
defaults1 = defaults.map{|prp| prp }
reload = ""
title1 = title + "--default"
defaults1.each_with_index{|prp,id|
@wdlg.execute_script( "document.getElementById('#{idns[id>}').value = '#{prp}'" )
}
@wdlg.execute_script( "document.title = '#{title1}'" )
#@wdlg.close
#show_webdialog prompts2 , defaults1 , lists2 , idns, title1 , defaults1 , defaults ,prompts ,lists, title
elsif save_preset != ""
prvalue = load_preset( save_preset , defaults )
defaults1 = prvalue.map{|prp| prp } if prvalue != nil
reload = ""
title1 = title + "--" + save_preset
defaults1.each_with_index{|prp,id|
@wdlg.execute_script( "document.getElementById('#{idns[id>}').value = '#{prp}'" )
}
@wdlg.execute_script( "document.title = '#{title1}'" )
#@wdlg.close
#show_webdialog prompts2 , defaults1 , lists2 , idns, title1 , defaults1 , defaults ,prompts ,lists, title
end
}
@wdlg.add_action_callback("get_from_mat"){|d,p|
cmat = Sketchup.active_model.materials.current
if cmat != nil
params = get_param cmat,idns
if params != nil
defaults1 = defaults.map{|prp| prp }
( 0..(params.size-1) ).each{|id|
defaults1[id> = params[id> if defaults1.length > id
}
defaults1.each_with_index{|prp,id|
@wdlg.execute_script( "document.getElementById('#{idns[id>}').value = '#{prp}'" )
}
#wdlg.close
#show_webdialog prompts2 , defaults1 , lists2 , idns, title1 , defaults1 , defaults ,prompts ,lists, title
end
end
}
@wdlg.add_action_callback("assign_to_mat"){|d,p|
fdensity = @wdlg.get_element_value("fdensity")
maxnum = @wdlg.get_element_value("maxnum")
flength = @wdlg.get_element_value("flength")
frootw = @wdlg.get_element_value("frootw")
fj = @wdlg.get_element_value("fljitter")
fwjitter = @wdlg.get_element_value("fwjitter")
fdivs = @wdlg.get_element_value("fdivs")
fvradius = @wdlg.get_element_value("fvradius")
fstrong = @wdlg.get_element_value("fstrong")
fsjitter = @wdlg.get_element_value("fsjitter")
ftype = @wdlg.get_element_value("ftype")
finstance = @wdlg.get_element_value("instance")
save_preset = @wdlg.get_element_value("save_preset")
results = [fdensity,maxnum ,flength,frootw,fstrong,fj,fwjitter,fsjitter,fdivs,fvradius,ftype,finstance,save_preset>
cmat = Sketchup.active_model.materials.current
put_param cmat ,results,idns if cmat != nil
}
@wdlg.add_action_callback("start_fur"){|d,p|
fdensity = @wdlg.get_element_value("fdensity")
maxnum = @wdlg.get_element_value("maxnum")
flength = @wdlg.get_element_value("flength")
frootw = @wdlg.get_element_value("frootw")
fj = @wdlg.get_element_value("fljitter")
fwjitter = @wdlg.get_element_value("fwjitter")
fdivs = @wdlg.get_element_value("fdivs")
fvradius = @wdlg.get_element_value("fvradius")
fstrong = @wdlg.get_element_value("fstrong")
fsjitter = @wdlg.get_element_value("fsjitter")
ftype = @wdlg.get_element_value("ftype")
finstance = @wdlg.get_element_value("instance")
save_preset = @wdlg.get_element_value("save_preset")
results = [fdensity,maxnum ,flength,frootw,fstrong,fj,fwjitter,fsjitter,fdivs,fvradius,ftype,finstance,save_preset>
is_df_exist = false
if finstance != "yes" and finstance != "no" and finstance != "fur_instance"
Sketchup.active_model.definitions.each{|df|
is_df_exist = true if df.name == finstance and df.group? == false
}
else
is_df_exist = true
end
if fdensity.to_f == 0 or maxnum.to_f == 0 or flength.to_f == 0 or frootw.to_f == 0 or fdivs.to_f == 0 or fstrong.to_f == 0 or is_df_exist == false
#nothing execute
else #if save_preset == ""
@fdensity = fdensity.to_f
@maxnum = maxnum.to_i
@flength = flength.to_f.m
@frootw = frootw.to_f.m
@fj = fj.to_f / 100
@flj = @fj * @flength.to_m.to_f
@fljitter = Geom::Vector3d.new( @fj * @flength , @fj * @flength , @fj * @flength )
@fwjitter = fwjitter.to_f * @frootw.to_m.to_f / 100
@fdivs = fdivs.to_i
@fvradius = fvradius.to_f.m
@fstrong = fstrong.to_f
@fsjitter = fsjitter.to_f * @fstrong.to_f / 100
@ftype = ftype.to_s
@finstance = finstance.to_s
put_param Sketchup.active_model ,results , idns
glowup
end
}
@dlg_possize = [250,500,200,200>
@wdlg.show
@wdlg.set_size 250,500
@wdlg.set_position 200,200
end
def fur_webdialog
lang = Sketchup.get_locale.upcase
dlg = get_dialogitems
prompts = [>
defaults = [>
lists = [>
idns = Hash.new
id = 0
dlg.each{|prp,dfl,lst,idn|
prompts.push prp
defaults.push dfl
lists.push lst
idns[id> = idn
id += 1
}
idns[dlg.length> = "save_preset"
params = get_param( Sketchup.active_model , idns )
defaults1 = defaults.map{|prp| prp }
if params != nil
( 0..(params.size-1) ).each{|id|
defaults1[id> = params[id> if defaults1.length > id
}
end
fdensity = ""
maxnum = ""
flength = ""
frootw = ""
fdivs = ""
fstrong = ""
fj = ""
fwjitter = ""
fsjitter = ""
fdivs = ""
fvradius = ""
ftype = ""
finstance = ""
save_preset = ""
results = [>
reload = ""
title = "Fur settings."
title1 = "Fur settings."
prompts2 = prompts.map{|prp| prp }
defaults2 = defaults1.map{|prp| prp }
lists2 = lists.map{|prp| prp }
show_webdialog prompts2 , defaults2 , lists2 , idns, title1 , defaults1 , defaults ,prompts ,lists, title
end
##Rev 2010-05-09 add for exporter.
def get_furmesh_by_mat( face , mat , ret_furmesh = [> )
#ret_furmesh = [ polygonmesh , uv >
if face.is_a?(Sketchup::Face)
else
return nil
end
if mat != nil
fdic = mat.attribute_dictionary FUR_DIC_PREFIX
return nil if fdic == nil
a = fdic[ "fdensity" >
@finstance = fdic[ "instance" >.to_s
return nil if @finstance != "yes" and @finstance != "no" and @finstance != "fur_instance"
@fforce = Geom::Vector3d.new( (0.0).m , (0.001).m , (-0.05).m )
@fdirection = Geom::Vector3d.new( (0.0).m , (0.0).m , @flength.to_f / 20 )
@camera = Sketchup.active_model.active_view.camera
@fdensity = fdic[ "fdensity" >.to_f
@maxnum = fdic[ "maxnum" >.to_i
@flength = fdic[ "flength" >.to_f.m
@frootw = fdic[ "frootw" >.to_f.m
@fj = fdic[ "fljitter" >.to_f / 100
@flj = @fj.to_f / 100 * @flength.to_m.to_f
@fljitter = Geom::Vector3d.new( @fj * @flength , @fj * @flength , @fj * @flength )
@fwjitter = fdic[ "fwjitter">.to_f * @frootw.to_m.to_f / 100
@fdivs = fdic[ "fdivs">.to_i
@fvradius = fdic[ "fvradius" >.to_f.m
@fstrong = fdic[ "fstrong" >.to_f
@fsjitter = fdic[ "fsjitter" >.to_f * @fstrong.to_f / 100
@ftype = fdic[ "ftype" >.to_s
@fdivs = @fdivs + 1 if @fvradius != 0
else
return nil
end
mesh = face.mesh(5)
nvec = face.normal
pmesh = Geom::PolygonMesh.new
#pmeshes = [>
ocnt = 0
if mesh != nil
mesh.polygons.each{|poly|
pt1 = mesh.point_at poly[0>
pt2 = mesh.point_at poly[1>
pt3 = mesh.point_at poly[2>
uv1 = mesh.uv_at( poly[0> ,1 )
uv2 = mesh.uv_at( poly[1> ,1 )
uv3 = mesh.uv_at( poly[2> ,1 )
nor1 = mesh.normal_at poly[0>
nor2 = mesh.normal_at poly[1>
nor3 = mesh.normal_at poly[2>
len12 = pt1.distance pt2
len13 = pt1.distance pt3
vec12 = pt1.vector_to pt2
vec13 = pt1.vector_to pt3
ang23 = vec12.angle_between vec13
area123 = len12.to_m * len13.to_m * Math.sin( ang23 ) * 0.5
cnt = area123 * @fdensity
cnt = cnt.to_i
cnt = 1 if cnt == 0
cnt = @maxnum if cnt > @maxnum
(0..cnt).each{|i|
pmesh = Geom::PolygonMesh.new
ra = rand
rb = 1.to_f - Math.sqrt( rand )
pt4 = Geom::Point3d.new
pt4 = point_add( vector_scale( pt2 , ra.to_f ) , vector_scale( pt3 ,( 1.to_f - ra.to_f ) ) )
pt5 = Geom::Point3d.new
pt5 = point_add( vector_scale( pt1 , rb.to_f ) , vector_scale( pt4 ,( 1.to_f - rb.to_f ) ) )
uv4 = Geom::Point3d.new
uv4.x = uv2.x * ra + uv3.x * (1-ra)
uv4.y = uv2.y * ra + uv3.y * (1-ra)
uv5 = Geom::Point3d.new
uv5.x = uv1.x * rb + uv4.x * (1-rb)
uv5.y = uv1.y * rb + uv4.y * (1-rb)
nor4 = Geom::Point3d.new
nor4 = point_add( vector_scale( nor2 , ra.to_f ) , vector_scale( nor3 ,( 1.to_f - ra.to_f ) ) )
nor5 = Geom::Point3d.new
nor5 = point_add( vector_scale( nor1 , rb.to_f ) , vector_scale( nor4 ,( 1.to_f - rb.to_f ) ) )
divs = @fdivs
#if @finstance == "no"
if @fvradius == 0
make_fur pmesh , pt5 , uv5, nor5 , mat , pt1 ,divs
else
cv1 = @camera.eye.vector_to @camera.target
cv2 = @camera.eye.vector_to pt5
if cv2.angle_between( cv1 ).to_f <= @camera.fov.degrees.to_f
pdist = @fvradius.to_f - pt5.distance( @camera.eye )
pdist = 0 if pdist < 0
divs = ( @fdivs * Math.sqrt( pdist / @fvradius ) ) .to_i
make_fur( pmesh , pt5 , uv5, nor5 , mat , pt1 ,divs ) if divs != 0
end
end
if pmesh.count_polygons > 0
ret_furmesh.push [ pmesh , uv5 >
ocnt += pmesh.count_polygons
Sketchup.set_status_text "Calc #{ocnt} Polygons"
end
#end
}##density loop end
}##polygons.each
end##if mesh?
#ret_furmesh = pmeshes.map{|pm,uv| [ pm , uv > }
return true
end
def glowup
model = Sketchup.active_model
ss = model.selection
ents = model.entities
if ss.empty?
UI.messagebox("No selection.")
return nil
end
return if ss.find{|selface| selface.kind_of? Sketchup::Face } == nil
starttime = Time.now.to_f
@fforce = Geom::Vector3d.new( (0.0).m , (0.001).m , (-0.05).m )
@fdirection = Geom::Vector3d.new( (0.0).m , (0.0).m , @flength.to_f / 20 )
@camera = Sketchup.active_model.active_view.camera
@fdivs = @fdivs + 1 if @fvradius != 0
cnt = 0
sfaces = ss.find_all{|selface| selface.is_a?(Sketchup::Face) }
spgs = sfaces.map{|pg| [pg.mesh(5) , pg.material , pg.normal> }
ocnt = 0
pmesh = Geom
|