SetMeshMaterial

Everything related to 3D programming
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

SetMeshMaterial

Post by Polo »

Does this function really work with submeshes?

I'm trying to use it but the final mesh remains white.
If I specify the same material when attaching the mesh to the entity then the mesh is textured.

I'm basically doing:

Code: Select all

mesh=CreateMesh(#PB_Any)
AddSubMesh()
SetMeshMaterial(mesh,materialID,0)

-- vertices/faces --


FinishMesh()
UpdateMeshBoundingBox(mesh)
entity = CreateEntity(#PB_Any,MeshID(mesh),#PB_Material_None)
Wherever I put the SetMeshMaterial (before or after adding faces) it doesn't change anything.
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: SetMeshMaterial

Post by Comtois »

Try this way, after FinishMesh()

Code: Select all

mesh=CreateMesh(#PB_Any)
AddSubMesh()

-- vertices/faces --


FinishMesh()

SetMeshMaterial(mesh,materialID,0)

UpdateMeshBoundingBox(mesh)


entity = CreateEntity(#PB_Any,MeshID(mesh),#PB_Material_None)
Please correct my english
http://purebasic.developpez.com/
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: SetMeshMaterial

Post by Polo »

Thanks it works! This should be documented if possible :)
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: SetMeshMaterial

Post by Comtois »

I will add an example, may be shorter than this one :)

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - SetMeshMaterial
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 1

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

Define.f x, y, z, nx, ny, nz, u, v
Define.l Co
Define.w t1, t2, t3

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    ; Create a cube manually
    ; 
    
    ; Define all the vertices and their attributes
    CreateMesh(0)
    
    AddMeshVertex(-0.5,0.5,-0.5)
      MeshVertexTextureCoordinate(0,0)
    AddMeshVertex(0.5,0.5,-0.5)
      MeshVertexTextureCoordinate(0,1)
    AddMeshVertex(0.5,0.5,0.5)
      MeshVertexTextureCoordinate(1,1)
    AddMeshVertex(-0.5,0.5,0.5)
      MeshVertexTextureCoordinate(1,0)
      
    ; Define all the faces, based on the vertex index
    AddMeshFace(2,1,0)
    AddMeshFace(0,3,2)  
    
    AddSubMesh()      
    AddMeshVertex(-0.5,-0.5,0.5)
      MeshVertexTextureCoordinate(0,0)
    AddMeshVertex(0.5,-0.5,0.5)
      MeshVertexTextureCoordinate(0,1)
    AddMeshVertex(0.5,-0.5,-0.5)
      MeshVertexTextureCoordinate(1,1)
    AddMeshVertex(-0.5,-0.5,-0.5)
      MeshVertexTextureCoordinate(1,0)
      
    ; Define all the faces, based on the vertex index
    AddMeshFace(2,1,0)
    AddMeshFace(0,3,2) 
    
    AddSubMesh()
    AddMeshVertex(-0.5,0.5,0.5)
      MeshVertexTextureCoordinate(0,0)
    AddMeshVertex(0.5,0.5,0.5)
      MeshVertexTextureCoordinate(0,1)
    AddMeshVertex(0.5,-0.5,0.5)
      MeshVertexTextureCoordinate(1,1)
    AddMeshVertex(-0.5,-0.5,0.5)
      MeshVertexTextureCoordinate(1,0)
      
    ; Define all the faces, based on the vertex index
    AddMeshFace(2,1,0)
    AddMeshFace(0,3,2)       
      
    AddSubMesh()  
    AddMeshVertex(0.5,0.5,-0.5)
      MeshVertexTextureCoordinate(0,0)
    AddMeshVertex(-0.5,0.5,-0.5)
      MeshVertexTextureCoordinate(0,1)
    AddMeshVertex(-0.5,-0.5,-0.5)
      MeshVertexTextureCoordinate(1,1)
    AddMeshVertex(0.5,-0.5,-0.5)
      MeshVertexTextureCoordinate(1,0)
      
    ; Define all the faces, based on the vertex index
    AddMeshFace(2,1,0)
    AddMeshFace(0,3,2)       
      
    AddSubMesh()
    AddMeshVertex(-0.5,0.5,-0.5)
      MeshVertexTextureCoordinate(0,0)
    AddMeshVertex(-0.5,0.5,0.5)
      MeshVertexTextureCoordinate(0,1)
    AddMeshVertex(-0.5,-0.5,0.5)
      MeshVertexTextureCoordinate(1,1)
    AddMeshVertex(-0.5,-0.5,-0.5)
      MeshVertexTextureCoordinate(1,0)
      
    ; Define all the faces, based on the vertex index
    AddMeshFace(2,1,0)
    AddMeshFace(0,3,2)       
            
    AddSubMesh()
    AddMeshVertex(0.5,0.5,0.5)
      MeshVertexTextureCoordinate(0,0)
    AddMeshVertex(0.5,0.5,-0.5)
      MeshVertexTextureCoordinate(0,1)
    AddMeshVertex(0.5,-0.5,-0.5)
      MeshVertexTextureCoordinate(1,1)
    AddMeshVertex(0.5,-0.5,0.5)
      MeshVertexTextureCoordinate(1,0)
      
    ; Define all the faces, based on the vertex index
    AddMeshFace(2,1,0)
    AddMeshFace(0,3,2)      
            
    FinishMesh()
    NormalizeMesh(0) 
    
    UpdateMeshBoundingBox(0)
    
    ; Material
    CreateMaterial(0, LoadTexture(0, "Geebee2.bmp"))
    CreateMaterial(1, LoadTexture(1, "RustySteel.jpg"))
    CreateMaterial(2, LoadTexture(2, "Dirt.jpg"))
    CreateMaterial(3, LoadTexture(3, "Clouds.jpg"))
    CreateMaterial(4, LoadTexture(4, "Wood.jpg"))
    CreateMaterial(5, LoadTexture(5, "caisse.png"))
    
    SetMeshMaterial(0, MaterialID(0), 0)
    SetMeshMaterial(0, MaterialID(1), 1)
    SetMeshMaterial(0, MaterialID(2), 2)
    SetMeshMaterial(0, MaterialID(3), 3)
    SetMeshMaterial(0, MaterialID(4), 4)
    SetMeshMaterial(0, MaterialID(5), 5)
    
    CreateEntity(0, MeshID(0), #PB_Material_None)
    ScaleEntity(0, 200, 200, 200)
    
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 0, 0, 1000)
    
    CreateLight(0, RGB(255,255,255), 300, 600, -100)
    AmbientColor(RGB(80, 80, 80))
    
    Repeat
      Screen3DEvents()
      
      ExamineMouse()
      
      ExamineKeyboard()
              
      RotateEntity(0, 1, 1, 1, #PB_Relative)
       
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End
Please correct my english
http://purebasic.developpez.com/
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: SetMeshMaterial

Post by Polo »

Great! :)
royaltoon55
New User
New User
Posts: 1
Joined: Fri Feb 06, 2015 8:26 am

Re: SetMeshMaterial

Post by royaltoon55 »

what direction does the light look? And is there a way to rotate the light?
Other questions I have: If the light is attached to a node and the node is moved/rotated, the light is moved and rotated? (yep, in the manual they say that nodes are always rotated/moved relative to the node they're attached to, but does this work for lights, too?
John
Post Reply