load3d.cc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "r1_api.hh"
  9. #include "tmanage.hh"
  10. #include "obj3d.hh"
  11. #include "file/file.hh"
  12. #include "error/error.hh"
  13. #include "error/alert.hh"
  14. #include "load3d.hh"
  15. #include "math/num_type.hh"
  16. #include "loaders/dir_load.hh"
  17. #include "string/str_checksum.hh"
  18. #include "saver_id.hh"
  19. #define G3DF_VERSION 3
  20. g1_quad_object_class *g1_quad_object_loader_class::allocate_object()
  21. {
  22. g1_quad_object_class *o =(g1_quad_object_class*)heap->malloc(sizeof(g1_quad_object_class),
  23. "quad_object");
  24. if (o) o->init();
  25. return o;
  26. }
  27. void g1_quad_object_loader_class::set_num_vertex(w16 num_vertex)
  28. {
  29. obj->num_vertex=num_vertex;
  30. }
  31. void g1_quad_object_loader_class::set_num_animations(w16 anims)
  32. {
  33. obj->num_animations=anims;
  34. int size=sizeof(g1_quad_object_class::animation_class) * anims;
  35. obj->animation=(g1_quad_object_class::animation_class *)heap->malloc(size, "animation");
  36. }
  37. void g1_quad_object_loader_class::create_animation(w16 anim, const i4_const_str &name, w16 frames)
  38. {
  39. obj->animation[anim].num_frames=frames;
  40. obj->animation[anim].vertex=
  41. (g1_vert_class *)heap->malloc(sizeof(g1_vert_class)*frames*obj->num_vertex, "num frames");
  42. }
  43. void g1_quad_object_loader_class::create_vertex(w16 anim, w16 frame,
  44. w16 index, const i4_3d_vector& v)
  45. {
  46. g1_vert_class *vert=obj->get_verts(anim,frame)+index;
  47. vert->v = v;
  48. }
  49. void g1_quad_object_loader_class::store_vertex_normal(w16 anim, w16 frame, w16 index,
  50. const i4_3d_vector& normal)
  51. {
  52. g1_vert_class *vert=obj->get_verts(anim,frame)+index;
  53. vert->normal = normal;
  54. }
  55. void g1_quad_object_loader_class::set_num_quads(w16 quads)
  56. {
  57. obj->num_quad = quads;
  58. obj->quad=(g1_quad_class *)heap->malloc(sizeof(g1_quad_class) * quads, "obj_quads");
  59. }
  60. void g1_quad_object_loader_class::create_quad(w16 quad, int verts, w16 *ref, w32 flags)
  61. {
  62. g1_quad_class *q = &obj->quad[quad];
  63. q->set(ref[0], ref[1], ref[2], (verts>3)?ref[3]:0xffff);
  64. q->flags = flags;
  65. }
  66. void g1_quad_object_loader_class::store_texture_name(w32 quad, const i4_const_str &name)
  67. {
  68. g1_quad_class *q = &obj->quad[quad];
  69. if (name.null())
  70. {
  71. i4_alert(i4gets("no_texture"), 100, error_name);
  72. q->material_ref = 0;
  73. }
  74. else
  75. q->material_ref = tman->register_texture(name, *error_name);
  76. }
  77. void g1_quad_object_loader_class::store_texture_params(w32 quad, i4_float scale,
  78. i4_float *u, i4_float *v)
  79. {
  80. g1_quad_class *q = &obj->quad[quad];
  81. q->texture_scale = scale;
  82. q->u[0] = u[0];
  83. q->u[1] = u[1];
  84. q->u[2] = u[2];
  85. q->u[3] = u[3];
  86. q->v[0] = v[0];
  87. q->v[1] = v[1];
  88. q->v[2] = v[2];
  89. q->v[3] = v[3];
  90. }
  91. void g1_quad_object_loader_class::store_quad_normal(w16 quad, const i4_3d_vector& normal)
  92. {
  93. g1_quad_class *q = &obj->quad[quad];
  94. q->normal = normal;
  95. }
  96. void g1_quad_object_loader_class::set_num_mount_points(w16 mounts)
  97. {
  98. obj->num_mounts = mounts;
  99. obj->mount_id = (w32 *)heap->malloc(sizeof(w32) * mounts, "mount_ids");
  100. obj->mount = (i4_3d_vector *)heap->malloc(sizeof(i4_3d_vector) * mounts, "mount_vectors");
  101. }
  102. void g1_quad_object_loader_class::create_mount_point(w32 index, const i4_const_str &name,
  103. const i4_3d_vector &off)
  104. {
  105. obj->mount[index] = off;
  106. obj->mount_id[index] = i4_str_checksum(name);
  107. }
  108. void g1_quad_object_loader_class::set_num_texture_animations(w16 num_textures)
  109. {
  110. obj->num_special = num_textures;
  111. obj->special = (g1_texture_animation *)heap
  112. ->malloc(sizeof(g1_texture_animation) * num_textures, "texture_animations");
  113. }
  114. void g1_quad_object_loader_class::create_texture_animation(w32 index, w16 quad,
  115. w8 max_frames,
  116. w8 frames_x,
  117. i4_float du, i4_float dv,
  118. i4_float speed)
  119. {
  120. g1_texture_animation *p = &obj->special[index];
  121. p->quad_number = quad;
  122. p->max_frames = max_frames;
  123. p->frames_x = frames_x;
  124. p->du = du;
  125. p->dv = dv;
  126. p->speed = speed;
  127. g1_quad_class *q = &obj->quad[quad];
  128. for (int i=0; i<q->num_verts(); i++)
  129. {
  130. p->u[i] = q->u[i];
  131. p->v[i] = q->v[i];
  132. }
  133. }
  134. void g1_quad_object_loader_class::create_texture_pan(w32 index, w16 quad,
  135. i4_float du, i4_float dv, i4_float speed)
  136. {
  137. g1_texture_animation *p = &obj->special[index];
  138. p->quad_number = quad;
  139. p->max_frames = 0;
  140. p->frames_x = 0;
  141. p->du = du;
  142. p->dv = dv;
  143. p->speed = speed;
  144. g1_quad_class *q = &obj->quad[quad];
  145. for (int i=0; i<q->num_verts(); i++)
  146. {
  147. p->u[i] = q->u[i];
  148. p->v[i] = q->v[i];
  149. }
  150. }
  151. void g1_quad_object_loader_class::finish_object()
  152. {
  153. obj->calc_extents();
  154. }
  155. g1_quad_object_class *g1_quad_object_loader_class::load(i4_loader_class *fp,
  156. const i4_const_str &_error_name,
  157. r1_texture_manager_class *_tman)
  158. {
  159. tman = _tman;
  160. error_name = &_error_name;
  161. return g1_base_object_loader_class::load(fp);
  162. }