Author Topic: Scene .SCO Toolset - heightmap converters, object placers, and texture importers! Oh my!  (Read 4897 times)

0 Members and 1 Guest are viewing this topic.

Barabas

  • Master Knight
  • *
    • View Profile
  • Faction: Neutral
  • MP nick: Bassa Bar
  • WB
Hmm.... I'll take a look at it again.

cmpxchg8b

  • Modder++
  • Grandmaster Knight
  • *
  • Master of rglPool
    • View Profile
  • Faction: Vaegir
  • MP nick: cmp
  • M&BWBWF&SNW
Unless it's secret you can post it (or a snippet) here...
Warband Script Enhancer v3.1.5 - additional operations, game scripts and triggers for Warband modders

Barabas

  • Master Knight
  • *
    • View Profile
  • Faction: Neutral
  • MP nick: Bassa Bar
  • WB
It's no secret!  :D I just forgot to use version control so I do not know what went wrong yesterday. I got it working now without union stuff :) I guess I didn't cast it correctly yesterday or so.... who knows what I did at night  :lol:

I was wondering, does the random terrain generation from a terrainkey also contain vertex painting? I can't quite find it in the code, but I would think it should be in there somewhere.

So far I can write out the terrain mesh with the normals (not sure if they're working right) and the vertex colors from the sco file.
(click to show/hide)
« Last Edit: May 28, 2012, 01:17:49 PM by Barabas »

cmpxchg8b

  • Modder++
  • Grandmaster Knight
  • *
  • Master of rglPool
    • View Profile
  • Faction: Vaegir
  • MP nick: cmp
  • M&BWBWF&SNW
I was wondering, does the random terrain generation from a terrainkey also contain vertex painting? I can't quite find it in the code, but I would think it should be in there somewhere.
It does, yes, but since I omitted the whole part that generates meshes it's not in the TerrainGenerator source.
Warband Script Enhancer v3.1.5 - additional operations, game scripts and triggers for Warband modders

Barabas

  • Master Knight
  • *
    • View Profile
  • Faction: Neutral
  • MP nick: Bassa Bar
  • WB
I've got a problem that sometimes my program crashes trying to write the final sco file. I checked, it can open it fine, it just fails as soon as it tries to write the SCO_MAGIC  :(

I first read from the sco file and later try to overwrite it again with updated terrain info, maybe this doesn't work too well??
Code: [Select]
int convert_obj_to_sco(char* file_name_obj, char* terrain_key, char* file_name_sco)
{

FILE *file_obj = fopen(file_name_obj, "rt");;
if (file_obj==NULL)
{
printf("ERROR: file %s could not be opened.\n", file_name_obj);
return EXIT_FAILURE;
}
int c = fgetc(file_obj);
unsigned int n_vertices = 0;
while(c != EOF && c!='f')
{
if(c=='v')
{
++n_vertices;
}
c = fgetc(file_obj);
}
printf("counted vertices %u\n", n_vertices);
rewind(file_obj);

vector_t *vertices = new vector_t[n_vertices];
char temp[10];
for(c = 0; c<n_vertices; ++c)
{
fscanf(file_obj, "%s", temp);
fscanf(file_obj, "%f" , &(vertices+c)->x);
fscanf(file_obj, "%f" , &(vertices+c)->y);
fscanf(file_obj, "%f" , &(vertices+c)->z);
}
printf("exctracted vertices\n");

sco_file_t sco_file;

FILE *file_sco = fopen(file_name_sco, "rb");
if(file_sco==NULL)
{
printf("Failed to open file %s\n", file_name_sco );
return EXIT_FAILURE;
}
printf("Opened file %s with address %p\n",file_name_sco, file_sco );
read_sco_file(file_sco, &sco_file);

printf("Sco file loaded.\n");

TerrainGenerator *terrainGen; // too big for stack
try
{
terrainGen = new TerrainGenerator();
terrainGen->setTerrainCode(terrain_key);
terrainGen->generate();
}
catch (...) // just for SEH, needs /EHa
{
printf("exception while generating terrain. check your input mang :[\n");
system("pause");
return EXIT_FAILURE;
}

printf("Terrain generated.\n");

ground_paint_t* ground_paint = sco_file.ground_paint;
if( ground_paint->size_x != terrainGen->m_numFaces[0]+1 || ground_paint->size_y != terrainGen->m_numFaces[1]+1 )
{
printf("Sco object and terrain key don't match in size.\n");
return EXIT_FAILURE;
}

qsort(vertices, n_vertices, sizeof(vector_t), comp_vertices);
printf("Vertices from .obj sorted.\n");

int l;
for ( l = 0; l < ground_paint->num_layers; ++l)
{
if( ground_paint->layers[l].ground_spec_no == GROUND_PAINT_ELEVATION_MAGIC)
{
printf("Elevation layer found.\n");

ground_paint->layers[l].cells = new float[ground_paint->size_x*ground_paint->size_y];
ground_paint->layers[l].continuity_count = new int[ground_paint->size_x*ground_paint->size_y];
printf("Ground paint size: %i, %i.\n",ground_paint->size_x, ground_paint->size_x );
printf("New cells created.\n");
int x, y, count = 0;
ground_paint->layers[l].continuity_count[ground_paint->size_x*ground_paint->size_y] = 0;//ground_paint->size_x*ground_paint->size_y;
for(x=0; x<ground_paint->size_x;++x)
{
for(y=0; y<ground_paint->size_y; ++y)
{
ground_paint->layers[l].continuity_count[count]=ground_paint->size_x*ground_paint->size_y-count-1;
ground_paint->layers[l].cells[count] = vertices[x * ground_paint->size_y + y].z -terrainGen->m_vertices[x][y].m_position.z;
++count;
}
}
}
}


printf("Closed sco file.\n");
if( (file_sco = fopen(file_name_sco, "wb"))==NULL)
{
printf("Failed to open %s\n",file_name_sco );
return EXIT_FAILURE;
}
printf("Writing file %s with addres %p\n",file_name_sco, file_sco);
write_sco_file(file_sco, &sco_file);

return EXIT_FAILURE;
}

Just using the earlier posted write and read code.

EDIT:

Found the problem!
Code: [Select]
ground_paint->layers[l].continuity_count = new int[ground_paint->size_x*ground_paint->size_y];should be
Code: [Select]
ground_paint->layers[l].continuity_count = new int[ground_paint->size_x*ground_paint->size_y+1];
« Last Edit: June 02, 2012, 07:56:36 PM by Barabas »

Capsaicin

  • Recruit
  • *
    • View Profile
  • Faction: Neutral
I'm trying to make scenes for NW and everytime I try to use PNG to SCO, it crashes.  :(  Any help?