Blender General Questions

General discussion and questions about XNALara go here.

Moderators: ObscureMemories, Runa, Love2Raid

Post Reply
ProtocolX27
Porter
Posts: 3518
Joined: Mon Nov 26, 2012 12:13 pm
Custom Rank: Skynet Status
Location: Cyberspace
Contact:

Re: Blender General Questions

Post by ProtocolX27 »

semory wrote:Still haven't solved the problem via scripting but one thing I noticed... when I render the triangles are textured LOL! just not in the 3D view :D.
So even when set to 'Textured' mode they still aren't showing up?
User avatar
semory
Site Admin
Posts: 7755
Joined: Sat Aug 04, 2012 7:38 pm
Custom Rank: Kitty pu tu tu lay!
Location: Torrance, CA

Re: Blender General Questions

Post by semory »

Yep :D. Draw Type is set to Textured.
User avatar
semory
Site Admin
Posts: 7755
Joined: Sat Aug 04, 2012 7:38 pm
Custom Rank: Kitty pu tu tu lay!
Location: Torrance, CA

Re: Blender General Questions

Post by semory »

Code: Select all

#
# PYTHON IMPORTS
#
import array
import struct
import sys

#
# BLENDER IMPORTS
#
import Blender
from Blender import Image
from Blender import Material
from Blender import Modifier
from Blender import Mathutils
from Blender import Texture
from Blender import Window

import bpy

#
# CONTROL EXECUTION
# main() is called if and only if module is not imported
#
def main():

	# mesh data
	verts = [ (-1.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0) ]
	faces = [ (0, 1, 2) ]
	uvmap = [ (0.0, 0.0), (0.5, 1.0), (1.0, 0.0) ]

	# create mesh
	mesh = Blender.Mesh.New("mesh")
	mesh.verts.extend(verts)
	mesh.faces.extend(faces)
	mesh.faceUV = True
	mesh.addUVLayer('uvmap')
	mesh.activeUVLayer = 'uvmap'
	for index, face in enumerate(mesh.faces):
		a = faces[index][0]
		b = faces[index][1]
		c = faces[index][2]
		face.uv = [ Mathutils.Vector(uvmap[a][0], uvmap[a][1]), Mathutils.Vector(uvmap[b][0], uvmap[b][1]), Mathutils.Vector(uvmap[c][0], uvmap[c][1]) ]
		
	# add mesh to current scene and make mesh active
	scene = Blender.Scene.GetCurrent()
	meshobject = scene.objects.new(mesh, "MeshObject")
	scene.objects.active = meshobject

	# create and load image
	image = Image.Load('C:\\Program Files\\Blender Foundation\\blender-2.49b\\Jack_a.dds')
	if image is None: raise Exception('Failed to load image.')
	if image.bindcode == 0: image.glLoad()

	# create texture and assign image
	texture = Texture.New()
	texture.setImage(image)
	texture.setName('texture')
	
	# create material
	material = Material.New('material')
	material.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL)

	# assign material to faces
	meshobject.colbits = 1
	meshobject.setMaterials([material])
	for f in mesh.faces: f.mat = 0
		
	# redraw
	mesh.update()
	Window.RedrawAll()
    
if __name__ == '__main__':
	main()
ProtocolX27
Porter
Posts: 3518
Joined: Mon Nov 26, 2012 12:13 pm
Custom Rank: Skynet Status
Location: Cyberspace
Contact:

Re: Blender General Questions

Post by ProtocolX27 »

So could I just paste that in the script window and run it? ( minus the specific texture file of course)

My only noob though on that is, maybe the UV mapping isn't properly established on import...? The only reference I see is

material.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL)

Is that guaranteeing that the mesh / texture are aligned correctly? I know that when the mesh.ascii importers run I'd have to move the UV coordinates if I wanted to do any editing.
User avatar
semory
Site Admin
Posts: 7755
Joined: Sat Aug 04, 2012 7:38 pm
Custom Rank: Kitty pu tu tu lay!
Location: Torrance, CA

Re: Blender General Questions

Post by semory »

yeah, paste it in the text view and run it. UVs are fine, go into UV editor and select uvmap and voila a nice triangle. weird though it renders great just doesn't show in 3d view (have to actually load the image in the UV editor manually). i'm telling you, that blender python book sucks :D.
User avatar
semory
Site Admin
Posts: 7755
Joined: Sat Aug 04, 2012 7:38 pm
Custom Rank: Kitty pu tu tu lay!
Location: Torrance, CA

Re: Blender General Questions

Post by semory »

LOL solved the problem... had to use enable GLSL materials :D. Game > Blender GLSL materials... how finicky :D.
ProtocolX27
Porter
Posts: 3518
Joined: Mon Nov 26, 2012 12:13 pm
Custom Rank: Skynet Status
Location: Cyberspace
Contact:

Re: Blender General Questions

Post by ProtocolX27 »

semory wrote:LOL solved the problem... had to use enable GLSL materials :D. Game > Blender GLSL materials... how finicky :D.
Cool, sorry I didn't get a chance to take a look at it. Social stuff hijacked weekend shenanigans.
User avatar
semory
Site Admin
Posts: 7755
Joined: Sat Aug 04, 2012 7:38 pm
Custom Rank: Kitty pu tu tu lay!
Location: Torrance, CA

Re: Blender General Questions

Post by semory »

It's all good. I gave up on writing 2.49b plugin on Friday and busted sat and sun figuring out the 2.65 plugin system instead. Had same problem so started reading a book on general usage and found the glsl thing and it solved it for both. Sucks to spend two days on something that was just a one-click menu item problem :D.
ProtocolX27
Porter
Posts: 3518
Joined: Mon Nov 26, 2012 12:13 pm
Custom Rank: Skynet Status
Location: Cyberspace
Contact:

Re: Blender General Questions

Post by ProtocolX27 »

semory wrote:It's all good. I gave up on writing 2.49b plugin on Friday and busted sat and sun figuring out the 2.65 plugin system instead. Had same problem so started reading a book on general usage and found the glsl thing and it solved it for both. Sucks to spend two days on something that was just a one-click menu item problem :D.
Tis the nature of trial and error of troubleshooting anything technical. What you mean I spent 2 days trying to debug something only to find out I was missing a comma, :lol:
User avatar
semory
Site Admin
Posts: 7755
Joined: Sat Aug 04, 2012 7:38 pm
Custom Rank: Kitty pu tu tu lay!
Location: Torrance, CA

Re: Blender General Questions

Post by semory »

Yeah, it's like "hey, my file won't save... i keep losing my data" "oh, hey, two days later there's a File > Save menu item." Makes you feel really stupid you know :D. And to top it all off, szkaradek (the guy who writes blender scripts on xentax) responded to the question I sent him last Friday today (of course, after I finally figured it out :D).
Post Reply