texturing a model?
texturing a model?
Hi,
Are there any resources around on how to texture a model in the 3d engine?
If I used a simple cube with a texture loaded into on a material all is fine
If I model something in a 3d program, convert it to a .mesh and load it I can't get a texture to sit on it properly.
I'm not doing anything complicated with UV or anything yet but I want to go there later. just getting a brick wall texture and putting it on a house mesh just turns the house brick colour (no brick edges). I've tried material scaling up and down (works on the cube) but I cant get any bricks visible on the house (regardless of alignment or anything)
I thought I might have just been zoomed in or out too far but that doesn't seem to be the case.
Should I be doing something in the 3d software before I convert it?
Are there any resources around on how to texture a model in the 3d engine?
If I used a simple cube with a texture loaded into on a material all is fine
If I model something in a 3d program, convert it to a .mesh and load it I can't get a texture to sit on it properly.
I'm not doing anything complicated with UV or anything yet but I want to go there later. just getting a brick wall texture and putting it on a house mesh just turns the house brick colour (no brick edges). I've tried material scaling up and down (works on the cube) but I cant get any bricks visible on the house (regardless of alignment or anything)
I thought I might have just been zoomed in or out too far but that doesn't seem to be the case.
Should I be doing something in the 3d software before I convert it?
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: texturing a model?
Let Add3DArchive() point to your mesh-, material script- and texture locations.
Then use
Load the mesh
Create the entity
Set the materialID to #PB_Material_None.
Like this:
That should do it.
Then use
Code: Select all
Parse3DScripts()
Create the entity
Set the materialID to #PB_Material_None.
Like this:
Code: Select all
CreateEntity(EntID, MeshID(YourMesh), #PB_Material_None, Posx, posy, posz)
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Re: texturing a model?
Thanks for the help but No joy,
I'm using Parse3DScripts() but I added it again after the texture was loaded to try it but it didn't change anything.
Running with #PB_Material_None instead looks different so something is loading but nothing gets fixed.
The model was an stl file, after I put it through the OgreAssimpConverter it output a .mesh and a .material file. I load the .mesh with loadmesh, the material file is in the 3D archive but I don't do anything with it... should I? I gues it's like that font prop file that gets called when you use 3dfonts. There isn't much in it and when the .material file is not there nothing looks different.
I tried creating the entity with no material, then loading it but nothing really changed.
code is below, this is not a serious app, I'm trying to proof of concept how to do this so I can write a guide on how to do this end to end.
I'm using Parse3DScripts() but I added it again after the texture was loaded to try it but it didn't change anything.
Running with #PB_Material_None instead looks different so something is loading but nothing gets fixed.
The model was an stl file, after I put it through the OgreAssimpConverter it output a .mesh and a .material file. I load the .mesh with loadmesh, the material file is in the 3D archive but I don't do anything with it... should I? I gues it's like that font prop file that gets called when you use 3dfonts. There isn't much in it and when the .material file is not there nothing looks different.
I tried creating the entity with no material, then loading it but nothing really changed.
code is below, this is not a serious app, I'm trying to proof of concept how to do this so I can write a guide on how to do this end to end.
Code: Select all
;Initialise
InitEngine3D()
Add3DArchive(GetCurrentDirectory()+"\3d",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
AntialiasingMode(#PB_AntialiasingMode_x6)
Width = 2400
Height = 1200
;create window
If OpenWindow(0, 0, 0, Width, Height+MenuHeight(), "Ryan's 3D", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateMenu(0, WindowID(0))
Result = OpenWindowedScreen(WindowID(0), 0, 0, Width, Height, 0, 0, 0)
EndIf
WorldShadows(#PB_Shadow_Additive , 1000 )
;Mesh
mshRoom = LoadMesh(#PB_Any,"room_stl.mesh")
BuildMeshShadowVolume(mshRoom)
cu = CreateCube(#PB_Any,50)
;texture, material
tx = LoadTexture(#PB_Any,"soil_wall.jpg")
cutx = LoadTexture(#PB_Any,"caisse.png")
cumat = CreateMaterial(#PB_Any,TextureID(cutx))
mat = CreateMaterial(#PB_Any,TextureID(tx))
;Entity
cu_ent = CreateEntity(#PB_Any,MeshID(cu),MaterialID(cumat))
MoveEntity(cu_ent,0,-110,0)
ent = CreateEntity(#PB_Any,MeshID(mshRoom),MaterialID(mat))
; ent = CreateEntity(#PB_Any,MeshID(mshRoom),#PB_Material_None)
; SetEntityMaterial(ent, MaterialID(mat))
MoveEntity(ent,0,-300,0)
;Lights
lit1 = CreateLight(#PB_Any,RGB(50,50,50),-100,50,50)
lit3 = CreateLight(#PB_Any,RGB(120,120,120),-100,0,0)
MoveLight(lit3,500,200,200,#PB_Relative)
DisableLightShadows(lit3, #False)
;Camera
cam = CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(cam, 0, 200, 900, #PB_Absolute)
RotateCamera(cam,-20,0,0)
RotateEntity(ent, -90,0, 0, #PB_Absolute)
;Event Loop
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
ExamineKeyboard()
RotateEntity(ent, 0, 0, 0.3, #PB_Relative)
RotateEntity(cu_ent, 2, 2, 2, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: texturing a model?
I created a new model, just a simple cube as an STL and ran it through the converter etc and tried it...
same thing, tried the same material that's on the createcube() cube and I get a blue cube. (not the standard caisse.png image) I suspected a scaling issue of the texture but tried lots of scalematerial up and down but nothing. I'd hoped that it was just being caused by the additiona complexity of the model.
Results are that I put a material on an STL model I get one colour of the material all over it.
same thing, tried the same material that's on the createcube() cube and I get a blue cube. (not the standard caisse.png image) I suspected a scaling issue of the texture but tried lots of scalematerial up and down but nothing. I'd hoped that it was just being caused by the additiona complexity of the model.
Results are that I put a material on an STL model I get one colour of the material all over it.
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: texturing a model?
Try radically changing the size of your cube.
Re: texturing a model?
same.
maybe I'm barking up the wrong tree here, perhaps I should start looking for a PB UV map tutorial and do this that way.
maybe I'm barking up the wrong tree here, perhaps I should start looking for a PB UV map tutorial and do this that way.
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
-
- Addict
- Posts: 2228
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: texturing a model?
There are many approaches how you can map a texture on an object. The most common way is to specify UV coordinates for each vertex. Without these being specified you'll get the effect you've described: "just turns the house brick colour (no brick edges)". The engine assumes all UV coordinates are @ (0.0, 0.0), so the very first pixel inside the texture will be taken.pdwyer wrote:Hi,
Are there any resources around on how to texture a model in the 3d engine?
If I used a simple cube with a texture loaded into on a material all is fine
If I model something in a 3d program, convert it to a .mesh and load it I can't get a texture to sit on it properly.
I'm not doing anything complicated with UV or anything yet but I want to go there later. just getting a brick wall texture and putting it on a house mesh just turns the house brick colour (no brick edges). I've tried material scaling up and down (works on the cube) but I cant get any bricks visible on the house (regardless of alignment or anything)
I thought I might have just been zoomed in or out too far but that doesn't seem to be the case.
Should I be doing something in the 3d software before I convert it?
However there are other approaches. You could e.g. map the world's (x, y) coordinates to the (u, v) texture space and repeat the texture. This will result in two of the sides of an axis aligned cube being textured, however the other ones will look bad. There are more mapping methods, however it always results in UV coordinates in texture space.
bye,
Daniel
Daniel
Re: texturing a model?
I am writing a .obj/.mtl parser for my own use in PB... the texturing seems to be the tricky part hehe
Proud supporter of PB! * Musician * C64/6502 Freak
Re: texturing a model?
Daniel,
Regarding you comment:
Should I extract the mesh to an array, set these points with values and then load them back? (save it like that for next time perhaps as my own mesh format).
What do I put in these values, the equivalent vertex coords from the 2d texture I'm going to load? That will hard to know what the datapoints are in the mesh...
Should I be using the array of faces instead and set them to something
I'm having trouble finding any information on how to do all this. I guess if ogre uses the same function names as PB has wrappers I could look at their docs??
Regarding you comment:
I'm having trouble finding much detail on how to do this. not much under texture or material functions. Under Mesh there is a SetMeshData() and GetMeshData() function and the structure has the U and V parts.The most common way is to specify UV coordinates for each vertex
Should I extract the mesh to an array, set these points with values and then load them back? (save it like that for next time perhaps as my own mesh format).
What do I put in these values, the equivalent vertex coords from the 2d texture I'm going to load? That will hard to know what the datapoints are in the mesh...
Should I be using the array of faces instead and set them to something
I'm having trouble finding any information on how to do all this. I guess if ogre uses the same function names as PB has wrappers I could look at their docs??
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Re: texturing a model?
joining some dots...
On the comment earlier,
"Set the materialID to #PB_Material_None."
I set this again now as I found that you can add a material into the .material file and it seems to load. it still doesn't look any better but the colour changes when I set the material file so I know it's reading it.
Material file looks like this now: (there was no texture before)
I'm looking through other material files for ideas and checking ogre info here for details on params
https://www.ogre3d.org/docs/manual18/ma ... ml#texture
getting closer but it's not quite there.
If the material is loaded this way, how do I get to it to scale it? There is a "GetMaterialFromMesh()" that I can see to call this to scale it
On the comment earlier,
"Set the materialID to #PB_Material_None."
I set this again now as I found that you can add a material into the .material file and it seems to load. it still doesn't look any better but the colour changes when I set the material file so I know it's reading it.
Material file looks like this now: (there was no texture before)
Code: Select all
material skcube_stl#0
{
technique
{
pass
{
ambient 0.05 0.05 0.05 1
diffuse 1 1 1 1
specular 1 1 1 1
texture_unit
{
texture caisse.png
}
}
}
}
https://www.ogre3d.org/docs/manual18/ma ... ml#texture
getting closer but it's not quite there.
If the material is loaded this way, how do I get to it to scale it? There is a "GetMaterialFromMesh()" that I can see to call this to scale it
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
-
- Addict
- Posts: 2228
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: texturing a model?
Hello,
Usually you'd go into the model editor and unwrap the model into texture space and manually optimize the unwrapping. This video shows you how to do UV unwrapping with blender and you'll get a basic understanding what UV coordinates are: https://www.youtube.com/watch?v=Y7M-B6xnaEM
You could also use shaders and calculate the UV coordinates on the fly, but I think this is more advanced right now.
Kind regards,
Daniel
Usually you'd go into the model editor and unwrap the model into texture space and manually optimize the unwrapping. This video shows you how to do UV unwrapping with blender and you'll get a basic understanding what UV coordinates are: https://www.youtube.com/watch?v=Y7M-B6xnaEM
You could also use shaders and calculate the UV coordinates on the fly, but I think this is more advanced right now.
Kind regards,
Daniel
bye,
Daniel
Daniel
Re: texturing a model?
"the model editor" ?
There is a modelling editor?
I have blender and know the basics. I understand what is involved in UV mapping but I haven't done much of it. I used to work with sketchup quite a bit and as a test of their web version created the stl files there.
Perhaps I'm used to programs like sketchup and blender babying me but generally if you have a cube and a square texture it figures it out for you... or if not, you can see it tiling and can adjust scale.
If I do this in blender, how do I get the material files? are they correct based on the conversion software?
In this case, I don't seem to have any leavers to pull to fix it from code or config files or scripts and PB included documentation is a couple of lines of text with a function and sometimes some example code. Where there is no example code I don't know if PB function names map to similarly named ogre functions so that I can look them up and port the concept.
Which is why I'm doing this, to put a guide together on how it works. I have no idea how PB made that robot mesh, I don't know how they mapped the material, I don't know if there is some hidden file the Parse3DScripts() reads to UVmap it. The .material files are not mentioned in docs or called in code.
It's pretty unfriendly but looks powerful PB is powerful so I'm trying to keep at it. I suspect a lot of people give up though which is a shame.
There is a modelling editor?
I have blender and know the basics. I understand what is involved in UV mapping but I haven't done much of it. I used to work with sketchup quite a bit and as a test of their web version created the stl files there.
Perhaps I'm used to programs like sketchup and blender babying me but generally if you have a cube and a square texture it figures it out for you... or if not, you can see it tiling and can adjust scale.
If I do this in blender, how do I get the material files? are they correct based on the conversion software?
In this case, I don't seem to have any leavers to pull to fix it from code or config files or scripts and PB included documentation is a couple of lines of text with a function and sometimes some example code. Where there is no example code I don't know if PB function names map to similarly named ogre functions so that I can look them up and port the concept.
Which is why I'm doing this, to put a guide together on how it works. I have no idea how PB made that robot mesh, I don't know how they mapped the material, I don't know if there is some hidden file the Parse3DScripts() reads to UVmap it. The .material files are not mentioned in docs or called in code.
It's pretty unfriendly but looks powerful PB is powerful so I'm trying to keep at it. I suspect a lot of people give up though which is a shame.
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
-
- Addict
- Posts: 2228
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: texturing a model?
Oh sorry, I thought you made the mesh in a modeling tool, as you stated in your first post:pdwyer wrote:"the model editor" ?
There is a modelling editor?
pdwyer wrote:If I used a simple cube with a texture loaded into on a material all is fine
If I model something in a 3d program, convert it to a .mesh and load it I can't get a texture to sit on it properly.
Blender is really powerful. You can tell it how to determine the UV coordinates by specifying the source of them, e.g. the object's xy plane or something else. However you would probably want to generate UV coordinates and then export it to an OGRE mesh. This mesh will contain the UV coordinates. The material file will not. The material just tells how to render a object on a more global level. But if you don't have UV coordinates at all, you can just use environmental mapping (which calculates the UV coordinates based on the environment) or one pixel of your texture over the whole object. This is why your objects only colorize according to exactly one corner pixel of your texture and you don't see actual bricks with edges etc. For experiments you can change that corner pixel's color in paint to see which one it actually is. I guess the top left one.pdwyer wrote:I have blender and know the basics. I understand what is involved in UV mapping but I haven't done much of it. I used to work with sketchup quite a bit and as a test of their web version created the stl files there.
Perhaps I'm used to programs like sketchup and blender babying me but generally if you have a cube and a square texture it figures it out for you... or if not, you can see it tiling and can adjust scale.
I did this quite a few times for PB ogre and I really liked how easy it was to export the mesh.pdwyer wrote:If I do this in blender, how do I get the material files? are they correct based on the conversion software?
The PB OGRE implementation is a rough abstraction of the real OGRE functionality. You still need to know a lot before starting with 3D development, even with PB's abstraction. The general concepts aren't documented within the PB documentation. It would at least double the size of the complete documentation.pdwyer wrote:In this case, I don't seem to have any leavers to pull to fix it from code or config files or scripts and PB included documentation is a couple of lines of text with a function and sometimes some example code. Where there is no example code I don't know if PB function names map to similarly named ogre functions so that I can look them up and port the concept.
I think this robot mesh was created with milkshape 3d in the old days, however I'm not sure. In these times milkshape was the only tool with a nice OGRE converter. Today I would really recommend blender.pdwyer wrote:Which is why I'm doing this, to put a guide together on how it works. I have no idea how PB made that robot mesh, I don't know how they mapped the material, I don't know if there is some hidden file the Parse3DScripts() reads to UVmap it. The .material files are not mentioned in docs or called in code.
It's pretty unfriendly but looks powerful PB is powerful so I'm trying to keep at it. I suspect a lot of people give up though which is a shame.
[EDIT] oops forgot to comment the last quote.
Last edited by DarkDragon on Tue May 26, 2020 2:03 pm, edited 1 time in total.
bye,
Daniel
Daniel
Re: texturing a model?
@pdwyer , you are converting STL files to Ogre mesh, but STL files does not have texture mapping info (u,v) by specifications look here:
https://blender.stackexchange.com/quest ... d-stl-file
The STL file format doesn't support textures, its a geometry only file format suited for 3D printing and computer based fabrication processes
this is why OgreAssimpConverter convert your STL files to ogre mesh *.mesh without uv info
i suggest this practical approach for converting the STL model to Ogre *.mesh which accepts texturing:
1- export your stl files to wavefront *.OBJ model use any software, such as the freeware MeshLab or blender
2- Load the OBJ file to the freeware UVMapper Classic from http://www.uvmapper.com/downloads.html
3- it will not show the model yet but a message "this object has no UV texture coordinates use Edit -> New UV Map to create some
4- press Edit -> new UV map -> planar , accept the defaults (i don't have info about what these do)
5- now the model appears on the screen, save the model with other name of type .OBJ
6- now if you drop the OBJ file in notepad you will see many lines begins with vt (this is for vertex texture coordinates)
now you can convert the OBJ file with OgreAssimpConverter , copy the resulted *.mesh with the accossciated material file to the PureBasic\Examples\3D\Data\Models folder
and run the mesh.pb example replace the robot.mesh with your mesh, and comment line 49 ScrollMaterial(..)
use the texture MRAMOR6X6.jpg from the texture folder
it is displayed with texture, albeit some errors but you will have an idea. i don't know how to fine tune the things.
i suggest to use the DarkDragon suggestions for precision texturing .
good luck
https://blender.stackexchange.com/quest ... d-stl-file
The STL file format doesn't support textures, its a geometry only file format suited for 3D printing and computer based fabrication processes
this is why OgreAssimpConverter convert your STL files to ogre mesh *.mesh without uv info
i suggest this practical approach for converting the STL model to Ogre *.mesh which accepts texturing:
1- export your stl files to wavefront *.OBJ model use any software, such as the freeware MeshLab or blender
2- Load the OBJ file to the freeware UVMapper Classic from http://www.uvmapper.com/downloads.html
3- it will not show the model yet but a message "this object has no UV texture coordinates use Edit -> New UV Map to create some
4- press Edit -> new UV map -> planar , accept the defaults (i don't have info about what these do)
5- now the model appears on the screen, save the model with other name of type .OBJ
6- now if you drop the OBJ file in notepad you will see many lines begins with vt (this is for vertex texture coordinates)
now you can convert the OBJ file with OgreAssimpConverter , copy the resulted *.mesh with the accossciated material file to the PureBasic\Examples\3D\Data\Models folder
and run the mesh.pb example replace the robot.mesh with your mesh, and comment line 49 ScrollMaterial(..)
use the texture MRAMOR6X6.jpg from the texture folder
it is displayed with texture, albeit some errors but you will have an idea. i don't know how to fine tune the things.
i suggest to use the DarkDragon suggestions for precision texturing .
good luck
Re: texturing a model?
Thanks!
This gives me lots of things to try
with a quick check, abandoning STL files seems to be getting results. .dea seems to work better
nice tip on that
This gives me lots of things to try
with a quick check, abandoning STL files seems to be getting results. .dea seems to work better
nice tip on that
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein