Help creating my own meshes

About Monkey 2 Forums Monkey 2 Programming Help Help creating my own meshes

Tagged: ,

This topic contains 9 replies, has 2 voices, and was last updated by  Ethernaut 1 year, 8 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #9847

    Ethernaut
    Participant

    I’m trying to create a 3D mesh from scratch, so I started with a simple “grid” object. For some reason, it doesn’t seem to apply the material correctly, and doesn’t receive shadows either. In this example code, if you comment out the line that uses the “CreateGrid” function and uncomment the line with “Mesh.CreateBox” you can see how create grid doesn’t work.

    I looked at the mesh creation functions in the “meshprims.monkey2” file inside mojo3d, and can’t figure out why my function doesn’t work but functions like Mesh.CreateSphere and Mesh.CreateTorus do. Just like those, I’m creating a vertex list and an index (faces) list and using those to return a new mesh.

    <edit> Argh! WordPress is refusing to let me post the code (“Unsafe operation” or something like that)… will keep trying.

    #9848

    Ethernaut
    Participant

    Sorry, can’t post the code… getting a “403 Forbidden:A potentially unsafe operation has been detected in your request to this site.” error.

    Has anyone else had this problem?

    #9849

    Mark Sibly
    Keymaster

    Have you tried attaching code or zip of code?

    If that’s not working, can you email code to me? blitzmunter at gmail dot com

    #9855

    Ethernaut
    Participant
    #9856

    Mark Sibly
    Keymaster

    Ok, main problem seems to be that it lacked texture coordinates and normals.

    I’m not 100% sure why this is affecting shadows so much though. There is a bit of hack in the shaders that moves points ‘off’ surfaces in the direction of the normal when comparing shadow depth, but it should still work with no normals. Will eventually investigate.

    Alas there is no UpdateNormals() yet so you need to manually create them – easy in this case though as they are all the same, ie: 0,0,-1.

    Also, for UpdateTangents to work a mesh must have both valid normals AND texture coordinates. Tangents are only used for bumpmapping though, so not strictly neccesary in this case.

    Sorry I haven’t been able to spend more time on the 3d lately everyone. IAP is *nearly* finished so I should be back into it soon.

    Anyway, here’s a version that works for me….

    #9857

    Mark Sibly
    Keymaster

    Actually, for now at least, all meshes that use PbrMaterial are gonna need texcoords, normals and tangents. Will add a simpler non-bumpy PBR style material in future.

    #9859

    Ethernaut
    Participant

    Got it. For some reason I didn’t realize you can just add those extra channels in the Vertex class itself.
    Actually, how to manipulate UVs would be my next question, so that covers it as well! 🙂

    Cheers!

    #9861

    Ethernaut
    Participant

    Question: naming wise, wouldn’t it be more clear to name the texture arguments “u” and “v”, instead of “s” and “t”, since most CG artists refer to texture coordinates as UV coordinates, or just UVs?

    #9869

    Mark Sibly
    Keymaster

    I use s,t,p,q for texture coordinates because that’s what opengl/glsl use.

    If it’s a huge hassle I can change it I guess, or even add u ,v, overloads?

    #9878

    Ethernaut
    Participant

    It’s good as is, makes more sense to be familiar to programmers who know OpenGL than to artists learning programming. Thanks!

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.