Thread: 3D Models

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    20

    3D Models

    Hey, I'm trying to hold a load of 3D models in my program... But I'm not sure how to go about doing it.
    At first, I tried an array of faces, containing an array of vertices, each being an array of XYZ. This returned stack overflows for big models.
    So then I tried an array of faces, which referred to an array of vertices which was an array of XYZ... But again - stack overflow.

    I checked, and apparently some of my models actually have 20,000+ faces... And this is far too many to put into an array.

    I know I could just make it a lower polygon model... But I'd rather change my method than my target.

    I'm not entirely sure how else to go about doing this... And I've tried to look about on Google to try and see how some other people have done it, but I've not been able to find anything.

    Could anyone give me a helpful push in the right direction?

    Thanks,
    Stephen

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    At first, I tried an array of faces, containing an array of vertices, each being an array of XYZ. This returned stack overflows for big models.
    So then I tried an array of faces, which referred to an array of vertices which was an array of XYZ... But again - stack overflow.
    Then use the heap.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    Ahhh... Right, sorry - thank you

    Is this a good way to go about doing it though? Just having a large array?

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Encapsulate the mesh into a class.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    Yeah, I'd already done that - it was the mesh that was holding the array of faces and vertices.
    Cheers

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    Actually no, wait - problem. I can create the array to send to the class... But within the class, when I try and create an array using the heap, I get this error thrown:
    "only static const integral data members can be initialized within a class"

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That makes me wonder how you tried to create the array. Your data member should be a pointer to the appropriate base type, and then you use new in the constructor (or wherever you find out how big it should be) to make it all happen.

  8. #8
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    So my class should actually just handle the pointer to the array, rather than the array itself - do you mean?

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    class MagicalArrayOfInts {
        private:
            int *array_start;
            int array_size;
    
        public:
            MagicalArrayOfInts(int size);
            int at(int index);
    };
    
    MagicalArrayOfInts::MagicalArrayOfInts(int size) {
        array_size = size;
        array_start = new int[size]; // look!  an array!  on the heap!  magic!
    }
    Not actually tested, but I feel pretty confident I didn't screw anything up.

    (EDIT: If things get really bad, you can even blow the heap, but that takes a fair bit of stuff.)

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Something tells me you need to concentrate on learning the language rather than loading 3D models.

    I say this because there is no way you can use a stack based array in a class to load a model when you do not know how many vertices or indices are in the model to begin with. You must use the heap. Now that you have been told to use the heap your answers come back as if you are still trying to use the stack. I suggest studying up a bit before progressing further.
    Last edited by VirtualAce; 03-28-2010 at 12:02 PM.

  11. #11
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    Cheers tabstop, that worked brilliantly.
    And yeah, Bubba - you're right; it's just I prefer to try and learn in doing things... Otherwise I just get bored out of my head. None of what I'm doing is going towards anything other than myself learning... And I have ordered a nice little book that should help me a great deal hopefully as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D models to in-game
    By Wes in forum Game Programming
    Replies: 2
    Last Post: 08-26-2004, 08:18 PM
  2. A 3D Program for my 3D models...?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 08-19-2004, 10:04 AM
  3. API programs for 3d models...?
    By Rune Hunter in forum Game Programming
    Replies: 1
    Last Post: 08-18-2004, 09:48 AM
  4. Deep Exploration, OpenGL, and 3d models
    By DavidP in forum Game Programming
    Replies: 18
    Last Post: 04-06-2003, 01:12 PM
  5. polygons vs. 3d models
    By Unregistered in forum Game Programming
    Replies: 5
    Last Post: 07-27-2002, 03:39 PM