Changed to class module template and default export

This commit is contained in:
Ben Coleman 2018-06-25 09:13:16 +01:00
parent 9d1ae4c65e
commit d1e2fcdf69
2 changed files with 49 additions and 43 deletions

View File

@ -3,45 +3,53 @@
// Definitions by: Ben Coleman <https://github.com/benc-uk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export default class Parser {
export as namespace ObjFileParser;
/* Class module */
declare class ObjFileParser {
constructor(fileContents: any, defaultModelName?: any);
parse(): ObjFile;
parse(): ObjFileParser.ObjFile;
}
export interface ObjFile {
models: ObjModel[];
materialLibraries: any[];
/* Additional exported interfaces */
declare namespace ObjFileParser {
interface ObjFile {
models: ObjModel[];
materialLibraries: any[];
}
interface ObjModel {
name: string;
vertices: Vertex[];
textureCoords: VertexTexture[];
vertexNormals: Vertex[];
faces: Face[];
}
interface Face {
material: any;
group: string;
smoothingGroup: number;
vertices: FaceVertex[];
}
interface FaceVertex {
vertexIndex: number;
textureCoordsIndex: number;
vertexNormalIndex: number;
}
interface Vertex {
x: number;
y: number;
z: number;
}
interface VertexTexture {
u: number;
v: number;
w: number;
}
}
export class ObjModel {
name: string;
vertices: Vertex[];
textureCoords: VertexTexture[];
vertexNormals: Vertex[];
faces: Face[];
}
export class Face {
material: any;
group: string;
smoothingGroup: number;
vertices: FaceVertex[];
}
export class FaceVertex {
vertexIndex: number;
textureCoordsIndex: number;
vertexNormalIndex: number;
}
export class Vertex {
x: number;
y: number;
z: number;
}
export class VertexTexture {
u: number;
v: number;
w: number;
}
export = ObjFileParser;

View File

@ -1,5 +1,3 @@
import ObjFileParser, { ObjModel, ObjFile, Vertex, Face, FaceVertex } from 'obj-file-parser';
const testObjFile = `
# cube.obj
# Example object
@ -42,14 +40,14 @@ const parser = new ObjFileParser(testObjFile, 'test');
const file = parser.parse();
// get first model in file
const model: ObjModel = file.models[0];
const model: ObjFileParser.ObjModel = file.models[0];
// gets object name
const name: string = model.name;
// gets first face in model
const face: Face = model.faces[0];
const face: ObjFileParser.Face = model.faces[0];
// gets first vertex in face
const faceVert: FaceVertex = face.vertices[0];
const faceVert: ObjFileParser.FaceVertex = face.vertices[0];
// gets vertex
const vertPoints: Vertex = model.vertices[faceVert.vertexIndex];
const vertPoints: ObjFileParser.Vertex = model.vertices[faceVert.vertexIndex];
// gets x value of vertex
const x = vertPoints.x;