I’m writing an importer. I use from_pydata() to create vertices and faces.
I can’t find out how to assign materials and textures which I created from my file to the mesh I created.
I can’t find a way to set a color, uv, bone name and bone weight of vertices.
I can’t find a way to remove doubles after the import, the context operator won’t work as I’m in the script window when running the script (unsurprisingly).
Thanks.
The format I use supports RGBA vertex colors, but Blender only seems to support RGB. Information will get lost after importing and exporting again. Can anything be done?
Also, I still don’t know how to set vertex weight for individual vertex.
BTW, how can you assign a material to vertex group, not mesh? Or can you perhaps assign a material to mesh given the face index and number of faces to assign the material? So you can only assign a material to some faces?
Learn a little bit to answer your questions yourself!
E.g make a cube and subdivide once.
give it two materials (different!)
go to edit mode and select e.g one face
go to the menu where you can set vertex groups
add a new one select your face vertices deselect select (to see it workded)
select the OHTHER material and press Assign
drag the info part (click boarder) to below and you see your API actions like this
bpy.ops.object.editmode_toggle()
bpy.ops.object.vertex_group_add()
bpy.ops.object.vertex_group_deselect()
bpy.ops.object.vertex_group_select()
bpy.ops.object.material_slot_assign() #this is the only part which is not yet clear
But such API work on the ‘latest’ active … (whatever) …
Meaning you have to find out to make the good material slot active and
something like this you can ask here
BUT WITHOUT that stupid “BUMP” … just tell what you do not know to do (IMHO).
And after some more activity you may add pictures and or a .blend file here! (is dependent on the number of post must be greater than x (x around ??? 20???)
Creating bone weights and bone indexes for a vertice cant be guessed by doing it in GUI and looking at the Info window output, because the only way i see of doing it by GUI is the weight paint tool.
I thought there would be a faster way to add vertices to vertexgroups than selecting the vertices, assigning them, and then deselecting again. Same for material assignment.
My other question was, like I said, is there no way to use RGBA colors for vertices? My format uses Alpha for vertex colors so passing it through Blender will make it lose information.
How can you select an object by code? Not everything gets printed in the Info window, like this. I know you can set an object as active, but active != selected, some operators wont work on an active object, unless it’s also selected, like shade_smooth().
I have nothing else to add to my questions, so I could write a pointless sentence like others, but it would have the same meaning as “bump”. Sorry.
lol … batFINGER,
what would be (internet-)life without trolls?
so this code-snippet may be for interest for any real blender-script(?kiddy)er;
its pupose is to run blender to generate one render-image and it was tested
with blender-2.61 (the original download from blender.org, the linux-64bit-version)
saved in a file with name: one_frame.py
# test-dr -- tested with blender-2.61 like this:
# ./blender -b fireworks1.blend -P one_frame.py 60
# then renders frame 60 and exits
import bpy
import sys
print( sys.argv)
sframe = bpy.context.scene.frame_start
eframe = bpy.context.scene.frame_end
#the place to store the image
bpy.context.scene.render.filepath="\ mp\\dummy1"
bpy.context.scene.render.image_settings.file_format="JPEG"
#what renderer to use
bpy.context.scene.render.engine = "BLENDER_RENDER"
#bpy.context.scene.render.engine = "CYCLES"
renderframe = 1
# was an arg at the end after the script-name
# then use it as the frame to be rendered
if sys.argv[-1] != "one_frame.py":
renderframe = int(sys.argv[-1])
bpy.context.scene.frame_end = renderframe
bpy.context.scene.frame_start = renderframe
bpy.context.scene.frame_end = renderframe
bpy.context.scene.frame_current = renderframe
bpy.ops.render.render(animation=True)
bpy.ops.wm.quit_blender()
and if running from a terminal with the shell,
one could do some simple looping like this:
for f in 10 20 30 40; do ./blender -b myblend.blend -P one_frame.py $f; done
creating the images for the frames 10, 20, 30, and 40 … if it does not crash …
And why do you quote my questions before saying it?
You assumed that I’m using my own format (but I’m not) and thought if I think I’m so smart to use my own format, maybe I think I’m so smart that I don’t need Blender and can write my own program.
Firstly, I’m not using a 3d format I invented and even if I did that doesn’t mean anything.
Man, you just made some wrong assumptions. But even if you were right, it doesn’t allow you to be offensive.
Didn’t post that. Not completely innocent. Been teaching a mate how to use blender on the weekends. part of which is how to use the forums to get answers. When I posted post number 2 in this thread last weekend, I had a little wager that no code would be produced… and guess what?.. I won, cheers. We had a good laugh about it… probably came up with the above smart ass reply… tell you what glad he used that one. Wondered why he was grinning like a Cheshire cat when he left after paying up.
Pointless getting offended by silly boys after a few sherbets…
import bpy
#select the batfinger object
ob = bpy.data.objects["Cube"]
ob.name = "batFINGER"
#link to the doghouse scene
if "doghouse" in bpy.data.scenes:
sce = bpy.data.scenes["doghouse"]
sce.objects.link(ob)
else:
print("there is no doghouse %s, otherwise you'd be in it"%ob.name)
This is really funny and all, but can we get back to the topic.
I figured out how to select an object by code: bpy.ops.object.select_name(name = “”). Would be easier to guess from another name like just select(name = “”), or select_by_name(name = “”), but its figured out.
Still no idea how you set bone weights (per-vertex that is, not per vertex group).
And still no idea if I can set Alpha for vertex color as well.