Beispiel #1
0
int GraspitDBModel::load(World *w)
{
  // delete the previously loaded graspabody
  if (mGraspableBody) { delete mGraspableBody; }
  // load the body
  mGraspableBody = new GraspableBody(w, ModelName().c_str());
  mGraspableBody->setDBModel(this);
  //material is default
  mGraspableBody->setMaterial(w->getMaterialIdx("wood"));

  //PSB objects have a scale of their own. To get to "graspable size"
  //we manually set a scaling factor for each of them, which is in the
  //database as well. We need to scale the geometry appropriately
  SoScale *scale = new SoScale();
  scale->scaleFactor.setValue(RescaleFactor(), RescaleFactor(), RescaleFactor());
  mGraspableBody->getIVGeomRoot()->addChild(scale);

  if (loadGeometry() != SUCCESS) {
    mGeometryLoaded = false;
    return FAILURE;
  }
  mGeometryLoaded = true;
  mGraspableBody->addIVMat();

  //set the dynamic properties. This needs a better solution...
  mGraspableBody->setDefaultDynamicParameters();
  //hard-coded inertia matrix of the flask...
  double I[] = {4853.0, -1.1196, -6.5156, -1.1196, 4853.0, 47.542, -6.5156, 0.0, 2357.6};
  mGraspableBody->setInertiaMatrix(I);
  mGraspableBody->setMaxRadius(mGraspableBody->computeDefaultMaxRadius());
  mGraspableBody->setMass(300);

  return SUCCESS;
}
Beispiel #2
0
void
CStarField::vStartPreload()
{
	CLog::Print("STAR FIELD starting preload.\n");

	// read model
	std::string ModelName("/data/");
	ModelName += "catalog.txt";
	CLoadProxy::getInstance().ReadFile( ModelName.c_str(), this );
}
Beispiel #3
0
/* Load primitive object from file function.
 * ARGUMENTS:
 *   - animation system pointer:
 *       anim *Ani;
 *   - model (Alias Wavefront *.OBJ) file name:
 *       CHAR *FileName;
 * RETURNS:
 *   (BOOL) TRUE if success, FALSE otherwise.
 */
BOOL tlr::geom_prim::Load( anim *Ani, CHAR *FileName )
{
  file_path ModelName(FileName);

  /* Collect model geometry information */
  FILE *F;
  if ((F = fopen(FileName, "rb")) == NULL)
    return FALSE;

  stock<vec> ReadV;
  stock<vec> ReadN;
  stock<UV> ReadUV;
  stock<INT> ReadF;
  vertex_references VRefs(10);
  struct PRIMINFO
  {
    INT First, Last; // Facet indexes (first and last)
    material *Mat;   // Material pointer
  };
  stock<PRIMINFO> PrimsInfo;


  /* Read every file line */
  buffer RBuf;
  INT pri_no = 0;
  while (RBuf.Read(F))
  {
    if (RBuf("mtllib "))
    {
      RBuf.Split();
      Ani->Load(RBuf[1], FileName);
    }
    else if (RBuf("v "))
    {
      FLT x, y, z;

      RBuf.Split();
      sscanf(RBuf[1], "%f", &x);
      sscanf(RBuf[2], "%f", &y);
      sscanf(RBuf[3], "%f", &z);
      ReadV << vec(x, y, z) * 5;
    }
    else if (RBuf("vn "))
    {
      FLT x, y, z;

      RBuf.Split();
      sscanf(RBuf[1], "%f", &x);
      sscanf(RBuf[2], "%f", &y);
      sscanf(RBuf[3], "%f", &z);
      ReadN << vec(x, y, z);
    }
    else if (RBuf("vt "))
    {
      FLT u, v;

      RBuf.Split();
      sscanf(RBuf[1], "%f", &u);
      sscanf(RBuf[2], "%f", &v);
      ReadUV << UV(u, v);
    }
    else if (RBuf("f "))
    {
      RBuf.Split();

#define SCAN3(str, ref) \
      if (sscanf(str, "%i/%i/%i", &ref[0], &ref[1], &ref[2]) == 3) \
        ref[0]--, ref[1]--, ref[2]--;                              \
      else if (sscanf(str, "%i//%i", &ref[0], &ref[2]) == 2)       \
        ref[0]--, ref[2]--, ref[1] = -1;                           \
      else if (sscanf(str, "%i/%i", &ref[0], &ref[1]) == 2)        \
        ref[0]--, ref[1]--, ref[2] = -1;                           \
      else if (sscanf(str, "%i", &ref[0]) == 1)                    \
        ref[0]--, ref[1] = ref[2] = -1

      INT n0[3], n_prev[3], n[3], r0, r_prev, r;
      /* Start polygon point */
      SCAN3(RBuf[1], n0);
      r0 = VRefs.GetVertexNumber(n0[0], n0[2], n0[1]);

      /* Second polygon point */
      SCAN3(RBuf[2], n_prev);
      r_prev = VRefs.GetVertexNumber(n_prev[0], n_prev[2], n_prev[1]);

      for (INT i = 3; i < RBuf.NumOfParts; i++)
      {
        /* Third polygon point */
        SCAN3(RBuf[i], n);
        r = VRefs.GetVertexNumber(n[0], n[2], n[1]);

        /* Add triangle */
        ReadF << r0;
        ReadF << r_prev;
        ReadF << r;

        /* Go to next triangle */
        r_prev = r;
      }
    }
    else if (RBuf("usemtl"))
    {
      RBuf.Split();

      PrimsInfo.Alloc(1);
      if (pri_no != 0)
        PrimsInfo[pri_no - 1].Last = ReadF.Size() / 3 - 1; 
      PrimsInfo[pri_no].First = ReadF.Size() / 3;

      /* Look for material */
      PrimsInfo[pri_no].Mat = Ani->Create(RBuf[1]);
      pri_no++;
    }
  }
  /* Build result primitives */
  prim p;

  p.Create(prim::TRIMESH, VRefs.VertexRefs.Size(), ReadF.Size());
  p.OpenEditV();
  matr m;
  m.SetRotateX(-90);
  for (INT i = 0; i < p.NoofV; i++)
  {
    p.V[i].P = m * ReadV[VRefs.VertexRefs[i].Nv];
    p.V[i].N = ReadN[VRefs.VertexRefs[i].Nn];
    p.V[i].T = ReadUV[VRefs.VertexRefs[i].Nt];
    p.V[i].C = color(1, 1, 1);
  }
  p.OpenEditI();
  for (INT i = 0; i < p.NoofI; i++)
  {
    p.I[i] = ReadF[i];
  }

  Prims << p;

  fclose(F);
  return FALSE;
} /* End of 'tlr::geom_prim::Load' function */
Beispiel #4
0
/* Load materials from file function.
 * ARGUMENTS:
 *   - material file name:
 *       CHAR *FileName;
 *   - material path (or model full file name):
 *       CHAR *Path;
 * RETURNS: None.
 */
VOID tlr::material_manager::Load( CHAR *FileName, CHAR *Path )
{
  /* Build material file name */
  file_path ModelName(Path);
  CHAR FullName[_MAX_PATH];
  _makepath(FullName, ModelName.Drive, ModelName.Dir, FileName, "");

  /* Setup default material */
  material Mat("unknown");

  FILE *F;
  if ((F = fopen(FullName, "rt")) == NULL)
    return;

  buffer RBuf;
  BOOL IsFirst = TRUE;
  /* Read all material */
  while (RBuf.Read(F))
  {
    RBuf.Split();
    if (RBuf.NumOfParts > 1)
      if (RBuf("Ka"))
      {
        sscanf(RBuf[1], "%f", &Mat.Ka.R);
        sscanf(RBuf[2], "%f", &Mat.Ka.G);
        sscanf(RBuf[3], "%f", &Mat.Ka.B);
      }
      else if (RBuf("Kd"))
      {
        sscanf(RBuf[1], "%f", &Mat.Kd.R);
        sscanf(RBuf[2], "%f", &Mat.Kd.G);
        sscanf(RBuf[3], "%f", &Mat.Kd.B);
      }
      else if (RBuf("Ks"))
      {
        sscanf(RBuf[1], "%f", &Mat.Ks.R);
        sscanf(RBuf[2], "%f", &Mat.Ks.G);
        sscanf(RBuf[3], "%f", &Mat.Ks.B);
      }
      else if (RBuf("Ns"))
        sscanf(RBuf[1], "%f", &Mat.Phong);
      else if (RBuf("Tr") || RBuf("d") || RBuf("D"))
        sscanf(RBuf[1], "%f", &Mat.Kt);
      else if (RBuf("map_Ka"))
      {
        _makepath(FullName, ModelName.Drive, ModelName.Dir, RBuf[1], "");
        strncpy(Mat.NameMap[0], FullName, MaxStringLength - 1);
      }
      else if (RBuf("map_Kd"))
      {
        _makepath(FullName, ModelName.Drive, ModelName.Dir, RBuf[1], "");
        strncpy(Mat.NameMap[1], FullName, MaxStringLength - 1);
      }
      else if (RBuf("map_Ks"))
      {
        _makepath(FullName, ModelName.Drive, ModelName.Dir, RBuf[1], "");
        strncpy(Mat.NameMap[2], FullName, MaxStringLength - 1);
      }
      else if (RBuf("map_opacity") || RBuf("map_d"))
      {
        _makepath(FullName, ModelName.Drive, ModelName.Dir, RBuf[1], "");
        strncpy(Mat.NameMap[3], FullName, MaxStringLength - 1);
      }
      else if (RBuf("map_bump") || RBuf("bump"))
      {
        _makepath(FullName, ModelName.Drive, ModelName.Dir, RBuf[1], "");
        strncpy(Mat.NameMap[4], FullName, MaxStringLength - 1);
      }
      else if (RBuf("newmtl"))
      {
        if (IsFirst)
          IsFirst = FALSE;
        else 
          Materials << Mat;
        Mat = material(RBuf[1]);
      }
    }
  if (!IsFirst)
    Materials << Mat;
  fclose(F);
} /* End of 'tlr::material_manager::Load' function */
Beispiel #5
0
Token* DEReceiver_Get(struct DEReceiver* r) {
    if (pblListIsEmpty(r->_tokens)) {
        fprintf(stderr, "No more Tokens in the DE Receiver \
                                : DEReceiver_Get ($ModelName()__DEReceiver.c)\n");
        exit(-1);
    }
Beispiel #6
0
static void DrawSurfInfo()
{
	static const flagInfo_t surfNames[] = {
#define T(name)		{SURF_##name, #name}
		T(LIGHT), T(SLICK), T(SKY), T(WARP),
		T(TRANS33), T(TRANS66), T(FLOWING), T(NODRAW),
		// Kingpin flags
		T(ALPHA), T(DIFFUSE), T(SPECULAR),
		// new flags (temp ??)
		T(AUTOFLARE)
#undef T
	};

	static const char *materialNames[MATERIAL_COUNT] = {
		"silent",
		"concrete",
		"fabric",
		"gravel",
		"metal",
		"metal_l",
		"snow",
		"tin",
		"tile",
		"wood",
		"water",
		"glass",
		"dirt"
	};

	CVec3 start, end;
	start = cl.refdef.vieworg;
	Euler2Vecs(cl.refdef.viewangles, &end, NULL, NULL);
	end.Scale(500);
	end.Add(start);

	unsigned cont = r_surfinfo->integer & 4 ? MASK_ALL : MASK_SHOT|MASK_WATER;
	trace_t	trace;
#if TRACE_DEBUG
	cm_showTrace = true;
#endif
//static CBox nullBox = {{-2,-2,-2},{2,2,2}};
//static CBox nullBox = {{-10,-10,-10},{10,10,10}};
//static CBox nullBox = {{-20,-20,-20},{20,20,20}};
	CM_BoxTrace(trace, start, end, nullBox, 0, cont);
	CM_ClipTraceToModels(trace, start, end, nullBox, cont);
#if TRACE_DEBUG
	cm_showTrace = false;
#endif
	if (!(r_surfinfo->integer & 2))
		CL_EntityTrace(trace, start, end, nullBox, cont);
	V_AddLight(trace.endpos, 5, 0.3, 0.6, 0.3);	//?? keep or remove? intens > trace bounds!

	if (trace.fraction < 1.0)
	{
		if (trace.brushNum >= 0)
		{
			// brush
			RE_DrawTextLeft(va("BrushNum: %d", trace.brushNum), RGB(0.2,0.4,0.1));
			if (r_surfinfo->integer & 8)
			{
				// visualize brush
				if (!debugMem) debugMem = new CMemoryChain;
				CBrush *brush = CM_BuildBrush(trace.brushNum, debugMem);
				if (brush)
					RE_DrawBrush(brush, "brush", trace.brushNum);
				else
					RE_DrawTextLeft(va("brush %d: error", trace.brushNum), RGB(1,0,0));
			}
		}
		RE_DrawTextLeft("Surface info:\n-------------", RGB(0.4,0.4,0.6));
		RE_DrawTextLeft(va("Point: %g  %g  %g", VECTOR_ARG(trace.endpos)), RGB(0.2,0.4,0.1));
		csurface_t *surf = trace.surface;
		RE_DrawTextLeft(va("Normal: %g  %g  %g", VECTOR_ARG(trace.plane.normal)), RGB(0.2,0.4,0.1));
		if (surf->fullName[0])		// non-null surface
		{
			RE_DrawTextLeft(va("Texture: %s", surf->fullName), RGB(0.2,0.4,0.1));
			if (surf->value)
				RE_DrawTextLeft(va("Value: %d", surf->value), RGB(0.2,0.4,0.1));
			DrawFlag(surf->flags, ARRAY_ARG(surfNames), "SURF_");
			// material
			const char *s = (surf->material > 0 && surf->material < MATERIAL_COUNT) ?
				materialNames[surf->material] : "?? bad ??";
			RE_DrawTextLeft(va("Material: %s", s), RGB(0.3,0.6,0.4));
		}
		DecodeContents(trace.contents);
		if (trace.ent)
		{
			clEntityState_t *ent = (clEntityState_t*)trace.ent;
			RE_DrawTextLeft("\nEntity:\n-------", RGB(0.4,0.4,0.6));
			RE_DrawTextLeft(va("Origin: %g %g %g", VECTOR_ARG(ent->origin)), RGB(0.2,0.4,0.1));
			RE_DrawTextLeft(va("fx: %X  rfx: %X", ent->effects, ent->renderfx), RGB(0.2,0.4,0.1));
			if (ent->modelindex)	RE_DrawTextLeft(va("model: %s", ModelName(ent->modelindex)), RGB(0.2,0.4,0.1));
			if (ent->modelindex2)	RE_DrawTextLeft(va("model2: %s", ModelName(ent->modelindex2)), RGB(0.2,0.4,0.1));
			if (ent->modelindex3)	RE_DrawTextLeft(va("model3: %s", ModelName(ent->modelindex3)), RGB(0.2,0.4,0.1));
			if (ent->modelindex4)	RE_DrawTextLeft(va("model4: %s", ModelName(ent->modelindex4)), RGB(0.2,0.4,0.1));

			CL_AddEntityBox(ent, RGB(1,0.1,0.1));
		}
		RE_DrawTextLeft("");	// empty line
	}
}