예제 #1
0
파일: file.cpp 프로젝트: nitrologic/mod
/*!
 * \ingroup file
 */
void
lib3ds_file_bounding_box(Lib3dsFile *file, Lib3dsVector min, Lib3dsVector max)
{
    Lib3dsBool init=LIB3DS_FALSE;

    {
        Lib3dsVector lmin, lmax;
        Lib3dsMesh *p=file->meshes;

        if (!init && p) {
            init = LIB3DS_TRUE;
            lib3ds_mesh_bounding_box(p, min, max);
            p = p->next;
        }
        while (p) {
            lib3ds_mesh_bounding_box(p, lmin, lmax);
            lib3ds_vector_min(min, lmin);
            lib3ds_vector_max(max, lmax);
            p=p->next;
        }
    }
    {
        Lib3dsCamera *p=file->cameras;
        if (!init && p) {
            init = LIB3DS_TRUE;
            lib3ds_vector_copy(min, p->position);
            lib3ds_vector_copy(max, p->position);
        }

        while (p) {
            lib3ds_vector_min(min, p->position);
            lib3ds_vector_max(max, p->position);
            lib3ds_vector_min(min, p->target);
            lib3ds_vector_max(max, p->target);
            p=p->next;
        }
    }
    {
        Lib3dsLight *p=file->lights;
        if (!init && p) {
            init = LIB3DS_TRUE;
            lib3ds_vector_copy(min, p->position);
            lib3ds_vector_copy(max, p->position);
        }

        while (p) {
            lib3ds_vector_min(min, p->position);
            lib3ds_vector_max(max, p->position);
            if (p->spot_light) {
                lib3ds_vector_min(min, p->spot);
                lib3ds_vector_max(max, p->spot);
            }
            p=p->next;
        }
    }
}
예제 #2
0
/*!
 * Find the bounding box of a mesh object.
 *
 * \param mesh The mesh object
 * \param bmin Returned bounding box
 * \param bmax Returned bounding box
 */
void
lib3ds_mesh_bounding_box(Lib3dsMesh *mesh, float bmin[3], float bmax[3]) {
    int i;
    bmin[0] = bmin[1] = bmin[2] = FLT_MAX;
    bmax[0] = bmax[1] = bmax[2] = -FLT_MAX;

    for (i = 0; i < mesh->nvertices; ++i) {
        lib3ds_vector_min(bmin, mesh->vertices[i]);
        lib3ds_vector_max(bmax, mesh->vertices[i]);
    }
}
예제 #3
0
/*!
 * This function computes the bounding box of meshes, cameras and lights 
 * defined in the 3D editor.
 *
 * \param file              The Lib3dsFile object to be examined.
 * \param include_meshes    Include meshes in bounding box calculation.
 * \param include_cameras   Include cameras in bounding box calculation.
 * \param include_lights    Include lights in bounding box calculation.
 * \param bmin              Returned minimum x,y,z values.
 * \param bmax              Returned maximum x,y,z values.
 *
 * \ingroup file
 */
void
lib3ds_file_bounding_box_of_objects(Lib3dsFile *file, Lib3dsBool include_meshes, 
                                    Lib3dsBool include_cameras, Lib3dsBool include_lights, 
                                    Lib3dsVector bmin, Lib3dsVector bmax)
{
  bmin[0] = bmin[1] = bmin[2] = FLT_MAX; 
  bmax[0] = bmax[1] = bmax[2] = FLT_MIN; 

  if (include_meshes) {
    Lib3dsVector lmin, lmax;
    Lib3dsMesh *p=file->meshes;
    while (p) {
      lib3ds_mesh_bounding_box(p, lmin, lmax);
      lib3ds_vector_min(bmin, lmin);
      lib3ds_vector_max(bmax, lmax);
      p=p->next;
    }
  }
  if (include_cameras) {
    Lib3dsCamera *p=file->cameras;
    while (p) {
      lib3ds_vector_min(bmin, p->position);
      lib3ds_vector_max(bmax, p->position);
      lib3ds_vector_min(bmin, p->target);
      lib3ds_vector_max(bmax, p->target);
      p=p->next;
    }
  }
  if (include_lights) {
    Lib3dsLight *p=file->lights;
    while (p) {
      lib3ds_vector_min(bmin, p->position);
      lib3ds_vector_max(bmax, p->position);
      if (p->spot_light) {
        lib3ds_vector_min(bmin, p->spot);
        lib3ds_vector_max(bmax, p->spot);
      }
      p=p->next;
    }
  }
}  
예제 #4
0
/*!
 * Find the bounding box of a mesh object.
 *
 * \param mesh The mesh object
 * \param bmin Returned bounding box
 * \param bmax Returned bounding box
 *
 * \ingroup mesh
 */
void
lib3ds_mesh_bounding_box(Lib3dsMesh *mesh, Lib3dsVector bmin, Lib3dsVector bmax)
{
  unsigned i;
  bmin[0] = bmin[1] = bmin[2] = FLT_MAX; 
  bmax[0] = bmax[1] = bmax[2] = FLT_MIN; 

  for (i=0; i<mesh->points; ++i) {
    lib3ds_vector_min(bmin, mesh->pointL[i].pos);
    lib3ds_vector_max(bmax, mesh->pointL[i].pos);
  }
}
예제 #5
0
void
lib3ds_file_bounding_box_of_objects(Lib3dsFile *file, int 
                                    include_meshes, int include_cameras, int include_lights,
                                    float bmin[3], float bmax[3]) {
    bmin[0] = bmin[1] = bmin[2] = FLT_MAX;
    bmax[0] = bmax[1] = bmax[2] = -FLT_MAX;

    if (include_meshes) {
        float lmin[3], lmax[3];
        int i;
        for (i = 0; i < file->nmeshes; ++i) {
            lib3ds_mesh_bounding_box(file->meshes[i], lmin, lmax);
            lib3ds_vector_min(bmin, lmin);
            lib3ds_vector_max(bmax, lmax);
        }
    }
    if (include_cameras) {
        int i;
        for (i = 0; i < file->ncameras; ++i) {
            lib3ds_vector_min(bmin, file->cameras[i]->position);
            lib3ds_vector_max(bmax, file->cameras[i]->position);
            lib3ds_vector_min(bmin, file->cameras[i]->target);
            lib3ds_vector_max(bmax, file->cameras[i]->target);
        }
    }
    if (include_lights) {
        int i;
        for (i = 0; i < file->ncameras; ++i) {
            lib3ds_vector_min(bmin, file->lights[i]->position);
            lib3ds_vector_max(bmax, file->lights[i]->position);
            if (file->lights[i]->spot_light) {
                lib3ds_vector_min(bmin, file->lights[i]->target);
                lib3ds_vector_max(bmax, file->lights[i]->target);
            }
        }
    }
}
예제 #6
0
/*!
 * Compute the bounding box for Lib3dsFile objects.
 *
 * This function computes the bounding box for all meshes
 * in the Lib3dsFile object.  Cameras and lights are not included.
 *
 * \param file The Lib3dsFile object to be examined.
 * \param min Returned minimum x,y,z values.
 * \param max Returned maximum x,y,z values.
 *
 * \ingroup file
 */
void
lib3ds_object_bounding_box(Lib3dsFile *file, Lib3dsVector min, Lib3dsVector max)
{
  {
    Lib3dsVector lmin, lmax;
    Lib3dsMesh *p=file->meshes;

    if (p) {
      lib3ds_mesh_bounding_box(p, min, max);
      p = p->next;  
    }
    while (p) {
      lib3ds_mesh_bounding_box(p, lmin, lmax);
      lib3ds_vector_min(min, lmin);
      lib3ds_vector_max(max, lmax);
      p=p->next;
    }
  }
}  
예제 #7
0
static void
file_bounding_box_of_nodes_impl(Lib3dsNode *node, Lib3dsFile *file, Lib3dsBool include_meshes, 
                                Lib3dsBool include_cameras, Lib3dsBool include_lights, 
                                Lib3dsVector bmin, Lib3dsVector bmax)
{
  switch (node->type)
  {
    case LIB3DS_OBJECT_NODE:
      if (include_meshes) {
        Lib3dsMesh *mesh;

        mesh = lib3ds_file_mesh_by_name(file, node->data.object.instance);
        if (!mesh)
          mesh = lib3ds_file_mesh_by_name(file, node->name);
        if (mesh) {
          Lib3dsMatrix inv_matrix, M;
          Lib3dsVector v;
          unsigned i;

          lib3ds_matrix_copy(inv_matrix, mesh->matrix);
          lib3ds_matrix_inv(inv_matrix);
          lib3ds_matrix_copy(M, node->matrix);
          lib3ds_matrix_translate_xyz(M, -node->data.object.pivot[0], -node->data.object.pivot[1], -node->data.object.pivot[2]);
          lib3ds_matrix_mult(M, inv_matrix);

          for (i=0; i<mesh->points; ++i) {
            lib3ds_vector_transform(v, M, mesh->pointL[i].pos);
            lib3ds_vector_min(bmin, v);
            lib3ds_vector_max(bmax, v);
          }
        }
      }
      break;
   /*
    case LIB3DS_CAMERA_NODE:
    case LIB3DS_TARGET_NODE:
      if (include_cameras) {
        Lib3dsVector z,v;
        lib3ds_vector_zero(z);
        lib3ds_vector_transform(v, node->matrix, z);
        lib3ds_vector_min(bmin, v);
        lib3ds_vector_max(bmax, v);
      }
      break;

    case LIB3DS_LIGHT_NODE:
    case LIB3DS_SPOT_NODE:
      if (include_lights) {
        Lib3dsVector z,v;
        lib3ds_vector_zero(z);
        lib3ds_vector_transform(v, node->matrix, z);
        lib3ds_vector_min(bmin, v);
        lib3ds_vector_max(bmax, v);
      }
      break;
    */
  }
  {
    Lib3dsNode *p=node->childs;
    while (p) {
      file_bounding_box_of_nodes_impl(p, file, include_meshes, include_cameras, include_lights, bmin, bmax);
      p=p->next;
    }
  }
}
예제 #8
0
static void
file_bounding_box_of_nodes_impl(Lib3dsNode *node, Lib3dsFile *file, 
                                int include_meshes, int include_cameras, int include_lights,
                                float bmin[3], float bmax[3], float matrix[4][4]) {
    switch (node->type) {
        case LIB3DS_NODE_MESH_INSTANCE:
            if (include_meshes) {
                int index;
                Lib3dsMeshInstanceNode *n = (Lib3dsMeshInstanceNode*)node;

                index = lib3ds_file_mesh_by_name(file, n->instance_name);
                if (index < 0)
                    index = lib3ds_file_mesh_by_name(file, node->name);
                if (index >= 0) {
                    Lib3dsMesh *mesh;
                    float inv_matrix[4][4], M[4][4];
                    float v[3];
                    int i;

                    mesh = file->meshes[index];
                    lib3ds_matrix_copy(inv_matrix, mesh->matrix);
                    lib3ds_matrix_inv(inv_matrix);
                    lib3ds_matrix_mult(M, matrix, node->matrix);
                    lib3ds_matrix_translate(M, -n->pivot[0], -n->pivot[1], -n->pivot[2]);
                    lib3ds_matrix_mult(M, M, inv_matrix);

                    for (i = 0; i < mesh->nvertices; ++i) {
                        lib3ds_vector_transform(v, M, mesh->vertices[i]);
                        lib3ds_vector_min(bmin, v);
                        lib3ds_vector_max(bmax, v);
                    }
                }
            }
            break;

        case LIB3DS_NODE_CAMERA:
        case LIB3DS_NODE_CAMERA_TARGET:
            if (include_cameras) {
                float z[3], v[3];
                float M[4][4];
                lib3ds_matrix_mult(M, matrix, node->matrix);
                lib3ds_vector_zero(z);
                lib3ds_vector_transform(v, M, z);
                lib3ds_vector_min(bmin, v);
                lib3ds_vector_max(bmax, v);
            }
            break;

        case LIB3DS_NODE_OMNILIGHT:
        case LIB3DS_NODE_SPOTLIGHT:
        case LIB3DS_NODE_SPOTLIGHT_TARGET:
            if (include_lights) {
                float z[3], v[3];
                float M[4][4];
                lib3ds_matrix_mult(M, matrix, node->matrix);
                lib3ds_vector_zero(z);
                lib3ds_vector_transform(v, M, z);
                lib3ds_vector_min(bmin, v);
                lib3ds_vector_max(bmax, v);
            }
            break;
    }
    {
        Lib3dsNode *p = node->childs;
        while (p) {
            file_bounding_box_of_nodes_impl(p, file, include_meshes, include_cameras, include_lights, bmin, bmax, matrix);
            p = p->next;
        }
    }
}