mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
New type definitions for obj-file-parser package
This commit is contained in:
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// Type definitions for obj-file-parser 0.5
|
||||
// Project: https://github.com/WesUnwin/obj-file-parser#readme
|
||||
// Definitions by: Ben Coleman https://github.com/benc-uk
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
|
||||
export default class Parser {
|
||||
constructor(fileContents: any, defaultModelName?: any);
|
||||
parse(): ObjFile;
|
||||
}
|
||||
|
||||
export interface ObjFile {
|
||||
models: ObjModel[];
|
||||
materialLibraries: any[];
|
||||
}
|
||||
|
||||
export class ObjModel {
|
||||
name: string;
|
||||
vertices: {x: number, y: number, z: number}[];
|
||||
textureCoords: {u: number, v: number, w: number}[];
|
||||
vertexNormals: {x: number, y: number, z: number}[];
|
||||
faces: Face[];
|
||||
}
|
||||
|
||||
export class Face {
|
||||
material: any;
|
||||
group: string;
|
||||
smoothingGroup: number;
|
||||
vertices: FaceVertex[]
|
||||
}
|
||||
|
||||
export class FaceVertex {
|
||||
vertexIndex: number;
|
||||
textureCoordsIndex: number;
|
||||
vertexNormalIndex: number;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import ObjFileParser, { ObjModel, ObjFile } from 'obj-file-parser'
|
||||
|
||||
let testObjFile = `
|
||||
# cube.obj
|
||||
# Example object
|
||||
|
||||
g cube
|
||||
|
||||
v 0.0 0.0 0.0
|
||||
v 0.0 0.0 1.0
|
||||
v 0.0 1.0 0.0
|
||||
v 0.0 1.0 1.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 0.0 1.0
|
||||
v 1.0 1.0 0.0
|
||||
v 1.0 1.0 1.0
|
||||
|
||||
vn 0.0 0.0 1.0
|
||||
vn 0.0 0.0 -1.0
|
||||
vn 0.0 1.0 0.0
|
||||
vn 0.0 -1.0 0.0
|
||||
vn 1.0 0.0 0.0
|
||||
vn -1.0 0.0 0.0
|
||||
|
||||
g cube-faces
|
||||
|
||||
f 1//2 7//2 5//2
|
||||
f 1//2 3//2 7//2
|
||||
f 1//6 4//6 3//6
|
||||
f 1//6 2//6 4//6
|
||||
f 3//3 8//3 7//3
|
||||
f 3//3 4//3 8//3
|
||||
f 5//5 7//5 8//5
|
||||
f 5//5 8//5 6//5
|
||||
f 1//4 5//4 6//4
|
||||
f 1//4 6//4 2//4
|
||||
f 2//1 6//1 8//1
|
||||
f 2//1 8//1 4//1`
|
||||
|
||||
// Create parser and load test OBJ
|
||||
let parser = new ObjFileParser(testObjFile, 'test');
|
||||
let file = parser.parse();
|
||||
let model = file.models[0];
|
||||
|
||||
let name = model.name; // Prints "test"
|
||||
let face = model.faces[0] // Prints faces object
|
||||
|
||||
// gets { vertexIndex: 1, textureCoordsIndex: 0, vertexNormalIndex: 2 }
|
||||
let vert = face.vertices[0];
|
||||
// gets { x: 0, y: 0, z: 1 }
|
||||
let vertPoints = model.vertices[vert.vertexIndex];
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"obj-file-parser-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user