Results 1 to 9 of 9

Thread: Avoid importing the same mesh into the scene?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    8

    Avoid importing the same mesh into the scene?

    Hi all,
    I am very new to opengl.
    I managed to import an object but i wish to reuse that MEsh for other instance object in my game... (As there are many of the same geometry mesh in the scene).

    How can i do so without keep importing the same mesh into the scene?

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Avoid importing the same mesh into the scene?

    Import it only once.
    In fact I don't see why you would do differently.

    Or maybe I misunderstood your question ?

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    8

    Re: Avoid importing the same mesh into the scene?

    I have multiple objects of the same geometry.
    And What i did now is that for each objs, when i am in the display() function, i call a loop which loops thru each of the objects and load the geometry.

    I find it resources wasteful because the geometry are the same... except that the rotation and translation are different.

    Hence, i wish some experts to advice me how i can deal with this?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: Avoid importing the same mesh into the scene?

    Quote Originally Posted by ZbuffeR
    Import it only once.
    In fact I don't see why you would do differently.

    Or maybe I misunderstood your question ?
    And draw multiple times. There's no secret about it.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    8

    Re: Avoid importing the same mesh into the scene?

    I can't store the geometry in a buffer or something and retrieve it and somehow link that geometry object with each of the class objects I have created??

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jan 2011
    Location
    Paris, France
    Posts
    281

    Re: Avoid importing the same mesh into the scene?

    Diskhub,

    You can store the common part using glNewList/glEndList and use glCallList after the rotation/translation Display List
    @+
    Yannoo

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    8

    Re: Avoid importing the same mesh into the scene?

    how can i do that?
    Currently, i have the following a class called Teaport (for example):
    Code :
    class Teaport{
    ..
    void objload(String name, float size, GL2 gl){
      model = new OBJModel(name, size, gl, false);
    }
     
    void draw(GLAutoDrawable drawable)
    {
    System.out.println(model.getDisplayList());
    GL2 gl = drawable.getGL().getGL2();
    gl.glPushMatrix();
    gl.glTranslatef(25, 5, 25);
    gl.glRotatef(-90.0f+spin, 1.0f, 1.0f, 1.0f);
    	[B]model.draw(gl);[/B]
    gl.glPopMatrix();
    spin+=2;
    }
    ..
    }

    the model.draw method will draw the teaport in the scene.
    I have also used glNewList/glEndList and glCallList in my draw method in the objloader.

    Now the problem is:
    I wish to have mulitple teaport in the scene.
    Which means i have to initialise my teaport object like the following:
    Code :
    for(int i=0; i<8; i++){
    Teapot temp = new Teaport();
    arraylist.add(temp);
    }

    but i do not wish to do this for my draw and load:
    Code :
    for(int i=0; i<8; i++){
    arraylist.get(i).objload('..');
    }

    how can i achieve this?
    Sorry, I am still quite lost.

  8. #8
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,678

    Re: Avoid importing the same mesh into the scene?

    I wish to have mulitple teaport in the scene.
    Which means i have to initialise my teaport object like the following:
    "have to"? It's your code; you don't "have to" anything.

    This is a trivial software engineering problem. Your problem is that your "Teapot" object represents not only a mesh, but the position and orientation of that mesh in the world. Separate these two concepts.

    You need a "mesh" object that represents a particular set of vertex data. And you need an object that represents the position and orientation of something in the world.

    but i do not wish to do this for my draw and load:
    Then don't. Make a separate function that loads a model one time. Then give references to that model to the objects that need them. Your "Teapot" constructor should be given a model; it should neither own or load it.

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    8

    Re: Avoid importing the same mesh into the scene?

    thanks for enlightening me!
    I will give it a try

Similar Threads

  1. Multiple Textures in One scene, One per mesh?
    By Snow_56767 in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 08-22-2011, 03:32 AM
  2. Replies: 2
    Last Post: 05-04-2005, 07:28 PM
  3. importing a vrml scene "in" opengl
    By db in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 09-29-2004, 06:52 PM
  4. importing a vrml scene "in" opengl
    By db in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-29-2004, 12:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean