Commit d7c11fba authored by Seth Carter's avatar Seth Carter
Browse files

Merge branch '30-drop-support-for-s3dm' into 'master'

Resolve "Drop support for S3DM"

Closes #30

See merge request rsethc/slice!15
parents 75cdf88f d15edf3d
Pipeline #242414377 passed with stage
in 6 minutes and 20 seconds
......@@ -3,9 +3,10 @@
*.dll
*.a
*.o
*.depend
*.depend
*.layout
package/
*.zip
.vscode/
.DS_Store
\ No newline at end of file
.DS_Store
bin/
......@@ -30,17 +30,14 @@ SLICE3D_OBJS = $(patsubst %.cpp,%.o,$(shell find src/slice3d -iname '*.cpp'))
SLICEGRAPHS_OBJS = $(patsubst %.cpp,%.o,$(shell find src/slicegraphs -iname '*.cpp'))
all: $(PRODUCTS)
g++ -fpermissive src/modelcompiler/main.cpp -o src/modelcompiler/compile-s3dm
g++ -fpermissive src/s3dm-to-obj/s3dm-src-to-obj.cpp -o src/s3dm-to-obj/s3dm-src-to-obj
g++ -fpermissive src/s3dm-to-obj/s3dm-to-obj.cpp -o src/s3dm-to-obj/s3dm-to-obj
install: all
install src/modelcompiler/compile-s3dm /usr/local/bin
install $(PRODUCTS) $(TARGET_LIB_DIR)
cp -r include/* $(TARGET_INCLUDE_DIR)
mkdir -p /usr/local/slice-utils
cp src/obj-to-s3dm-src/ObjToS3dmSrc.java /usr/local/slice-utils
install src/obj-to-s3dm-src/obj-to-s3dm-src /usr/local/bin
install src/convert-every-obj /usr/local/bin
install src/compile-every-s3dm /usr/local/bin
install src/s3dm-to-obj/s3dm-src-to-obj /usr/local/bin
install src/s3dm-to-obj/s3dm-to-obj /usr/local/bin
libslice.a: $(SLICE_OBJS) third-party/glad-3.1/src/glad.o
ar -cr $@ $^
......
......@@ -10,7 +10,6 @@ RUN apt-get -y update; \
libsdl2-ttf-dev \
libogg-dev \
libvorbis-dev \
default-jre \
curl
# Note about tzdata install: we have to explicitly set the noninteractive
# frontend to the package manager, or otherwise it will hold up the GitLab
......
......@@ -7,7 +7,6 @@ RUN apt-get -y update; \
build-essential \
gcc-mingw-w64 \
g++-mingw-w64 \
default-jre \
curl \
zip
# Note about tzdata install: we have to explicitly set the noninteractive
......
#!/bin/sh
set -eux
docker build . -f builders/ubuntu/Dockerfile -t slice-builder-ubuntu
docker create --name slice-builder-ubuntu slice-builder-ubuntu
mkdir -p bin
docker cp slice-builder-ubuntu:/usr/local/bin/s3dm-src-to-obj bin/s3dm-src-to-obj
docker cp slice-builder-ubuntu:/usr/local/bin/s3dm-to-obj bin/s3dm-to-obj
docker rm slice-builder-ubuntu
......@@ -275,8 +275,10 @@ struct s3dMesh
//float* vertices;
GLuint vertex_buffer,vertex_array;
uint32_t triangle_count;
GLcolor3 diffuse_color, ambient_color, specular_color;
GLfloat specular_exponent;
bool mag_filter_nearest; // if set to true, use GL_NEAREST as texture magnification filter. Otherwise use LINEAR.
};
struct s3dModel
......@@ -294,15 +296,8 @@ struct s3dModel
SDL_AtomicDecRef(&usages);
};
};
s3dModel* s3dLoadModel (char* modelpath, /* TEMPORARY: Will be removed! ---> */ s3dVec3 mesh_points_offset = s3dVec3(0), slScalar scaling = 1);
s3dModel* s3dLoadObj (char* basepath, char* filename, /* TEMPORARY: Will be removed! ---> */ s3dVec3 mesh_points_offset = s3dVec3(0), slScalar scaling = 1);
s3dModel* s3dSpriteModel (
slTexture* texref = NULL,
GLcolor3 ambient_color = objFallbackMaterial.ambient_color,
GLcolor3 diffuse_color = objFallbackMaterial.diffuse_color,
GLcolor3 specular_color = objFallbackMaterial.specular_color,
GLfloat specular_exponent = objFallbackMaterial.specular_exponent
);
s3dModel* s3dLoadObj (char* basepath, char* filename);
s3dModel* s3dSpriteModel (slTexture* texref = NULL, objMaterial material = objFallbackMaterial);
struct s3dObject
{
......
......@@ -37,6 +37,7 @@ struct objMaterial
float specular_exponent;
char* texpath; // will be NULL if not specified by the file
char* bump_texpath; // will be NULL if not specified by the file
char mag_filter_nearest;
};
extern objMaterial objFallbackMaterial;
struct objGroup
......
#!/bin/sh
set -eux
S3DM_SRCS=$(find /game/built -iname '*.s3dm-src')
for S3DM_SRC in $S3DM_SRCS; do
compile-s3dm $S3DM_SRC > /dev/null
rm $S3DM_SRC
done
#!/bin/sh
set -eux
OBJS=$(find /game/built -iname '*.obj')
for OBJ in $OBJS; do
obj-to-s3dm-src $OBJ no-texture
done
rmdir /s /q "package"
mkdir "package"
mkdir "package/bin"
xcopy /y /e /s "windows dlls" "package/bin"
mkdir "package/dependencies"
xcopy /y /e /s "dependencies" "package/dependencies"
mkdir "package/lib"
mkdir "package/include"
copy "libslice.a" "package/lib/libslice.a"
copy "slice.h" "package/include/slice.h"
mkdir "package/include/slice"
xcopy /y /e /s /exclude:createpackage_excludes.txt "slice" "package/include/slice"
rmdir /s /q "package/include/slice/obj"
copy "libslicefps.a" "package/lib/libslicefps.a"
copy "slicefps.h" "package/include/slicefps.h"
copy "libsliceopts.a" "package/lib/libsliceopts.a"
copy "sliceopts.h" "package/include/sliceopts.h"
copy "libslice2d.a" "package/lib/libslice2d.a"
copy "slice2d.h" "package/include/slice2d.h"
mkdir "package/include/slice2d"
xcopy /y /e /s /exclude:createpackage_excludes.txt "slice2d" "package/include/slice2d"
rmdir /s /q "package/include/slice2d/obj"
copy "libslice3d.a" "package/lib/libslice3d.a"
copy "slice3d.h" "package/include/slice3d.h"
mkdir "package/include/slice3d"
xcopy /y /e /s /exclude:createpackage_excludes.txt "slice3d" "package/include/slice3d"
rmdir /s /q "package/include/slice3d/obj"
copy "libslicegraphs.a" "package/lib/libslicegraphs.a"
copy "slicegraphs.h" "package/include/slicegraphs.h"
mkdir "package/include/slicegraphs"
xcopy /y /e /s /exclude:createpackage_excludes.txt "slicegraphs" "package/include/slicegraphs"
rmdir /s /q "package/include/slicegraphs/obj"
mkdir "package/tools"
copy "compile-model.exe" "package/tools/compile-model.exe"
copy "print-model.exe" "package/tools/print-model.exe"
copy "version.txt" "package/version.txt"
mkdir "package/changelogs/"
xcopy /y /s /e "changelogs" "package/changelogs"
mkdir "package/include/Box2D"
xcopy /y /e /s /exclude:createpackage_excludes.txt "Box2D/Box2D" "package/include/Box2D"
copy Box2D\compiled\libbox2d.a "package/lib/libbox2d.a"
mkdir "package/bullet287-src"
xcopy /y /e /s /exclude:createpackage_excludes.txt "bullet3-2.87/src" "package/bullet287-src"
copy bullet287-build\libbullet.a "package/lib/libbullet.a"
mkdir "package/include"
xcopy /y /e /s "glad-3.0/include" "package/include"
copy "version.txt" "L:/slice-site/version.txt"
mkdir "L:/slice-site/changelogs/"
xcopy /y /s /e "changelogs" "L:/slice-site/changelogs"
START "Slice Site Rebuild" /wait /d "L:/slice-site_dev/" "L:/slice-site_dev/site.sub"
echo "Done"
.cpp
.c
.txt
.lua
.cmake
.cbp
.depend
.layout
\ No newline at end of file
#include <stdio.h>
#include <stdint.h>
int main (int argc, char** argv)
{
if (argc < 2)
{
printf("(!) No file path given.\n");
return -1;
};
FILE* file = fopen(argv[1],"rb");
if (!file)
{
printf("(!) Cannot open binary file.\n");
return -2;
};
uint32_t meshcount;
fread(&meshcount,4,1,file);
printf("Mesh Count: %u\n\n",meshcount);
while (meshcount--)
{
printf("{\n");
uint32_t len;
fread(&len,4,1,file);
printf("\tTexture String Length: %u\n\n",len);
printf("\t\"");
while (len--) putchar(fgetc(file));
printf("\"\n");
uint32_t tricount;
fread(&tricount,4,1,file);
printf("\n\tTriangle Count: %u\n",tricount);
while (tricount--)
{
float values [15];
fread(values,4,15,file);
printf(
"\n\t%.2f %.2f %.2f / %.2f %.2f,\n\t%.2f %.2f %.2f / %.2f %.2f,\n\t%.2f %.2f %.2f / %.2f %.2f;\n",
values[0],values[1],values[2],values[3],values[4],values[5],values[6],values[7],values[8],values[9],values[10],values[11],values[12],values[13],values[14]
);
};
printf("}\n\n");
};
return 0;
};
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.regex.Pattern;
/**
* @author Seth
*/
public class ObjToS3dmSrc
{
static void Convert (String path, String texvalue, double factor) throws FileNotFoundException, IOException
{
String basename = path.substring(0,path.length() - 4);// remove the '.obj'
String outpath = basename + ".s3dm-src";
BufferedReader file = new BufferedReader(new FileReader(path));
class Vec3 { double x,y,z; Vec3(double x,double y,double z){this.x=x;this.y=y;this.z=z;} }
ArrayList<Vec3> vertices = new ArrayList();
ArrayList<Vec3> normals = new ArrayList();
class WholeVertex {Vec3 pos,normal; WholeVertex (int pos_location, int normal_location) { pos = vertices.get(pos_location); normal = normals.get(normal_location); } }
class Face { LinkedList<WholeVertex> vertices=new LinkedList(); }
ArrayList<Face> faces = new ArrayList();
int line_id = 0;
while (true)
{
String line = file.readLine();
if (line == null) break;
//System.out.println("line "+ ++line_id);
Scanner line_scan = new Scanner(line);
if (!line_scan.hasNext()) continue;
String type = line_scan.next();
switch (type)
{
case "v": vertices.add(new Vec3(line_scan.nextDouble(),line_scan.nextDouble(),line_scan.nextDouble())); break;
case "vn": normals.add(new Vec3(line_scan.nextDouble(),line_scan.nextDouble(),line_scan.nextDouble())); break;
case "f":
Face face = new Face();
faces.add(face);
while (line_scan.hasNext())
{
String vert_str = line_scan.next();
vert_str = vert_str.replace('/',' ');
//System.out.println("vert_str "+vert_str);
Scanner vert_scan = new Scanner(vert_str);
//System.out.println("vertpos "+vert_scan.next());
//System.out.println("normpos "+vert_scan.next());
int vertpos = vert_scan.nextInt();
int normpos = vert_scan.nextInt();
face.vertices.add(new WholeVertex(vertpos-1,normpos-1));
}
}
}
PrintStream out = new PrintStream(outpath);
out.printf("{\n\t\"%s\"\n",texvalue);
for (Face face : faces)
{
out.printf("\n\n\n");
WholeVertex a=null,b=null,c=null;
int n=1;
for (WholeVertex vert : face.vertices)
{
if (n==1) a=vert;
b=c;c=vert;
if (n>3) out.printf("\n");
if (n>=3)
{
out.printf(
"\t%f %f %f / 0 0,\n"+
"\t%f %f %f / 0 0,\n"+
"\t%f %f %f / 0 0;\n",
a.pos.x*factor,a.pos.y*factor,a.pos.z*factor,
b.pos.x*factor,b.pos.y*factor,b.pos.z*factor,
c.pos.x*factor,c.pos.y*factor,c.pos.z*factor
);
}
n++;
}
}
out.printf("}\n");
}
public static void main(String[] args) throws FileNotFoundException, IOException
{
if (args.length < 2 || args.length > 3)
{
System.out.println("usage:");
System.out.println("\tjava ObjToS3dmSrc.java obj_path texture_path");
System.out.println("\tjava ObjToS3dmSrc.java obj_path texture_path scaling_factor");
System.exit(1);
}
else
{
double scaling_factor;
if (args.length >= 3) scaling_factor = Double.parseDouble(args[2]);
else scaling_factor = 1;
Convert(args[0],args[1],scaling_factor);
}
}
}
#!/bin/sh
java /usr/local/slice-utils/ObjToS3dmSrc.java $@
......@@ -23,25 +23,20 @@ char* strclone (char* str)
memcpy(out,str,size);
return out;
};
int main (int argc, char** argv)
int convert_one (char* in_path)
{
if (argc < 2)
{
printf("(!) No file path given.\n");
return -1;
};
FILE* src = fopen(argv[1],"r");
FILE* src = fopen(in_path,"r");
if (!src)
{
printf("(!) Cannot open source file.\n");
return -2;
};
char* outpath;
size_t inlen = strlen(argv[1]);
size_t inlen = strlen(in_path);
if (inlen < 5) outpath = strclone(".s3dm");
else
{
outpath = strclone(argv[1]);
outpath = strclone(in_path);
outpath[inlen - 4] = 0;
};
printf("Output Path: \"%s\"\n\n",outpath);
......@@ -139,6 +134,44 @@ int main (int argc, char** argv)
fseek(outfile,0,SEEK_SET);
uint32_t sectioncount = MeshCount;
fwrite(&sectioncount,4,1,outfile);
printf("Finished\n");
return 0;
fclose(outfile); // Must close this before running the other program,
// otherwise the file could appear to be empty or incomplete since not all
// contents would have been flushed to disk potentially.
printf("Finished compiling S3DM\n");
printf("Converting compiled S3DM to Obj\n");
char* cmd;
asprintf(&cmd,"s3dm-to-obj '%s'\n",outpath);
int to_obj_result = system(cmd);
free(cmd);
if (to_obj_result) printf("FAILED to convert S3DM to Obj ('%s').\n",outpath);
else printf("Finished converting S3DM to Obj\n");
remove(outpath); // delete the compiled s3dm file since it was temporary
free(outpath);
return to_obj_result;
};
int main (int argc, char** argv)
{
if (argc < 2)
{
printf("(!) No input file path(s) given.\n");
return -1;
};
int all_result = 0;
int successful = 0;
for (int i = 1; i < argc; i++)
{
char* in_path = argv[i];
printf("Converting '%s'\n",in_path);
int one_result = convert_one(in_path);
if (one_result)
{
printf("Failed to convert '%s'!\n",in_path);
all_result = 1;
}
else successful++;
}
printf("%d/%d succeeded\n",successful,argc-1);
return all_result;
}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int convert_one (char* in_path)
{
char* obj_path;
asprintf(&obj_path,"%s.obj",in_path);
char* mtl_path;
asprintf(&mtl_path,"%s.mtl",in_path);
FILE* in_file = fopen(in_path,"rb");
FILE* obj_file = fopen(obj_path,"w");
FILE* mtl_file = fopen(mtl_path,"w");
free(obj_path);
free(mtl_path);
if (!in_file || !obj_file || !mtl_file)
{
if (!in_file) printf("(!) Can't open input file '%s'\n",in_path);
else fclose(in_file);
if (!obj_file) printf("(!) Can't open output file '%s'\n",obj_path);
else fclose(obj_file);
if (!mtl_file) printf("(!) Can't open output file '%s'\n",mtl_path);
else fclose(mtl_file);
return 1;
}
fprintf(obj_file,"mtllib %s.mtl\n",in_path);
uint32_t meshcount;
fread(&meshcount,4,1,in_file);
printf("Mesh Count: %u\n\n",meshcount);
int global_v_id = 1;
int mat_name = 0;
while (meshcount--)
{
// Declare a new material and refer to it in the main file.
fprintf(mtl_file,"newmtl %d\n",mat_name);
fprintf(obj_file,"usemtl %d\n",mat_name);
mat_name++;
// Put the texture path into the material definition.
uint32_t len;
fread(&len,4,1,in_file);
fprintf(mtl_file,"map_Ka ");
while (len--) fputc(fgetc(in_file),mtl_file);
fputc('\n',mtl_file);
fprintf(mtl_file,"mag_filter_nearest\n");
uint32_t tricount;
fread(&tricount,4,1,in_file);
printf("\n\tTriangle Count: %u\n",tricount);
while (tricount--)
{
float values [15];
fread(values,4,15,in_file);
for (int offset = 0; offset < 15; offset += 5)
{
fprintf(obj_file, "v %f %f %f\n", values[offset+0], values[offset+1], values[offset+2]);
fprintf(obj_file, "vt %f %f\n", values[offset+3], 1-values[offset+4]);
}
int a = global_v_id++;
int b = global_v_id++;
int c = global_v_id++;
fprintf(obj_file, "f %d/%d %d/%d %d/%d\n", a, a, b, b, c, c);
};
};
fprintf(obj_file,"# This line indicates the file is complete.\n");
fprintf(mtl_file,"# This line indicates the file is complete.\n");
fclose(in_file);
fclose(obj_file);
fclose(mtl_file);
return 0;
};
int main (int argc, char** argv)
{
if (argc < 2)
{
printf("(!) No input file path(s) given.\n");
return -1;
}
int all_result = 0;
int successful = 0;
for (int i = 1; i < argc; i++)
{
char* in_path = argv[i];
printf("Converting '%s'\n",in_path);
int one_result = convert_one(in_path);
if (one_result)
{
printf("Failed to convert '%s'!\n",in_path);
all_result = 1;
}
else successful++;
}
printf("%d/%d succeeded\n",successful,argc-1);
return all_result;
}
......@@ -5,7 +5,8 @@ objMaterial objFallbackMaterial =
{1,1,1},{1,1,1},{1,1,1},
250,
NULL,
NULL
NULL,
0
};
void objDiscardRemainingLine (FILE* file)
{
......@@ -292,6 +293,10 @@ int objReadMaterials (FILE* file, objModel* model, int& material_capacity, char*
current_material->bump_texpath = objFilePath(basepath,filename);
if (basepath) free(filename); // only free if texpath was separately allocated
}
else if (!strcmp(keyword,"mag_filter_nearest")) /* custom */
{
current_material->mag_filter_nearest = 1;
}
else
{
free(keyword);
......@@ -374,9 +379,18 @@ int objParseFile (FILE* file, objModel* model, char* basepath)
printf("vertex position index missing\n");
return 1; // You MUST have a Vertex Position!
}
if (objLexExpectChar(file,'/')) continue;
if (objLexExpectChar(file,'/'))
{
ref->tex_id = 0;
ref->normal_id = 0;
continue;
}
if (objLexInt(file,&ref->tex_id)) ref->tex_id = 0;
if (objLexExpectChar(file,'/')) continue;
if (objLexExpectChar(file,'/'))
{
ref->normal_id = 0;
continue;