Scanning Texture Baker L.O.D.

Greetings,

I have several questions for some of you that know more about Python and Blender3D than I. My questions pertain to a new script/feature proposal that is currently in the works. Before we go much further we think it would be a good idea to get some more input on this. Just to maybe spur some different directions or possibilities.

This is a proposal for a new feature in Blender3D that will allow content creators the ability to apply various Levels Of Detail or LOD to their models. This feature could also be used to capture textures from various sources within Blender3D and transfer these to a UV map.

We have written a paper on this proposal, I ask anyone knowledgeable or curious to please have a look at it. The paper can be found here. http://home.earthlink.net/~jaspermine/LODed.pdf

We would like to know what you think about this, what is wrong with it, how it could be made better or even how it can be realized. Thank-you.

jsplifer

I have a doubt on your camera script . Did you really use it ?

Yeah that’s quite nice, Model a high oly model, render it and use the renders to create a texture for the low poly model. That’s a need for the game engine. :stuck_out_tongue:

what do you mean you have a doubt on the camera script? the code that is in the proposal is old code, but it still worked

timmo

Greetings jms,

Thank-you for having a look at the paper. The code in question is slightly outdated. As well as its instructions being undocumented. You could almost call that example a proof of concept or foundation. It was not mentioned that you need a camera tracking an empty or the object having to be selected. We merely provided it as proof that this is not as far fetched as one would think. The images were created by manually positioning the camera and then applying the image as a uv to the low-poly mesh. We are trying to do this same thing, but automatically.

I am very curious though if you have more input on this, please be verbose in your doubts as this could help us clarify the discrepancies.

Sincerely
jsplifer

actually, it’s nearly possible in some ways. There is a texture baker script in blender’s script window. The only problem is, it makes my pc lock-up.
You could render the model with highpoly/subsurfs and then just take the texture.
It seems that the baker renders the image and scretches it into a texture.
I saw it once, the second time it locked up.

what do you mean you have a doubt on the camera script? the code that is in the proposal is old code, but it still worked

timmo[/quote]

1/ the name of the object (selected twice) could be different from the mesh name.
2/ method to set the position of the camera adding the faces’ normal seems very curious.

Hello,

This is an update on the LODed project.

Currently the project is forked. Ideasman has corrupted the mind of the lead developer, causing him to embark on a much longer than necessary journey, a tool that while useful, does not conform to the tool that has been proposed.

Several disturbing flaws exist in their algorithm. So this leads me to ask again if anyone with time or knowledge could please have a look at the proposal LODed from http://home.earthlink.net/~jaspermine/LODed.pdf and to drop their comments, or contributions here.

Also I include the code that positions the camera to each face, and then to the relative area on the high-poly model. I think it would be best if all the faces are tested, and the distance to the largest face being locked in order to keep the resolution of all subsequent faces equal in respect to a virtual dpi.

The script:

def maxDist(face): 
    verts = face.v; 
    if len(verts) = 4: 
        dist = distance4points(verts); 
    else: 
        dist = distance3points(verts); 

def maxDistance3points(verts = []):import Blender 
import math 
import bakingLib 
from Blender import * 
from Blender.Scene import Render 
from bakingLib import * 

selObj = Object.GetSelected()[0]; 
selObjName = selObj.getName(); 

camTrackObj = Object.Get("Track"); 
camTrackRef = camTrackObj.getName(); 

#------------------------------------------ 
# now integrated into library 

#curScene = Scene.getCurrent(); 
#sceneCam = curScene.getCurrentCamera(); 
#camName = sceneCam.getName(); 

#camObj = Object.Get(camName); 
#------------------------------------------ 

camObj = getSceneCam(); 

#------------------------------------------ 
# now integrated into library 

#meshObj = Object.GetSelected()[0]; 
#meshName = meshObj.getName(); 
#meshRaw = NMesh.GetRaw(meshName); 
#------------------------------------------ 

meshRaw = getSelMesh(); 
faces = meshRaw.faces; 

#------------------------------------------ 
# now integrated into library as object 
# 'renderer' 

#context = curScene.getRenderingContext(); 
#Render.EnableDispWin(); 
#context.enableExtensions(1); 
#context.setRenderPath("C:/myRenderdir/"); 
#context.sizePreset(Render.PC); 
#context.startFrame(1); 
#context.endFrame(1); 
#------------------------------------------ 

renderHandle = renderer(); 
renderHandle.initRender; 

norms = [] 
camPos = [] 

for face in faces: 
    norms.append(face.normal); 
    camPos.append([i*2.207 for i in face.normal]); 

for index in range(len(camPos)): 
    camTrackObj.setLocation(norms[index][0],norms[index][1],norms[index][2]); 
    camObj.setLocation(camPos[index][0],camPos[index][1],camPos[index][2]); 
    renderHandle.doRender(); 
    Redraw();

The module:

import Blender 
from Blender import * 
from Blender.Scene import Render 
import math 

def hypotenuseLength(face): 
    verts = face.v 
    maxLength = 0 
    for x in range(verts): 
        for y in range(verts): 
            dist = distance3Points(verts[x],verts[y]) 
            if dist > maxLength: 
                maxLength = dist; 

def distance2Points(vector1 = [],vector2 = []): 
    differenceVector = [vector1[i] - vector2[i] for i in range(vector1)]; 
    vectorLength = pythagoras3D(differenceVector); 

def pythagoras3D(vector = []): 
    sqrVector = [i * i for i in vector]; 
    sqrTotal = reduce(lambda x, y: x + y, sqrVector); 
    total = sqrTotal ** 0.5; 

def getSceneCam (): 
    """Returns the object that the currently active camera is linked to.""" 
    print "" 
    print "Camera -----------------------------------" 
    curScene = Scene.getCurrent(); 
    print "Scene :",curScene 
    sceneCam = curScene.getCurrentCamera(); 
    camName = sceneCam.getName(); 
    print "Current Camera :", camName 
    camObj = Object.Get(camName); 
    print "Camera Object :", camObj 
    print "------------------------------------------" 
    return camObj 

#---------------------------------------------------
#More suitable replacement by jms below.
#
#def getSelMesh (): 
#    """Returns the raw mesh linked to the currently selected object.""" 
#    meshObj = Object.GetSelected()[0]; 
#    meshName = meshObj.getName(); 
#    meshRaw = NMesh.GetRaw(meshName); 
#    return meshRaw
#---------------------------------------------------

def getSelMesh (): 
   """Returns the raw mesh linked to the currently selected object.""" 
   return  Blender.Object.GetSelected()[0].getData(); 
 

class renderer: 
    """Creates an object to deal with all rendering in a predetermined way.""" 
    def __init__ (self): 
        self.curScene = Scene.getCurrent(); 
        self.context = self.curScene.getRenderingContext(); 
        print "Render initialised" 

    def initRender (self): 
        """Set up render parameters.""" 
        Render.EnableDispWin(); 
        self.context.enableExtensions(1); 
        self.context.setRenderPath("C:/myRenderdir/"); 
        self.context.sizePreset(Render.PC); 
        self.context.startFrame(1); 
        self.context.endFrame(1); 

    def doRender (self,completion=0): 
        """Render current scene.""" 
        print "Rendering ", (completion * 100),"%"     
        print completion 
        self.context.render(); 
        Render.CloseRenderWindow

Thank you,
jsplifer

you should read my message and rewrite this funcion :

def getSelMesh ():
“”“Returns the raw mesh linked to the currently selected object.”""
meshObj = Object.GetSelected()[0];
meshName = meshObj.getName();
meshRaw = NMesh.GetRaw(meshName);
return meshRaw

jms,

I read what you are saying, and I see where it should be changed. However I am no coder. I am just a wisher of such feature…

If you have the time, please feel free to change it, and to post an update.

sincerely
jsplifer

could be something like this:


def getSelMesh ():
   """Returns the raw mesh linked to the currently selected object."""
   return  Blender.Object.GetSelected()[0].getData();

jms,

Updated the script above.

appreciatively yours,
jsplifer

just “could be” . You have to test it before …