void SkeletonExporter::dump_material_tracks(Mtl* mtl)
{
  Control *c;
  int size_key;
  Animatable *track;

  if (!mtl) return;
  export_animatable(mtl, 1);

  if (mtl->ClassID() == Class_ID(DMTL_CLASS_ID, 0))
  {
    // opacity track
	track=mtl->SubAnim(2)->SubAnim(0);
    c=GetControlInterface(track);
    if ((c) && (c->NumKeys()>0))
	{
       if (IsTCBControl(c)) size_key=28;
	   else
	   if (IsBezierControl(c)) size_key=16;
	   else size_key=8;
	   fprintf(fTXT, "Material %s:  opacity track present.\n", mtl->GetName());
       write_chunk_header(fA3D, MATERIAL_OPACITY_TRACK_ID,
	                      mtl->GetName(), 1+2+4+c->NumKeys()*size_key);
	   export_float_track(c, 1.0f, fA3D);
	}
  }
  fprintf(fTXT, "\n\n");
}
Exemplo n.º 2
0
static int write_packet(AVFormatContext *s, AVPacket *pkt)
{
    AVIOContext *pb = s->pb;
    WtvContext  *wctx = s->priv_data;

    /* emit sync chunk and 'timeline.table.0.entries.Event' record every 50 frames */
    if (wctx->serial - (wctx->nb_sp_pairs ? wctx->sp_pairs[wctx->nb_sp_pairs - 1].serial : 0) >= 50)
        write_sync(s);

    /* emit 'table.0.entries.time' record every 500ms */
    if (pkt->pts != AV_NOPTS_VALUE && pkt->pts - (wctx->nb_st_pairs ? wctx->st_pairs[wctx->nb_st_pairs - 1].value : 0) >= 5000000)
        add_serial_pair(&wctx->st_pairs, &wctx->nb_st_pairs, wctx->serial, pkt->pts);

    if (pkt->pts != AV_NOPTS_VALUE && pkt->pts > wctx->last_pts) {
        wctx->last_pts = pkt->pts;
        wctx->last_serial = wctx->serial;
    }

    // write timestamp chunk
    write_timestamp(s, pkt);

    write_chunk_header(s, &ff_data_guid, pkt->size, INDEX_BASE + pkt->stream_index);
    avio_write(pb, pkt->data, pkt->size);
    write_pad(pb, WTV_PAD8(pkt->size) - pkt->size);

    wctx->serial++;
    avio_flush(pb);
    return 0;
}
Exemplo n.º 3
0
static void write_chunk_header2(AVFormatContext *s, const ff_asf_guid *guid, int stream_id)
{
    WtvContext *wctx = s->priv_data;
    AVIOContext *pb = s->pb;

    int64_t last_chunk_pos = wctx->last_chunk_pos;
    write_chunk_header(s, guid, 0, stream_id); // length updated later
    avio_wl64(pb, last_chunk_pos);
}
Exemplo n.º 4
0
// ###########################################################
// #######   EXPORTERs DI SINGOLE ENTITA' DELLA SCENA  #######
// ###########################################################
void SkeletonExporter::export_general_info(void)
{
	int ff, lf, fs;
	Interval range = ip->GetAnimRange();
	Box3 bbox;

	fprintf(fTXT, "[AD]Turbo ROX as usual !! \n\n");

	INode *root = ip->GetRootNode();
	bbox.pmin.x=bbox.pmin.y=bbox.pmin.z=(float)1E10;
	bbox.pmax.x=bbox.pmax.y=bbox.pmax.z=(float)-1E10;
    GetSceneBoundingBox(root, 0, &bbox);

	ff=range.Start() / GetTicksPerFrame();
	lf=range.End() / GetTicksPerFrame();
	fs=GetFrameRate();

	// Start with a file identifier and format version
	fprintf(fTXT, "First frame : %d\n", ff);
	fprintf(fTXT, "Last frame : %d\n", lf);
	fprintf(fTXT, "Frame speed : %d\n", fs);
	fprintf(fTXT, "Scene Bounding Box at time 0\n");
	fprintf(fTXT, "min : %f, %f, %f\n",
		    bbox.pmin.x, bbox.pmin.y, bbox.pmin.z);
	fprintf(fTXT, "max : %f, %f, %f\n",
		    bbox.pmax.x, bbox.pmax.y, bbox.pmax.z);

	write_chunk_header(fA3D, SCENE_GENERAL_INFO_ID, "Scene Root", 36);
	fwrite(&ff, sizeof(int), 1, fA3D);
	fwrite(&lf, sizeof(int), 1, fA3D);
	fwrite(&fs, sizeof(int), 1, fA3D);
	write_bbox(&bbox, fA3D);

	if (makeRAY) write_chunk_header(fRAY, SCENE_GENERAL_INFO_ID, "Scene Root", 36);
	if (makeRAY) fwrite(&ff, sizeof(int), 1, fRAY);
	if (makeRAY) fwrite(&lf, sizeof(int), 1, fRAY);
	if (makeRAY) fwrite(&fs, sizeof(int), 1, fRAY);
	if (makeRAY) write_bbox(&bbox, fRAY);
}
Exemplo n.º 5
0
static void write_sync(AVFormatContext *s)
{
    AVIOContext *pb = s->pb;
    WtvContext *wctx = s->priv_data;
    int64_t last_chunk_pos = wctx->last_chunk_pos;
    wctx->sync_pos = avio_tell(pb) - wctx->timeline_start_pos;

    write_chunk_header(s, &sync_guid, 0x18, 0);
    write_pad(pb, 24);

    finish_chunk(s);

    wctx->last_chunk_pos = last_chunk_pos;
}
Exemplo n.º 6
0
static void write_sync(AVFormatContext *s)
{
    AVIOContext *pb = s->pb;
    WtvContext *wctx = s->priv_data;
    int64_t last_chunk_pos = wctx->last_chunk_pos;

    write_chunk_header(s, &ff_sync_guid, 0x18, 0);
    avio_wl64(pb, wctx->first_index_pos);
    avio_wl64(pb, wctx->last_timestamp_pos);
    avio_wl64(pb, 0);

    finish_chunk(s);
    add_serial_pair(&wctx->sp_pairs, &wctx->nb_sp_pairs, wctx->serial, wctx->last_chunk_pos);

    wctx->last_chunk_pos = last_chunk_pos;
}
Exemplo n.º 7
0
static int write_packet(AVFormatContext *s, AVPacket *pkt)
{
    AVIOContext *pb = s->pb;
    WtvContext  *wctx = s->priv_data;

    // write timestamp chunk
    write_timestamp(s, pkt);

    write_chunk_header(s, &ff_data_guid, pkt->size, INDEX_BASE + pkt->stream_index);
    avio_write(pb, pkt->data, pkt->size);
    write_pad(pb, WTV_PAD8(pkt->size) - pkt->size);

    wctx->serial++;
    avio_flush(pb);
    return 0;
}
Exemplo n.º 8
0
static void write_timestamp(AVFormatContext *s, AVPacket *pkt)
{
    AVIOContext *pb = s->pb;
    WtvContext  *wctx = s->priv_data;
    AVCodecContext *enc = s->streams[pkt->stream_index]->codec;

    write_chunk_header(s, &ff_timestamp_guid, 56, 0x40000000 | (INDEX_BASE + pkt->stream_index));
    write_pad(pb, 8);
    avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts);
    avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts);
    avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts);
    avio_wl64(pb, 0);
    avio_wl64(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY) ? 1 : 0);
    avio_wl64(pb, 0);

    wctx->last_timestamp_pos = wctx->last_chunk_pos;
}
Exemplo n.º 9
0
static void write_timestamp(AVFormatContext *s, AVPacket *pkt)
{
    AVIOContext *pb = s->pb;
    WtvContext  *wctx = s->priv_data;
    AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
    int flag = 0;
    int64_t frame_number = 0;

    if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
        wctx->frame_nb++;
        frame_number = wctx->frame_nb;
        flag = pkt->flags & AV_PKT_FLAG_KEY ? 1 : 0;
    }
    write_chunk_header(s, &ff_timestamp_guid, 56, 0x40000000 | (INDEX_BASE + pkt->stream_index));
    write_pad(pb, 8);
    avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts);
    avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts);

    avio_wl64(pb, frame_number);
    avio_wl64(pb, 0);
    avio_wl64(pb, flag);
    avio_wl64(pb, 0);
}
Exemplo n.º 10
0
void SkeletonExporter::export_light(INode *node)
{
  Control *c;
  int size_key, sf;
  ObjectState os;
  GenLight* light;
  struct LightState ls;
  float near_radius, far_radius;
  Point3 row;
  Matrix3 mat;

  os=node->EvalWorldState(0);
  if (!os.obj) return;  // per sicurezza
  light=(GenLight*)os.obj;

  // controlliamo se esiste un padre
  INode *padre=node->GetParentNode();
  if ((padre) && (strcmp(padre->GetName(), "Scene Root")!=0))
    sf=strlen(padre->GetName())+1;
  else sf=0;

  light->EvalLightState(0, FOREVER, &ls);
  fprintf(fTXT, "Name : %s\n", node->GetName());
  switch (ls.type)
  {
    case OMNI_LGT: fprintf(fTXT, "Omni light found\n");
		           // flag padre + nome padre + pivot + NodeTM(0) +
		           // + colore
		           write_chunk_header(fA3D, OMNI_LIGHT_ID,
					                  node->GetName(), 4+sf+12+48+12);
		           if (makeRAY) write_chunk_header(fRAY, OMNI_LIGHT_ID,
						              node->GetName(), 4+sf+12+48+12);
		           break;

    case SPOT_LGT: fprintf(fTXT, "Spot light found\n");
		           // flag padre + nome padre + pivot + NodeTM(0) +
		           // + colore + falloff + hotspot
		           write_chunk_header(fA3D, SPOT_LIGHT_ID,
					                  node->GetName(), 4+sf+12+48+12+8);
		           if (makeRAY) write_chunk_header(fRAY, SPOT_LIGHT_ID,
					                  node->GetName(), 4+sf+12+48+12+8);
		           break;
  }

  // -----------    scrivo il padre (flag, nome)   ------------------
  fwrite(&sf, sizeof(int), 1, fA3D);
  if (sf>0) write_string0(fA3D, padre->GetName());
  if (makeRAY) fwrite(&sf, sizeof(int), 1, fRAY);
  if (makeRAY) 
	if (sf>0) write_string0(fRAY, padre->GetName());
  
  // ---------------   scrittura del punto di pivot   ----------------
  GetPivotOffset(node, &row);
  fprintf(fTXT, "Pivot point : %f, %f, %f\n", row.x, row.y, row.z);
  write_point3(&row, fA3D);
  if (makeRAY) write_point3(&row, fRAY);

  // -------------------  salviamo la NodeTM(0)  ---------------------
  mat=node->GetNodeTM(0);
  row=mat.GetRow(3);
  fprintf(fTXT, "World position : x=%f, y=%f, z=%f\n", row.x, row.y, row.z);
  write_matrix(&mat, fA3D);
  if (makeRAY) write_matrix(&mat, fRAY);

  // --------------------  salviamo il colore  -----------------------
  fprintf(fTXT, "Color : R=%f, G=%f, B=%f\n", ls.color.r, ls.color.g, ls.color.b);
  fwrite(&ls.color.r, sizeof(float), 1, fA3D);
  fwrite(&ls.color.g, sizeof(float), 1, fA3D);
  fwrite(&ls.color.b, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&ls.color.r, sizeof(float), 1, fRAY);
  if (makeRAY) fwrite(&ls.color.g, sizeof(float), 1, fRAY);
  if (makeRAY) fwrite(&ls.color.b, sizeof(float), 1, fRAY);

  // ----------------------  falloff e hotpsot  ----------------------
  if (ls.type == SPOT_LGT)
  {
	 float hotspot = (float)(ls.hotsize*3.14159265358979323846/180.0);
	 float falloff = (float)(ls.fallsize*3.14159265358979323846/180.0);
	 fwrite(&hotspot, sizeof(float), 1, fA3D);
	 if (makeRAY) fwrite(&hotspot, sizeof(float), 1, fRAY);
	 fwrite(&falloff, sizeof(float), 1, fA3D);
	 if (makeRAY) fwrite(&falloff, sizeof(float), 1, fRAY);
  }

  fprintf(fTXT, "Intensity : %f\n", ls.intens);

  // --------------  esportazione tracce di posizione  ---------------
  c=node->GetTMController()->GetPositionController();
  if ((c) && (c->NumKeys()>0))
  {
	if (IsTCBControl(c)) size_key=36;
    else
	if (IsBezierControl(c)) size_key=40;
	else size_key=16;
	fprintf(fTXT, "Light position track present.");
    write_chunk_header(fA3D, POSITION_TRACK_ID,
                       node->GetName(), 1+2+4+c->NumKeys()*size_key);
    export_point3_track(c, 1, fA3D);
    if (makeRAY) write_chunk_header(fRAY, POSITION_TRACK_ID,
                       node->GetName(), 1+2+4+c->NumKeys()*size_key);
    if (makeRAY) export_point3_track(c, 1, fRAY);
  }


  // ---------------  esportazione tracce di colore  -----------------
  c=light->GetColorControl();
  if ((c) && (c->NumKeys()>0))
  {
	if (IsTCBControl(c)) size_key=36;
	else
	if (IsBezierControl(c)) size_key=40;
	else size_key=16;
	fprintf(fTXT, "Light color track present.");
    write_chunk_header(fA3D, COLOR_TRACK_ID,
                       node->GetName(), 1+2+4+c->NumKeys()*size_key);
    export_point3_track(c, 1.0f, fA3D);
    if (makeRAY) write_chunk_header(fRAY, COLOR_TRACK_ID,
                       node->GetName(), 1+2+4+c->NumKeys()*size_key);
    if (makeRAY) export_point3_track(c, 1.0f, fRAY);
  }

  // --------------  esportazione tracce di hotspot  -----------------
  c=light->GetHotSpotControl();
  if ((c) && (c->NumKeys()>0) && (ls.type == SPOT_LGT))
  {
	if (IsTCBControl(c)) size_key=28;
	else
	if (IsBezierControl(c)) size_key=16;
	else size_key=8;
	fprintf(fTXT, "Light hotspot track present.");
    write_chunk_header(fA3D, HOTSPOT_TRACK_ID,
                       node->GetName(), 1+2+4+c->NumKeys()*size_key);
    export_float_track(c, (float)(3.14159265358979323846/180.0), fA3D);  // in radianti
    if (makeRAY) write_chunk_header(fRAY, HOTSPOT_TRACK_ID,
                       node->GetName(), 1+2+4+c->NumKeys()*size_key);
    if (makeRAY) export_float_track(c, (float)(3.14159265358979323846/180.0), fRAY);  // in radianti
  }

  // --------------  esportazione tracce di falloff  -----------------
  c=light->GetFalloffControl();
  if ((c) && (c->NumKeys()>0) && (ls.type == SPOT_LGT))
  {
	if (IsTCBControl(c)) size_key=28;
	else
	if (IsBezierControl(c)) size_key=16;
	else size_key=8;
	fprintf(fTXT, "Light falloff track present.");
    write_chunk_header(fA3D, FALLOFF_TRACK_ID,
                       node->GetName(), 1+2+4+c->NumKeys()*size_key);
    export_float_track(c, (float)(3.14159265358979323846/180.0), fA3D);  // in radianti
    if (makeRAY) write_chunk_header(fRAY, FALLOFF_TRACK_ID,
                       node->GetName(), 1+2+4+c->NumKeys()*size_key);
    if (makeRAY) export_float_track(c, (float)(3.14159265358979323846/180.0), fRAY);  // in radianti
  }


  // -------------------------  script ADL  --------------------------
  Mtl *materiale=node->GetMtl();
  // NO far + NO near
  if ((!light->GetUseAttenNear()) && (!light->GetUseAtten()))
  {
     far_radius=near_radius=999999;
  }
  else
  // NO far + SI near
  if ((light->GetUseAttenNear()) && (!light->GetUseAtten()))
  {
     near_radius=light->GetAtten(0, ATTEN1_START, FOREVER);
	 far_radius=999999;
  }
  else
  // SI far + NO near
  if ((!light->GetUseAttenNear()) && (light->GetUseAtten()))
  {
     far_radius=light->GetAtten(0, ATTEN_START, FOREVER);
     near_radius=far_radius;
  }
  // SI far + SI near
  if ((light->GetUseAttenNear()) && (light->GetUseAtten()))
  {
     near_radius=light->GetAtten(0, ATTEN1_START, FOREVER);
	 far_radius=light->GetAtten(0, ATTEN_START, FOREVER);
  }
  if (makeADL)
  {
    fprintf(fADL, "  light %c%s%c\n  {\n", '"', node->GetName(), '"');
	if (materiale)
	  fprintf(fADL, "    material=%c%s%c;\n", '"', materiale->GetName(), '"');
    else
	  fprintf(fADL, "    material=%cNONE%c;\n", '"', '"');
    //fprintf(fADL, "    scale_x=%c160%c;\n", '"', '"');
    //fprintf(fADL, "    scale_y=%c160%c;\n", '"', '"');
    //fprintf(fADL, "    near_radius=%c%f%c;\n", '"', near_radius, '"');
    //fprintf(fADL, "    far_radius=%c%f%c;\n", '"', far_radius, '"');
	switch (light->GetDecayType())
	{
	   case 0: fprintf(fADL, "    attenuation0=%c1.0%c;\n", '"', '"');
               fprintf(fADL, "    attenuation1=%c0%c;\n", '"', '"');
               fprintf(fADL, "    attenuation2=%c0%c;\n", '"', '"');
		       break;
	   case 1: fprintf(fADL, "    attenuation0=%c0%c;\n", '"', '"');
               fprintf(fADL, "    attenuation1=%c1.0%c;\n", '"', '"');
               fprintf(fADL, "    attenuation2=%c0%c;\n", '"', '"');
		       break;
	   case 2: fprintf(fADL, "    attenuation0=%c0%c;\n", '"', '"');
               fprintf(fADL, "    attenuation1=%c0%c;\n", '"', '"');
               fprintf(fADL, "    attenuation2=%c1.0%c;\n", '"', '"');
		       break;
	}
	char range[20];
	my_ftoa(far_radius, range);
    fprintf(fADL, "    max_range=%c%s%c;\n", '"', range, '"');
	fprintf(fADL, "  }\n\n");
  }
  fprintf(fTXT, "\n\n\n----------------------------------------------------\n");
}
Exemplo n.º 11
0
int	SkeletonExporter::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options)
{
	// Set local interface pointer
	ip = i;

	// load the configuration from disk
	// so that it can be used in our dialog box
	if(!LoadExporterConfig()) return 0;

	if(!suppressPrompts)
	{

		// Show preferences setup dialog
		int res = DialogBoxParam(
			hInstance,
			MAKEINTRESOURCE(IDD_SKELETON_SCEXP),
			i->GetMAXHWnd(),
			PrefsDlgProc,
			(LPARAM)this);

		// User clicked 'Cancel'
		if(res!=0) return 0;

	}

	exportSelected = (options & SCENE_EXPORT_SELECTED) ? TRUE : FALSE;

	// Open a fA3D for writing out to
	fA3D = fopen (name, "wb+");
	if (!fA3D) return 0;

	strcpy(nomefileTXT, name);  // copio nella variabile della
	int sl=strlen(name); // classe il nome del file .A3D
	                            // (compresa estensione)
    nomefileTXT[sl-4]='.';
    nomefileTXT[sl-3]='T';
    nomefileTXT[sl-2]='X';
    nomefileTXT[sl-1]='T';
    nomefileTXT[sl-0]='\0';
	fTXT = _tfopen(nomefileTXT, _T("wt"));
	if (!fTXT) return 0;

    if (makeRAY)
	{
      strcpy(nomefileRAY, name);
      nomefileRAY[sl-4]='.';
      nomefileRAY[sl-3]='R';
      nomefileRAY[sl-2]='A';
      nomefileRAY[sl-1]='Y';
      nomefileRAY[sl-0]='\0';
	  fRAY = fopen(nomefileRAY, "wb+");
	  if (!fRAY) return 0;
	}

    strcpy(nomefileANI, name);
    nomefileANI[sl-4]='.';
    nomefileANI[sl-3]='A';
    nomefileANI[sl-2]='N';
    nomefileANI[sl-1]='I';
    nomefileANI[sl-0]='\0';
	//fANI = fopen(nomefileANI, "wb+");
	//if (!fANI) return 0;

    if (makeADM)
	{
      strcpy(nomefileADM, name);
      nomefileADM[sl-4]='.';
      nomefileADM[sl-3]='A';
      nomefileADM[sl-2]='D';
      nomefileADM[sl-1]='M';
      nomefileADM[sl-0]='\0';
      fADM=fopen(nomefileADM, "wt");
      fprintf(fADM, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADM, "// Material script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADM, "// Design is simply all...\n\n");
	}

    if (makeADL)
	{
      strcpy(nomefileADL, name);
      nomefileADL[sl-4]='.';
      nomefileADL[sl-3]='A';
      nomefileADL[sl-2]='D';
      nomefileADL[sl-1]='L';
      nomefileADL[sl-0]='\0';
      fADL=fopen(nomefileADL, "wt");
      fprintf(fADL, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADL, "// Light script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADL, "// Design is simply all...\n\n");
	}

    if (makeADO)
	{
      strcpy(nomefileADO, name);
      nomefileADO[sl-4]='.';
      nomefileADO[sl-3]='A';
      nomefileADO[sl-2]='D';
      nomefileADO[sl-1]='O';
      nomefileADO[sl-0]='\0';
      fADO=fopen(nomefileADO, "wt");
      fprintf(fADO, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADO, "// Object script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADO, "// Design is simply all...\n\n");
	}
/*
    if (makeADD)
	{
      strcpy(nomefileADD, name);
      nomefileADD[sl-4]='.';
      nomefileADD[sl-3]='A';
      nomefileADD[sl-2]='D';
      nomefileADD[sl-1]='D';
      nomefileADD[sl-0]='\0';
      fADD=fopen(nomefileADD, "wt");
      fprintf(fADD, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADD, "// Dummys script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADD, "// Design is simply all...\n\n");
	}
*/
    if (makeADP)
	{
      strcpy(nomefileADP, name);
      nomefileADP[sl-4]='.';
      nomefileADP[sl-3]='A';
      nomefileADP[sl-2]='D';
      nomefileADP[sl-1]='P';
      nomefileADP[sl-0]='\0';
      fADP=fopen(nomefileADP, "wt");
      fprintf(fADP, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADP, "// Particle systems script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADP, "// Design is simply all...\n\n");
	}

    if (makeADS)
	{
      strcpy(nomefileADS, name);
      nomefileADS[sl-4]='.';
      nomefileADS[sl-3]='A';
      nomefileADS[sl-2]='D';
      nomefileADS[sl-1]='S';
      nomefileADS[sl-0]='\0';
      fADS=fopen(nomefileADS, "wt");
      fprintf(fADS, "// *** Apocalypse Design Scripting System v1.0 ***\n");
      fprintf(fADS, "// Scene script auto-created by Turbo's MAX-plugin\n");
      fprintf(fADS, "// Design is simply all...\n\n");
	}

	export_general_info();
	export_materials();

	// Print out a title for the file header
	fprintf(fTXT, "***Elenco dei nodi***\n\n");

	// Simple root node -> children enumeration
	// This will get the root node, and then cycle through its children (ie, the basic scene nodes)
	// It will then recurse to search their children, and then their children, etc
	int numChildren = i->GetRootNode()->NumberOfChildren();
	
	for (int idx=0; idx<numChildren; idx++) {
//		if (i->GetCancel()) break;
		nodeEnum(i->GetRootNode()->GetChildNode(idx), i);
	}


    // scrittura del chunk di fine scena !!!
	int flag_end=1;
    write_chunk_header(fA3D, END_SCENE_ID, i->GetRootNode()->GetName(), 4);
	fwrite(&flag_end, sizeof(int), 1, fA3D);
    if (makeRAY)
	{
       write_chunk_header(fRAY, END_SCENE_ID, i->GetRootNode()->GetName(), 4);
       fwrite(&flag_end, sizeof(int), 1, fRAY);
	}
	//export_ANI (i->GetRootNode());	

	//fflush(fANI);
	fclose(fTXT);
	fclose(fA3D);
	//fclose(fANI);
    if (makeADM) fclose(fADM);
    if (makeADL) fclose(fADL);
    if (makeADO) fclose(fADO);
    //if (makeADD) fclose(fADD);
    if (makeADP) fclose(fADP);
    if (makeADS) fclose(fADS);
    if (makeRAY) fclose(fRAY);

	// Save the current configuration back out to disk
	// for use next time the exporter is run
	SaveExporterConfig();
	return 1;
}
Exemplo n.º 12
0
void SkeletonExporter::export_camera(INode *node)
{
  Control *c;
  int size_key;
  float camera_znear, camera_zfar;
  CameraState cs;
//  Interval valid = FOREVER;
  ObjectState os;
  CameraObject *cam;
  GenCamera *gencam;
  float roll0;
  Matrix3 mat;
  Point3 row;

  os = node->EvalWorldState(0);
  cam = (CameraObject *)os.obj;
  gencam = (GenCamera *)os.obj;
  if (gencam->Type() != TARGETED_CAMERA)
  {
	 fprintf(fTXT, "Only targeted camera are supported!\n\n");
	 return;
  }

  fprintf(fTXT, "Targeted camera found\n");
  write_chunk_header(fA3D, TARGETED_CAMERA_ID, node->GetName(), 40);
  if (makeRAY) write_chunk_header(fRAY, TARGETED_CAMERA_ID, node->GetName(), 40);

  INode* target = node->GetTarget();
  fprintf(fTXT, "Name : %s\n", node->GetName());
  cam->EvalCameraState(0, FOREVER, &cs);

  // ------------------  salviamo znear e zfar  ----------------------
  camera_znear=2;
  camera_zfar=2000;
  if (cs.manualClip)
  {
	camera_znear=cs.hither;
	camera_zfar=cs.yon;
  }
  fprintf(fTXT, "Znear = %f \n", camera_znear);
  fwrite(&camera_znear, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&camera_znear, sizeof(float), 1, fRAY);
  fprintf(fTXT, "Zfar = %f \n", camera_zfar);
  fwrite(&camera_zfar, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&camera_zfar, sizeof(float), 1, fRAY);

  // -----------------  salviamo l'angolo di FOV  --------------------
  fprintf(fTXT, "FOV (rad) = %f \n", cs.fov);
  fwrite(&cs.fov, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&cs.fov, sizeof(float), 1, fRAY);

  // ------------------  salviamo l'angolo di roll  ------------------
  c=node->GetTMController()->GetRollController();
  c->GetValue(0, &roll0, FOREVER);	
  fprintf(fTXT, "Roll (rad) = %f \n", roll0);
  fwrite(&roll0, sizeof(float), 1, fA3D);
  if (makeRAY) fwrite(&roll0, sizeof(float), 1, fRAY);

  // salviamo la posizione nel mondo
  mat = node->GetNodeTM(0);
  row = mat.GetRow(3);
  fprintf(fTXT, "Camera world position : x=%f, y=%f, z=%f\n", row.x, row.y, row.z);
  write_point3(&row, fA3D);
  if (makeRAY) write_point3(&row, fRAY);

  // ---------  salviamo la posizione del target nel mondo  ----------
  if (target)
  {
    mat = target->GetNodeTM(0);
    row = mat.GetRow(3);
    fprintf(fTXT, "Target world position : x=%f, y=%f, z=%f\n", row.x, row.y, row.z);
    write_point3(&row, fA3D);
    if (makeRAY) write_point3(&row, fRAY);
  }

  
  // esportiamo l'animazione della posizione della camera
  // se ci sono un numero di key > 0
  c=node->GetTMController()->GetPositionController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=36;
	 else
	 if (IsBezierControl(c)) size_key=40;
	 else size_key=16;
	 fprintf(fTXT, "Camera position track present.");
     write_chunk_header(fA3D, POSITION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_point3_track(c, 1, fA3D);
     if (makeRAY) write_chunk_header(fRAY, POSITION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     if (makeRAY) export_point3_track(c, 1, fRAY);
  }

  // -----  esportiamo l'animazione della posizione del target  ------
  if (target)
  {
    c=target->GetTMController()->GetPositionController();
    if ((c) && (c->NumKeys()>0))
	{
	  if (IsTCBControl(c)) size_key=36;
	  else
	  if (IsBezierControl(c)) size_key=40;
	  else size_key=16;
	  fprintf(fTXT, "Target position track present.");
	  write_chunk_header(fA3D, CAMERA_TARGET_TRACK_ID,
		                 node->GetName(), 1+2+4+c->NumKeys()*size_key);
	  export_point3_track(c, 1, fA3D);

	  if (makeRAY) write_chunk_header(fRAY, CAMERA_TARGET_TRACK_ID,
		                 node->GetName(), 1+2+4+c->NumKeys()*size_key);
	  if (makeRAY) export_point3_track(c, 1, fRAY);
	}
  }

  // ---------------  esportiamo le tracce di FOV  -------------------
  c=gencam->GetFOVControl();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Camera FOV track present.");
     write_chunk_header(fA3D, CAMERA_FOV_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);  // radianti
     if (makeRAY) write_chunk_header(fRAY, CAMERA_FOV_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     if (makeRAY) export_float_track(c, 1, fRAY);  // radianti
  }


  // ---------------  esportiamo le tracce di roll  ------------------
  c=node->GetTMController()->GetRollController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Camera roll track present.");
     write_chunk_header(fA3D, CAMERA_ROLL_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D); // radianti

     if (makeRAY) write_chunk_header(fRAY, CAMERA_ROLL_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     if (makeRAY) export_float_track(c, 1, fRAY); // radianti
  }
  fprintf(fTXT, "\n\n--------------------------------------------------\n");
}
void SkeletonExporter::export_particle_spray(INode *node)
{
  char sval[50];
  Interval range = ip->GetAnimRange();
  ObjectState os = node->EvalWorldState(0);
  if (!os.obj) return;

  SimpleParticle *partsys;
  Object *p; IDerivedObject *q; Modifier *m;
  partsys=(SimpleParticle *)os.obj;
  Point3 row;
  Matrix3 mat;
  Mtl *materiale;
  INode *padre=node->GetParentNode();
  int mod_names=0, k, mod_count=0;
  char modNames[25][50], refname[50];
  int sf, sm, mf, n;

  if ((padre) && (strcmp(padre->GetName(), "Scene Root")!=0))
    sf=strlen(padre->GetName())+1;
  else sf=0;
  
  materiale=node->GetMtl();
  if (materiale) sm=strlen(materiale->GetName())+1;
  else sm=0;

  mf=0;

  // trovo i modificatori Wind e Gravity con il loro
  // nome
  p=node->GetObjOrWSMRef();
  if ((p->SuperClassID()==GEN_DERIVOB_CLASS_ID) &&
	 (p->ClassID()==Class_ID(WSM_DERIVOB_CLASS_ID, 0)))
  {
	q=(IDerivedObject *)p;
	n=q->NumModifiers();
	mod_names=mod_count=0;
	for (k=0; k<n; k++)
	{
      m=q->GetModifier(k);
      Class_ID cidd = m->ClassID();
	  if ((cidd==Class_ID(WINDMOD_CLASS_ID, 0)) ||
		  (cidd==Class_ID(GRAVITYMOD_CLASS_ID, 0)) ||
		  (cidd==Class_ID(BOMB_OBJECT_CLASS_ID, 0)))
	  {
		 SimpleWSMMod *wm=(SimpleWSMMod *)m;
		 strcpy(refname, wm->nodeRef->GetName());
		 strcpy(modNames[mod_count], refname);
		 mod_names+=(strlen(refname)+1);
         mod_count++;
	  }
	}
  }

  write_chunk_header(fA3D, SPRAY_PARTICLE_SYSTEM_ID, node->GetName(),
	                 4+sf+4+sm+  // padre, materiale
					 12+48+  //pivot, matrice world(t=0)
					 4+mf+   // nome mesh/oggetto
					 4+4+4+4+ // emitter: width, height, speed , variation
					 4+4+4+4+ // life, startTime, stopTime, max_particles
					 4+mod_names // num WSM, nomi WSM
					 );

  fprintf(fTXT, "Spray particle system found\n");
  fprintf(fTXT, "Name : %s\n", node->GetName());
  if (padre) fprintf(fTXT, "Parent name : %s\n", node->GetParentNode()->GetName());
  if (materiale) fprintf(fTXT, "Material name : %s\n", materiale->GetName());
  if (makeADP)
    fprintf(fADP, "  particle %c%s%c\n  {\n", '"', node->GetName(), '"');

  // -----------    scrivo il padre (flag, nome)   ------------------
  fwrite(&sf, sizeof(int), 1, fA3D);
  if (sf>0)
  {
	 write_string0(fA3D, padre->GetName());
	 if (makeADP) fprintf(fADP, "     father=%c%s%c;\n", '"', padre->GetName(), '"');
  }
  else
	 if (makeADP) fprintf(fADP, "     father=%cNONE%c;\n", '"', '"');


  // ---------   scrivo il materiale di base (flag, nome)   ----------
  fwrite(&sm, sizeof(int), 1, fA3D);
  if (sm>0)
  {
     write_string0(fA3D, materiale->GetName());
	 //if (makeADP) fprintf(fADP, "     material=%c%s%c;\n", '"', materiale->GetName(), '"');
  }
  else
	 //if (makeADP) fprintf(fADP, "     material=%cNONE%c;\n", '"', '"');


  // ---------------   scrittura del punto di pivot   ----------------
  GetPivotOffset(node, &row);
  fprintf(fTXT, "Pivot point : %f, %f, %f\n", row.x, row.y, row.z);
  write_point3(&row, fA3D);

  // -------------------   scrittura matrice   -----------------------
  mat = node->GetNodeTM(0);
  write_matrix(&mat, fA3D);

  // ---------   scrittura dell'eventuale nome della mesh   ----------
  fwrite(&mf, sizeof(int), 1, fA3D);
  if (mf>0)
  {
    write_string0(fA3D, "TO_DO");
    if (makeADP) fprintf(fADP, "    lod=%cTO_DO, 0, 99999.99%c;\n", '"', '"');
  }


  // *************  ESPORAZIONE DATI DEL PARTCLE SYSTEM  *************
  float initVel, var, width, height;
  int count, life, start_time, stop_time;

  partsys->pblock->GetValue(PB_EMITTERWIDTH, 0, width, FOREVER);
  partsys->pblock->GetValue(PB_EMITTERHEIGHT, 0, height, FOREVER);
  partsys->pblock->GetValue(PB_SPEED, 0, initVel, FOREVER);
  partsys->pblock->GetValue(PB_VARIATION, 0, var, FOREVER);
  partsys->pblock->GetValue(PB_LIFETIME, 0, life, FOREVER);
  life=life/ GetTicksPerFrame();
  partsys->pblock->GetValue(PB_STARTTIME, 0, start_time, FOREVER);
  start_time=start_time / GetTicksPerFrame();
  stop_time=range.End() / GetTicksPerFrame();
  partsys->pblock->GetValue(PB_RNDPARTICLES, 0, count, FOREVER);

  fprintf(fTXT, "Emitter width: %f\n", width);
  fprintf(fTXT, "Emitter height: %f\n", height);
  fprintf(fTXT, "Emitter speed (init vel): %f\n", initVel);
  fprintf(fTXT, "Emitter variation: %f\n", var);
  fprintf(fTXT, "Life: %d\n", life);
  fprintf(fTXT, "Start time: %d\n", start_time);
  fprintf(fTXT, "Stop time: %d\n", stop_time);
  fprintf(fTXT, "Max particles: %d\n", count);

  // informazioni in formato binario (.A3D)
  fwrite(&width, sizeof(float), 1, fA3D);
  fwrite(&height, sizeof(float), 1, fA3D);
  fwrite(&initVel, sizeof(float), 1, fA3D);
  fwrite(&var, sizeof(float), 1, fA3D);
  fwrite(&life, sizeof(int), 1, fA3D);
  fwrite(&start_time, sizeof(int), 1, fA3D);
  fwrite(&stop_time, sizeof(int), 1, fA3D);
  fwrite(&count, sizeof(int), 1, fA3D);

  fwrite(&mod_count, sizeof(int), 1, fA3D);
  fprintf(fTXT, "Modificatori (wind, gravity, bomb) collegati: %d\n", mod_count);
  for (k=0; k<mod_count; k++)
  {
     fprintf(fTXT, "Modificatore %d: %s\n", k, modNames[k]);
	 write_string0(fA3D, modNames[k]);
	 //if (makeADP)
       //fprintf(fADP, "     modifier=%c%s, ON%c;\n", '"', modNames[k], '"');
  }


  //------------------------
  // ESPORTAZIONE KEYFRAMER
  //------------------------
  Control *c;
  int size_key;

  // NB: per gli oggetti mesh e quant'altre tipologie di
  // oggetti che possono essere linkati (ovvero dove e'
  // possibile implmenetare gerarchie), esporto SEMPRE una key 
  // di posizione, una di rotazione ed una di scaling
  // POSITION CONTROLLER
  c=node->GetTMController()->GetPositionController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=36;
	 else
	 if (IsBezierControl(c)) size_key=40;
	 else size_key=16;
	 fprintf(fTXT, "Particle position track present.\n");
     write_chunk_header(fA3D, POSITION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_point3_track(c, 1, fA3D);
  }
  else
  {
	fprintf(fTXT, "Particle position track present. (1 key case)\n");
	if (!c) 	fprintf(fTXT, "c nullo !\n");
    fflush(fTXT);
	size_key=36;
    write_chunk_header(fA3D, POSITION_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_point3_track(c, 1, fA3D);
  }


  // ROTATION CONTROLLER
  c=node->GetTMController()->GetRotationController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=40;
	 else size_key=20;
	 fprintf(fTXT, "Particle rotation track present.\n");
     write_chunk_header(fA3D, ROTATION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_rot_track(c, fA3D);
  }
  else
  {
	fprintf(fTXT, "Particle rotation track present. (1 key case)\n");
    fflush(fTXT);
	size_key=40;
    write_chunk_header(fA3D, ROTATION_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_rot_track(c, fA3D);
  }

  
  // SCALE CONTROLLER
  c=node->GetTMController()->GetScaleController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=36;
	 else
	 if (IsBezierControl(c)) size_key=40;
	 else size_key=16;
	 fprintf(fTXT, "Particle scaling track present.\n");
     write_chunk_header(fA3D, SCALE_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_scale_track(c, fA3D);
  }
  else
  {
	fprintf(fTXT, "Particle scaling track present. (1 key case)\n");
	size_key=36;
    write_chunk_header(fA3D, SCALE_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_scale_track(c, fA3D);
  }

  // keyframer emitter width
  c=partsys->pblock->GetController(PB_EMITTERWIDTH);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Particle emitter width track present.\n");
     write_chunk_header(fA3D, PARTICLE_EMITTER_WIDTH_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  // keyframer emitter length
  c=partsys->pblock->GetController(PB_EMITTERHEIGHT);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Particle emitter length track present.\n");
     write_chunk_header(fA3D, PARTICLE_EMITTER_LENGTH_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  // keyframer particles speed
  c=partsys->pblock->GetController(PB_SPEED);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Particle emitter speed track present.\n");
     write_chunk_header(fA3D, PARTICLE_EMITTER_SPEED_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  // keyframer particles variations
  c=partsys->pblock->GetController(PB_VARIATION);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Particle emitter variation track present.\n");
     write_chunk_header(fA3D, PARTICLE_EMITTER_VARIATION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }


  if (makeADP)
  {
    fprintf(fADP, "     texture=%cNONE%c;\n", '"', '"');
	my_ftoa(width, sval);
	fprintf(fADP, "     emitter_width=%c%s%c;\n", '"', sval, '"');
	my_ftoa(height, sval);
    fprintf(fADP, "     emitter_height=%c%s%c;\n", '"', sval, '"');
    fprintf(fADP, "     faded_particles=%cOFF%c;\n", '"', '"');
    fprintf(fADP, "     max_particles=%c%d%c;\n", '"', count, '"');
    fprintf(fADP, "     start_time=%c%d%c;\n", '"', start_time, '"');
    fprintf(fADP, "     end_time=%c%d%c;\n", '"', stop_time, '"');
    fprintf(fADP, "     life=%c%d%c;\n", '"', life, '"');
	my_ftoa(initVel, sval);
    fprintf(fADP, "     speed=%c%s%c;\n", '"', sval, '"');
	my_ftoa(var, sval);
    fprintf(fADP, "     variation=%c%s%c;\n", '"', sval, '"');
    fprintf(fADP, "     size_attenuation=%c0.4, 1.0, 0.8, 0.1%c;\n", '"', '"');
	fprintf(fADP, "  }\n\n");
  }
  fprintf(fTXT, "\n\n");
}
Exemplo n.º 14
0
// ***********************************************************
// ******************       VENTO      ***********************
// ***********************************************************
void SkeletonExporter::export_WSM_wind(INode *node)
{
  Point3 row;
  Matrix3 mat;
  Control *c;
  int size_key;
  char sval[50];

  ObjectState os = node->EvalWorldState(0);
  if (!os.obj) return;

  INode *padre=node->GetParentNode();
  int sf;

  if ((padre) && (strcmp(padre->GetName(), "Scene Root")!=0))
  sf=strlen(padre->GetName())+1;
  else sf=0;
  
  fprintf(fTXT, "Wind space modifier found\n");
  fprintf(fTXT, "Name : %s\n", node->GetName());
  // flag padre + nome padre + pivot + matrice(t=0) +
  // strenght + decay + mapping + turbolence + frequency + scale
  write_chunk_header(fA3D, WIND_MODIFIER_ID, node->GetName(),
	                 4+sf+12+48+4*6);
  fwrite(&sf, sizeof(int), 1, fA3D);
  if (sf>0) write_string0(fA3D, padre->GetName());

  // ---------------   scrittura del punto di pivot   ----------------
  GetPivotOffset(node, &row);
  fprintf(fTXT, "Pivot point : %f, %f, %f\n", row.x, row.y, row.z);
  write_point3(&row, fA3D);

  // -------------------   scrittura matrice   -----------------------
  mat = node->GetNodeTM(0);
  write_matrix(&mat, fA3D);

  float turb, decay, stren, freq, scale;
  int type=0;
  SimpleWSMObject2 *obj=(SimpleWSMObject2 *)os.obj;
  fflush(fTXT);

  export_animatable(obj->pblock2, 5);

  // -----------------------   strenght   -----------------------
  c=obj->pblock2->GetController(WPB_STRENGTH);
  if (c) c->GetValue(0, &stren, FOREVER);
  else obj->pblock2->GetValue(WPB_STRENGTH, 0, stren, FOREVER);
  fprintf(fTXT, "Strenght: %f\n", stren);   fflush(fTXT);
  
  // -----------------------   decay   -----------------------

  c=obj->pblock2->GetController(WPB_DECAY);
  if (c) c->GetValue(0, &decay, FOREVER);
  else obj->pblock2->GetValue(WPB_DECAY, 0, decay, FOREVER);
  fprintf(fTXT, "Decay: %f\n", decay);   fflush(fTXT);

  // -----------------------   type   -----------------------
  //obj->pblock2->GetValue(WPB_TYPE, 0, type, FOREVER);
  //obj->pblock2->GetController(WPB_TYPE)->GetValue(0, &type, FOREVER);
  type=0;
  fprintf(fTXT, "Type: %d\n", type);   fflush(fTXT);

  // -----------------------   turbulence   -----------------------
  c=obj->pblock2->GetController(WPB_TURBULENCE);
  if (c) c->GetValue(0, &turb, FOREVER);
  else obj->pblock2->GetValue(WPB_TURBULENCE, 0, turb, FOREVER);
  fprintf(fTXT, "Turbulence: %f\n", turb);   fflush(fTXT);

  // -----------------------   frequency   -----------------------
  c=obj->pblock2->GetController(WPB_FREQUENCY);
  if (c) c->GetValue(0, &freq, FOREVER);
  else obj->pblock2->GetValue(WPB_FREQUENCY, 0, freq, FOREVER);
  fprintf(fTXT, "Frequency: %f\n", freq);   fflush(fTXT);

  // -----------------------   scale   -----------------------
  c=obj->pblock2->GetController(WPB_SCALE);
  if (c) c->GetValue(0, &scale, FOREVER);
  else obj->pblock2->GetValue(WPB_SCALE, 0, scale, FOREVER);
  fprintf(fTXT, "Scale: %f\n", scale); fflush(fTXT);

  fwrite(&stren, sizeof(float), 1, fA3D);
  fwrite(&decay, sizeof(float), 1, fA3D);
  fwrite(&type, sizeof(int), 1, fA3D);
  fwrite(&turb, sizeof(float), 1, fA3D);
  fwrite(&freq, sizeof(float), 1, fA3D);
  fwrite(&scale, sizeof(float), 1, fA3D);


  //------------------------
  // ESPORTAZIONE KEYFRAMER
  //------------------------

  // POSITION CONTROLLER
  c=node->GetTMController()->GetPositionController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=36;
	 else
	 if (IsBezierControl(c)) size_key=40;
	 else size_key=16;
	 fprintf(fTXT, "Object position track present.\n");
     write_chunk_header(fA3D, POSITION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_point3_track(c, 1, fA3D);
  }
  else
  {
	fprintf(fTXT, "Object position track present. (1 key case)\n");
	size_key=36;
    write_chunk_header(fA3D, POSITION_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_point3_track(c, 1, fA3D);
  }

  // ROTATION CONTROLLER
  c=node->GetTMController()->GetRotationController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=40;
	 else size_key=20;
	 fprintf(fTXT, "Object rotation track present.\n");
     write_chunk_header(fA3D, ROTATION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_rot_track(c, fA3D);
  }
  else
  {
	fprintf(fTXT, "Object rotation track present. (1 key case)\n");
	size_key=40;
    write_chunk_header(fA3D, ROTATION_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_rot_track(c, fA3D);
  }

  // SCALE CONTROLLER
  c=node->GetTMController()->GetScaleController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=36;
	 else
	 if (IsBezierControl(c)) size_key=40;
	 else size_key=16;
	 fprintf(fTXT, "Wind scaling track present.\n");
     write_chunk_header(fA3D, SCALE_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_scale_track(c, fA3D);
  }
  else
  {
	fprintf(fTXT, "Wind scaling track present. (1 key case)\n");
	size_key=36;
    write_chunk_header(fA3D, SCALE_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_scale_track(c, fA3D);
  }

  // wind strength keyframer
  c=obj->pblock2->GetController(WPB_STRENGTH);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Wind strength track present.\n");
     write_chunk_header(fA3D, WIND_STRENGTH_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  // wind decay keyframer
  c=obj->pblock2->GetController(WPB_DECAY);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Wind decay track present.\n");
     write_chunk_header(fA3D, WIND_DECAY_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  // wind turbolence keyframer
  c=obj->pblock2->GetController(WPB_TURBULENCE);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Wind turbolence track present.\n");
     write_chunk_header(fA3D, WIND_TURBOLENCE_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  // wind frequency keyframer
  c=obj->pblock2->GetController(WPB_FREQUENCY);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Wind frequency track present.\n");
     write_chunk_header(fA3D, WIND_FREQUENCY_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  // wind scale keyframer
  c=obj->pblock2->GetController(WPB_SCALE);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Wind scale(parameter) track present.\n");
     write_chunk_header(fA3D, WIND_SCALE_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  if (makeADP)
  {
    fprintf(fADP, "  windWSM %c%s%c\n  {\n", '"', node->GetName(), '"');
	if (type==0)
      fprintf(fADP, "     type=%c%PLANAR%c;\n", '"', '"');
	else
    fprintf(fADP, "     type=%c%SPHERICAL%c;\n", '"', '"');
    my_ftoa(stren, sval);
    fprintf(fADP, "     strength=%c%s%c;\n", '"', sval, '"');
    my_ftoa(decay, sval);
    fprintf(fADP, "     decay=%c%s%c;\n", '"', sval, '"');
    my_ftoa(turb, sval);
    fprintf(fADP, "     turbolence=%c%s%c;\n", '"', sval, '"');
    my_ftoa(freq, sval);
    fprintf(fADP, "     frequency=%c%s%c;\n", '"', sval, '"');
    my_ftoa(scale, sval);
    fprintf(fADP, "     scale=%c%s%c;\n", '"', sval, '"');
	fprintf(fADP, "  }\n\n");
  }
  fprintf(fTXT, "\n\n");
  fflush(fTXT);
  if (makeADP) fflush(fADP);
}
Exemplo n.º 15
0
// ***********************************************************
// ******************      GRAVITA'    ***********************
// ***********************************************************
void SkeletonExporter::export_WSM_gravity(INode *node)
{
  Matrix3 mat;
  Point3 row;
  float decay, stren;
  int type;
  char sval[50];

  ObjectState os = node->EvalWorldState(0);
  if (!os.obj) return;

  mat = node->GetNodeTM(0);

  INode *padre=node->GetParentNode();
  int sf;

  if ((padre) && (strcmp(padre->GetName(), "Scene Root")!=0))
  sf=strlen(padre->GetName())+1;
  else sf=0;

  fprintf(fTXT, "Gravity space modifier found\n");
  fprintf(fTXT, "Name : %s\n", node->GetName());
  // flag padre + nome padre + strenght + decay + mapping +
  // world position
  write_chunk_header(fA3D, GRAVITY_MODIFIER_ID, node->GetName(),
	                 4+sf+12+48+3*4);
  fwrite(&sf, sizeof(int), 1, fA3D);
  if (sf>0) write_string0(fA3D, padre->GetName());

  // ---------------   scrittura del punto di pivot   ----------------
  GetPivotOffset(node, &row);
  fprintf(fTXT, "Pivot point : %f, %f, %f\n", row.x, row.y, row.z);
  write_point3(&row, fA3D);

  // -------------------   scrittura matrice   -----------------------
  mat = node->GetNodeTM(0);
  write_matrix(&mat, fA3D);

  SimpleWSMObject2 *obj=(SimpleWSMObject2 *)os.obj;

  obj->pblock2->GetValue(GPB_STRENGTH, 0, stren, FOREVER);
  obj->pblock2->GetValue(GPB_DECAY, 0, decay, FOREVER);
  //obj->pblock2->GetValue(GPB_TYPE, 0, type, FOREVER);
  type=0;

  fprintf(fTXT, "Strength: %f\n", stren);
  fprintf(fTXT, "Decay: %f\n", decay);
  fprintf(fTXT, "Type: %d\n", type);

  fwrite(&stren, sizeof(float), 1, fA3D);
  fwrite(&decay, sizeof(float), 1, fA3D);
  fwrite(&type, sizeof(int), 1, fA3D);

  //------------------------
  // ESPORTAZIONE KEYFRAMER
  //------------------------
  Control *c;
  int size_key;

  // POSITION CONTROLLER
  c=node->GetTMController()->GetPositionController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=36;
	 else
	 if (IsBezierControl(c)) size_key=40;
	 else size_key=16;
	 fprintf(fTXT, "Object position track present.\n");
     write_chunk_header(fA3D, POSITION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_point3_track(c, 1, fA3D);
  }
  else
  {
	fprintf(fTXT, "Object position track present. (1 key case)\n");
	size_key=36;
    write_chunk_header(fA3D, POSITION_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_point3_track(c, 1, fA3D);
  }

  // ROTATION CONTROLLER
  c=node->GetTMController()->GetRotationController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=40;
	 else size_key=20;
	 fprintf(fTXT, "Object rotation track present.\n");
     write_chunk_header(fA3D, ROTATION_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_rot_track(c, fA3D);
  }
  else
  {
	fprintf(fTXT, "Object rotation track present. (1 key case)\n");
	size_key=40;
    write_chunk_header(fA3D, ROTATION_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_rot_track(c, fA3D);
  }

  // SCALE CONTROLLER
  c=node->GetTMController()->GetScaleController();
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=36;
	 else
	 if (IsBezierControl(c)) size_key=40;
	 else size_key=16;
	 fprintf(fTXT, "Gravity scaling track present.\n");
     write_chunk_header(fA3D, SCALE_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_scale_track(c, fA3D);
  }
  else
  {
	fprintf(fTXT, "Gravity scaling track present. (1 key case)\n");
	size_key=36;
    write_chunk_header(fA3D, SCALE_TRACK_ID,
	                   node->GetName(), 1+2+4+1*size_key);
    export_1key_scale_track(c, fA3D);
  }

  // gravity strength keyframer
  c=obj->pblock2->GetController(GPB_STRENGTH);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Gravity strength track present.\n");
     write_chunk_header(fA3D, GRAVITY_STRENGTH_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  // gravity decay keyframer
  c=obj->pblock2->GetController(GPB_DECAY);
  if ((c) && (c->NumKeys()>0))
  {
	 if (IsTCBControl(c)) size_key=28;
	 else
	 if (IsBezierControl(c)) size_key=16;
	 else size_key=8;
	 fprintf(fTXT, "Gravity decay track present.\n");
     write_chunk_header(fA3D, GRAVITY_DECAY_TRACK_ID,
	                    node->GetName(), 1+2+4+c->NumKeys()*size_key);
     export_float_track(c, 1, fA3D);
  }

  if (makeADP)
  {
    fprintf(fADP, "  gravityWSM %c%s%c\n  {\n", '"', node->GetName(), '"');
	if (type==0)
      fprintf(fADP, "     type=%c%PLANAR%c;\n", '"', '"');
	else
    fprintf(fADP, "     type=%c%SPHERICAL%c;\n", '"', '"');
	my_ftoa(stren, sval);
    fprintf(fADP, "     strength=%c%s%c;\n", '"', sval, '"');
    my_ftoa(decay, sval);
    fprintf(fADP, "     decay=%c%s%c;\n", '"', sval, '"');
	fprintf(fADP, "  }\n\n");
  }
  fprintf(fTXT, "\n\n");
}