Exemplo n.º 1
0
def ExportCoordInterface(rm,loc,blObj,so):
    ci = plCoordinateInterface(blObj.name)
    rm.AddObject(loc,ci)
    ci.owner = so.key
    #matrix fun
    l2w = utils.blMatrix44_2_hsMatrix44(blObj.matrix_local)
    ci.localToWorld = l2w
    ci.localToParent = l2w
    matcopy = blObj.matrix_local.__copy__()
    matcopy.invert()
    w2l = utils.blMatrix44_2_hsMatrix44(matcopy)
    ci.worldToLocal = w2l
    ci.parentToLocal = w2l
    return ci
Exemplo n.º 2
0
def ExportCoordInterface(rm, loc, blObj, so):
    ci = plCoordinateInterface(blObj.name)
    rm.AddObject(loc, ci)
    ci.owner = so.key
    #matrix fun
    l2w = utils.blMatrix44_2_hsMatrix44(blObj.matrix_local)
    ci.localToWorld = l2w
    ci.localToParent = l2w
    matcopy = blObj.matrix_local.__copy__()
    matcopy.invert()
    w2l = utils.blMatrix44_2_hsMatrix44(matcopy)
    ci.worldToLocal = w2l
    ci.parentToLocal = w2l
    return ci
Exemplo n.º 3
0
def ExportLamp(rm, loc, blObj, sceneobject):
    lamp = blObj.data
    if lamp.type == "POINT":
        print(" [OmniLight]")
        light = plOmniLightInfo(blObj.name)
        setSharedLampAndSpotSettings(lamp, light)
    elif lamp.type == "SPOT":
        print(" [SpotLight]")
        light = plSpotLightInfo(blObj.name)
        setSharedLampAndSpotSettings(lamp, light)

        spotsize = lamp.spot_size
        light.spotOuter = spotsize
        blend = lamp.spot_blend
        if blend == 0: #prevent divide by zero later on
            blend = 0.001
        light.spotInner = spotsize-(blend*spotsize)
        if lamp.use_halo:
            light.falloff = lamp.halo_intensity
        else:
            light.falloff = 1.0
    elif lamp.type == "SUN":
        print(" [DirectionalLight]")
        light = plDirectionalLightInfo(blObj.name)
    else:
        raise Exception("Unsupported Lamp Type %s"%lamp.type)
    #do stuff that's needed for every type of light
    if rm: #allow us to run this on something other than age export
        light.owner = sceneobject.key
        light.sceneNode = rm.getSceneNode(loc).key
        rm.AddObject(loc,light)
    # Determine negative lighting....
    if lamp.use_negative:
        print("  >>>Negative light<<<")
        R = 0.0 - lamp.color[0]
        G = 0.0 - lamp.color[1]
        B = 0.0 - lamp.color[2]
    else:
        R = lamp.color[0]
        G = lamp.color[1]
        B = lamp.color[2]

    # Plasma has the same Lights as DirectX:
    #

    energy = lamp.energy * 2

    # Diffuse:
    if lamp.use_diffuse:
        print("  Diffuse Lighting Enabled")
        light.diffuse=hsColorRGBA(R*energy,G*energy,B*energy,1.0)
    else:
        print("  Diffuse Lighting Disabled")
        light.diffuse=hsColorRGBA(0.0,0.0,0.0,1.0)


    # Specular
    if lamp.use_specular:
        print("  Specular Lighting Enabled")
        light.specular=hsColorRGBA(R*energy,G*energy,B*energy,1.0)
    else:
        print("  Specular Lighting Disabled")
        light.specular=hsColorRGBA(0.0,0.0,0.0,1.0)

    # Ambient:
    # Light not directly emitted by the light source, but present because of it.

    # If one wants to use a lamp as ambient, disable both diffuse and specular colors
    # Else, it's just set to 0,0,0 aka not used.

    if not lamp.use_specular and not lamp.use_diffuse:
        print("  Lamp is set as ambient light")
        light.ambient = hsColorRGBA(R * energy, G * energy, B * energy,1.0)
    else:
        light.ambient = hsColorRGBA(0.0, 0.0, 0.0, 0.0)

    #matrix fun
    l2w = utils.blMatrix44_2_hsMatrix44(blObj.matrix_local)
    light.lightToWorld = l2w
    matcopy = blObj.matrix_local.__copy__()
    matcopy.invert()
    w2l = utils.blMatrix44_2_hsMatrix44(matcopy)
    light.worldToLight = w2l
    return light
Exemplo n.º 4
0
 def AddBlenderMeshToDSpans(self, dspansind, blObj, mesh, hasCI, vos):
     material_keys = vos.materials
     light_keys = vos.lights
     hasvtxcolor = (set(mesh.vertex_colors.keys()) & set(colour_names) != set())
     hasvtxalpha = (set(mesh.vertex_colors.keys()) & set(alpha_names) != set())
     
     #autobake if we don't have a vertex color channel
     if not hasvtxcolor:
         print("Baking Vertex Colors...")
         auto_bake_paint = mesh.vertex_colors.get("autobake")
         if not auto_bake_paint:
             auto_bake_paint = mesh.vertex_colors.new("autobake")
         amb = tuple(bpy.context.scene.world.ambient_color)
         lights.set_vertex_color(auto_bake_paint, amb)
         for lightkey in light_keys.values():
             lights.light_mesh(blObj.data, blObj.matrix_world, lightkey.object, auto_bake_paint)
 
     dspans,buffergroupinfos = self.dspans_list[dspansind]
     bufferverts,inds_by_material = DigestBlMesh(mesh)
     icicle_inds = []
 
     for matindex in inds_by_material:
         print("Adding geometry associated with %s"%mesh.materials[matindex].name)
         verts, inds = GetPlasmaVertsIndsBoundsByMaterial(bufferverts, inds_by_material, matindex)
         print("  Verts: %i"%len(verts))
         print("  UVW layers: %i"%len(mesh.uv_textures))
         buffergroup_index = self.FindOrCreateBufferGroup(dspansind,len(mesh.uv_textures),len(verts))
         print("  Buffer Group Index: %i"%buffergroup_index)
         bg = dspans.bufferGroups[buffergroup_index]
         
         vert_offset = len(buffergroupinfos[buffergroup_index].verts_to_be_written)
         inds_offset = len(buffergroupinfos[buffergroup_index].inds_to_be_written)
         buffergroupinfos[buffergroup_index].verts_to_be_written.extend(verts)
         buffergroupinfos[buffergroup_index].inds_to_be_written.extend([i+vert_offset for i in inds])
         #create our icicle
         ice = plIcicle()
         #transformations
         if hasCI:
             #just put some identities in
             ice.localToWorld = hsMatrix44()
             ice.worldToLocal = hsMatrix44()
         else:
             #we need the transform
             l2w = utils.blMatrix44_2_hsMatrix44(blObj.matrix)
             ice.localToWorld = l2w
             matcopy = blObj.matrix.__copy__()
             matcopy.invert()
             w2l = utils.blMatrix44_2_hsMatrix44(matcopy)
             ice.worldToLocal = w2l
         #buffergroup stuff
         ice.groupIdx = buffergroup_index
         ice.VLength = len(verts)
         ice.VStartIdx = vert_offset
         ice.ILength = len(inds)
         ice.IStartIdx = inds_offset
         #find or create material
         matkey = material_keys[mesh.materials[matindex]]
         if matkey in dspans.materials:
             print("Already have it.")
         else:
             dspans.addMaterial(matkey)
         ice.materialIdx = dspans.materials.index(matkey)
         #set flags
         if hasvtxalpha:
             ice.props |= plSpan.kLiteVtxNonPreshaded
             #start of some hacky stuff
             gmat = hsGMaterial.Convert(matkey.object)
             for layerkey in gmat.layers:
                 layer = plLayerInterface.Convert(layerkey.object)
                 material.SetLayerFlagsAlpha(layer)
         #lights
         blmat = mesh.materials[matindex]
         if not blmat.use_shadeless:
             ice.props |= plSpan.kPropHasPermaLights
             for lightkey in light_keys.values(): #to do: check for lightgroup
                 print("Appending light %s"%lightkey.name)
                 ice.addPermaLight(lightkey)
         #finish up
         dspans.addIcicle(ice)
         icicle_inds.append(len(dspans.spans)-1)
     #deal with the DIIndex
     di_ind_obj = plDISpanIndex()
     di_ind_obj.indices = icicle_inds
     dspans.addDIIndex(di_ind_obj)
     return dspans,(len(dspans.DIIndices)-1)