2008/11/27 Aleksandar Kordic <ale...@gm...>:
> Hi,
>
> My project is simple simulation of robot movement on rectangular
> board. I used Frame from d3dx and StaticMesh from d3d module. So far
> only one model is presented in scene.
> Problem is that textures from .x file are not shown in scene. Am I
> doing something wrong in onRender() method ?
>
> def onRender(self):
> d3d.setView(self.eye, self.lookat, 6000.0, 0.7853)
> d3d.setState(RS.LIGHTING, True)
> d3d.setState(RS.AMBIENT, 0xffffffff)
> d3d.setState(RS.SPECULARENABLE, True)
>
> d3d.setLight(0, LIGHT.DIRECTIONAL, 0xffffffff, 500.0, (0.0, 100.0,
> 0.0), (0.3, -1.0, 0.3), 0.4, 0.4)
> d3d.setLight(1, LIGHT.DIRECTIONAL, 0xffffffff, 500.0, (200.0,
> -300.0, 0.0), (0.5, 0.5, 0.1), 0.4, 0.4)
> d3d.setState(RS.FILLMODE, RS.FILL.SOLID)
>
> d3d.setTransform( element.translation, element.rotation, element.scaling )
> d3d.setState(RS.USEMESHMATERIALS, True)
> element.mesh.render() #time_passed) - not for static mesh
>
> d3d.setState(RS.FILLMODE, RS.FILL.SOLID)
> self.manager.render(self.elapsedtime)
>
> Strange thing is that same model opened with 'MeshViewer.py' sample
> does not show textures, while DXViewer.exe (from directx sdk) loads
> textures properly.
>
> Textures in .x file are referenced as files
> example :
> Material Wood_OSB1{
> 0.392156862745098;1.0;0.392156862745098;1.0;;
> 3.2;
> 0.000000;0.000000;0.000000;;
> 0.000000;0.000000;0.000000;;
> TextureFilename { "teren.xWood_OSB.jpg"; }
> }
>
> Is it possible that d3d.StaticMesh does not load properly from '.x'
> file ? If so how can I contribute to fix this ?
>
> Best Regards,
> Alex
>
As you noticed, StaticMesh does not load any textures. Internally the
mesh object uses basic D3DX-functions and interfaces which don't
support it. The more complex interfaces (ID3DXFile etc.) require much
more processing which is not usually needed. Actually, it is almost
easier to write a simple .x-parser in Python than to create fully
supported C++-loader with those interfaces. They are flexible, but
also quite complex.
It is quite common to use .x-files to only store geometry (etc.) data
and use some other file format to store other information. For example
a simple text file could specify information about an object, like
it's physical abilities textures and approriate .x-files (if it is a
composite shape or something). When you need to load an object you
just process this file and load all needed resources.
--
Heikki Salo
|