الشبكة العربية لمطوري الألعاب

خبير مدير وسام البهنسي مشاركة 1

هذه الرسالة وصلتني بشل خاص من أحد الأصدقاء. أحببت أن يساعده الجميع في هذا المنتدى، ويستفيد البقية من الكلام...

Hi Wessam

I hoppe u r doing good. let annoy u one more time:

drawing using a vertex buffer and index buffer is really confusing me.
it is known that one of the advantages of using this method is that
vertices could be shared by triangles and this would save memory. that
is correct but what is confusing is that shared vertices might not have
the same texture coordinates and same normals. before u draw from a
vertex buffer u should specify the vertex format which means assigning
it x,y,z (this is ok since it is the same), nx, ny, nz (this might
differ between the two adjacent triangles), texture coordinates may also
differ so u need to repeat the vertices again to take the above
differences into account and this would defeat the purpose of using
vertex buffers.

I am trying to load an MS3D model, it saves the vertices into one place
then it index these vertices when defining the triangles. each triangle
has 3 sets of normals and texture coordinates for each corner and 3
indexes for the actual vertices as mentioned earlier. I can not just
copy the vertices into a vertex buffer since a vertex may be shared by
two triangles with different tex coordinates. the solution is create a
vertex buffer that contains the whole set of the model's vertices. if
that is the case why use indexed vertex buffer from the very beginning ?

thanks

وسام البهنسي
مبرمج في إنفيديا وإنفريمز

خبير مدير وسام البهنسي مشاركة 2

للأسف لا مهرب من إعادة تعريف الـ vertices التي تتشابه بالموقع وتختلف بأي شيء آخر (النواظم أو الـ Texture Coordinates مثلاً...).

طريقة تعريف النقط في صيغة الملفات التي تتعامل معها شائعة جداً (لم أر صيغة ملفات لا تفعل ذلك). لذا ستضطر لكتابة خوارزمية خاصة لإيجاد النقط المتطابقة (بكل معلوماتها) وإعطاؤها index واحد وهكذا...
طبعاً لا يمكن مقارنة الأداء بين مجسم مبني من سلسلة نقاط غير مشتركة أبداً، ومجسم يستخدم index buffer للتعبير عن مثلثاته بأكثر شكل مختصر.
في الحالة الأولى، لا يوجد حاجة للـ index buffer كما قلت. لذا يمكنك نسيان كل شيء عن الـ optimization والـ caching على كرت الشاشة...

وسام البهنسي
مبرمج في إنفيديا وإنفريمز

خبير  أحمد عبد الغني مشاركة 3

إذا كانت صيغة الملفات هذه تستخدم الـ indexing لتعريف مواقع نقاط المجسم، فيمكنك الابتداء من هذا الـ indexing. في كل مرة تواجه نفس الـ position index تكشف عن بقية العناصر (الـ normals والـ UV). إن كانت متطابقة، فاستخدم نفس الـ index للنقطة المعرفة مسبقاً. وإلا عرف نقطة جديدة وضعها مع قائمة خاصة بكل النقاط التي تتشارك بالـ position ولكن تختلف بالعناصر الأخرى..

أرجو أن يكون كلامي واضحاً...

__
هناك 10 أنواع من البشر.. من يعرف نظام العد الثنائي، ومن لا يعرفه!

اللهم انصر أهلنا في فلسطين وآجرنا أن نكون عوناً لهم

  Mohammad Aburrub مشاركة 4

Hi All
I started a similar thread at gamedev, u can have a look at:
http://www.gamedev.net/community/forums/topic.asp?topic_id=342094

خبير مدير وسام البهنسي مشاركة 5

طريقة أحمد عبد الغني بالفعل طريقة جيدة لحل الموضوع...
لكل position index لديك في الملف أنشئ مصفوفة بحجم أعظمي من عدد الـ vertices.
في هذه المصفوفة تسجل الـ vertices المختلفة والتي تتشارك فيما بينها بالموقع فقط. عندما تريد إضافة vertex لها نفس الموقع، اكشف إن كانت تطابق أحد "النسخ" المسجلة في المصفوفة، واستخدم الـ index للـ vertex المطابقة. إن لم يكن هناك vertex مطابقة في المصفوفة، عرف الـ vertex الجديدة وأضفها إلى المصفوفة إياها...

وسام البهنسي
مبرمج في إنفيديا وإنفريمز