Replace tabs with spaces.
This commit is contained in:
parent
9f9851a2ec
commit
bc74ed9b04
@ -1,115 +1,115 @@
|
||||
OV.ExporterObj = class extends OV.ExporterBase
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
super ();
|
||||
}
|
||||
constructor ()
|
||||
{
|
||||
super ();
|
||||
}
|
||||
|
||||
CanExport (format, extension)
|
||||
{
|
||||
return format === OV.FileFormat.Text && extension === 'obj';
|
||||
}
|
||||
|
||||
ExportContent (model, format, files)
|
||||
{
|
||||
function WriteTexture (mtlWriter, keyword, texture, files)
|
||||
{
|
||||
if (texture === null || !texture.IsValid ()) {
|
||||
return;
|
||||
}
|
||||
let fileName = OV.GetFileName (texture.name);
|
||||
mtlWriter.WriteArrayLine ([keyword, fileName]);
|
||||
ExportContent (model, format, files)
|
||||
{
|
||||
function WriteTexture (mtlWriter, keyword, texture, files)
|
||||
{
|
||||
if (texture === null || !texture.IsValid ()) {
|
||||
return;
|
||||
}
|
||||
let fileName = OV.GetFileName (texture.name);
|
||||
mtlWriter.WriteArrayLine ([keyword, fileName]);
|
||||
|
||||
let fileIndex = files.findIndex (function (file) {
|
||||
return file.GetName () === fileName;
|
||||
});
|
||||
if (fileIndex === -1) {
|
||||
let textureFile = new OV.ExportedFile (fileName);
|
||||
textureFile.SetContent (texture.buffer);
|
||||
files.push (textureFile);
|
||||
}
|
||||
}
|
||||
let fileIndex = files.findIndex (function (file) {
|
||||
return file.GetName () === fileName;
|
||||
});
|
||||
if (fileIndex === -1) {
|
||||
let textureFile = new OV.ExportedFile (fileName);
|
||||
textureFile.SetContent (texture.buffer);
|
||||
files.push (textureFile);
|
||||
}
|
||||
}
|
||||
|
||||
let mtlFile = new OV.ExportedFile ('model.mtl');
|
||||
let objFile = new OV.ExportedFile ('model.obj');
|
||||
let mtlFile = new OV.ExportedFile ('model.mtl');
|
||||
let objFile = new OV.ExportedFile ('model.obj');
|
||||
|
||||
files.push (mtlFile);
|
||||
files.push (objFile);
|
||||
files.push (mtlFile);
|
||||
files.push (objFile);
|
||||
|
||||
let mtlWriter = new OV.TextWriter ();
|
||||
mtlWriter.WriteLine (this.GetHeaderText ());
|
||||
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
||||
let material = model.GetMaterial (materialIndex);
|
||||
mtlWriter.WriteArrayLine (['newmtl', this.GetExportedMaterialName (material.name)]);
|
||||
mtlWriter.WriteArrayLine (['Ka', material.ambient.r / 255.0, material.ambient.g / 255.0, material.ambient.b / 255.0]);
|
||||
mtlWriter.WriteArrayLine (['Kd', material.diffuse.r / 255.0, material.diffuse.g / 255.0, material.diffuse.b / 255.0]);
|
||||
mtlWriter.WriteArrayLine (['Ks', material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0]);
|
||||
mtlWriter.WriteArrayLine (['Ns', material.shininess * 100.0]);
|
||||
mtlWriter.WriteArrayLine (['d', material.opacity]);
|
||||
WriteTexture (mtlWriter, 'map_Kd', material.diffuseMap, files);
|
||||
WriteTexture (mtlWriter, 'map_Ks', material.specularMap, files);
|
||||
WriteTexture (mtlWriter, 'bump', material.bumpMap, files);
|
||||
}
|
||||
mtlFile.SetContent (mtlWriter.GetText ());
|
||||
let mtlWriter = new OV.TextWriter ();
|
||||
mtlWriter.WriteLine (this.GetHeaderText ());
|
||||
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
||||
let material = model.GetMaterial (materialIndex);
|
||||
mtlWriter.WriteArrayLine (['newmtl', this.GetExportedMaterialName (material.name)]);
|
||||
mtlWriter.WriteArrayLine (['Ka', material.ambient.r / 255.0, material.ambient.g / 255.0, material.ambient.b / 255.0]);
|
||||
mtlWriter.WriteArrayLine (['Kd', material.diffuse.r / 255.0, material.diffuse.g / 255.0, material.diffuse.b / 255.0]);
|
||||
mtlWriter.WriteArrayLine (['Ks', material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0]);
|
||||
mtlWriter.WriteArrayLine (['Ns', material.shininess * 100.0]);
|
||||
mtlWriter.WriteArrayLine (['d', material.opacity]);
|
||||
WriteTexture (mtlWriter, 'map_Kd', material.diffuseMap, files);
|
||||
WriteTexture (mtlWriter, 'map_Ks', material.specularMap, files);
|
||||
WriteTexture (mtlWriter, 'bump', material.bumpMap, files);
|
||||
}
|
||||
mtlFile.SetContent (mtlWriter.GetText ());
|
||||
|
||||
let objWriter = new OV.TextWriter ();
|
||||
objWriter.WriteLine (this.GetHeaderText ());
|
||||
objWriter.WriteArrayLine (['mtllib', mtlFile.GetName ()]);
|
||||
let vertexOffset = 0;
|
||||
let normalOffset = 0;
|
||||
let uvOffset = 0;
|
||||
let usedMaterialName = null;
|
||||
for (let meshIndex = 0; meshIndex < model.MeshCount (); meshIndex++) {
|
||||
let mesh = model.GetMesh (meshIndex);
|
||||
objWriter.WriteArrayLine (['g', this.GetExportedMeshName (mesh.GetName ())]);
|
||||
for (let vertexIndex = 0; vertexIndex < mesh.VertexCount (); vertexIndex++) {
|
||||
let vertex = mesh.GetVertex (vertexIndex);
|
||||
objWriter.WriteArrayLine (['v', vertex.x, vertex.y, vertex.z]);
|
||||
}
|
||||
for (let normalIndex = 0; normalIndex < mesh.NormalCount (); normalIndex++) {
|
||||
let normal = mesh.GetNormal (normalIndex);
|
||||
objWriter.WriteArrayLine (['vn', normal.x, normal.y, normal.z]);
|
||||
}
|
||||
for (let textureUVIndex = 0; textureUVIndex < mesh.TextureUVCount (); textureUVIndex++) {
|
||||
let uv = mesh.GetTextureUV (textureUVIndex);
|
||||
objWriter.WriteArrayLine (['vt', uv.x, uv.y]);
|
||||
}
|
||||
for (let triangleIndex = 0; triangleIndex < mesh.TriangleCount (); triangleIndex++) {
|
||||
let triangle = mesh.GetTriangle (triangleIndex);
|
||||
let v0 = triangle.v0 + vertexOffset + 1;
|
||||
let v1 = triangle.v1 + vertexOffset + 1;
|
||||
let v2 = triangle.v2 + vertexOffset + 1;
|
||||
let n0 = triangle.n0 + normalOffset + 1;
|
||||
let n1 = triangle.n1 + normalOffset + 1;
|
||||
let n2 = triangle.n2 + normalOffset + 1;
|
||||
if (triangle.mat !== null) {
|
||||
let material = model.GetMaterial (triangle.mat);
|
||||
let materialName = this.GetExportedMaterialName (material.name);
|
||||
if (materialName !== usedMaterialName) {
|
||||
objWriter.WriteArrayLine (['usemtl', materialName]);
|
||||
usedMaterialName = materialName;
|
||||
}
|
||||
}
|
||||
let u0 = '';
|
||||
let u1 = '';
|
||||
let u2 = '';
|
||||
if (triangle.HasTextureUVs ()) {
|
||||
u0 = triangle.u0 + uvOffset + 1;
|
||||
u1 = triangle.u1 + uvOffset + 1;
|
||||
u2 = triangle.u2 + uvOffset + 1;
|
||||
}
|
||||
objWriter.WriteArrayLine (['f', [v0, u0, n0].join ('/'), [v1, u1, n1].join ('/'), [v2, u2, n2].join ('/')]);
|
||||
}
|
||||
vertexOffset += mesh.VertexCount ();
|
||||
normalOffset += mesh.NormalCount ();
|
||||
uvOffset += mesh.TextureUVCount ();
|
||||
}
|
||||
let objWriter = new OV.TextWriter ();
|
||||
objWriter.WriteLine (this.GetHeaderText ());
|
||||
objWriter.WriteArrayLine (['mtllib', mtlFile.GetName ()]);
|
||||
let vertexOffset = 0;
|
||||
let normalOffset = 0;
|
||||
let uvOffset = 0;
|
||||
let usedMaterialName = null;
|
||||
for (let meshIndex = 0; meshIndex < model.MeshCount (); meshIndex++) {
|
||||
let mesh = model.GetMesh (meshIndex);
|
||||
objWriter.WriteArrayLine (['g', this.GetExportedMeshName (mesh.GetName ())]);
|
||||
for (let vertexIndex = 0; vertexIndex < mesh.VertexCount (); vertexIndex++) {
|
||||
let vertex = mesh.GetVertex (vertexIndex);
|
||||
objWriter.WriteArrayLine (['v', vertex.x, vertex.y, vertex.z]);
|
||||
}
|
||||
for (let normalIndex = 0; normalIndex < mesh.NormalCount (); normalIndex++) {
|
||||
let normal = mesh.GetNormal (normalIndex);
|
||||
objWriter.WriteArrayLine (['vn', normal.x, normal.y, normal.z]);
|
||||
}
|
||||
for (let textureUVIndex = 0; textureUVIndex < mesh.TextureUVCount (); textureUVIndex++) {
|
||||
let uv = mesh.GetTextureUV (textureUVIndex);
|
||||
objWriter.WriteArrayLine (['vt', uv.x, uv.y]);
|
||||
}
|
||||
for (let triangleIndex = 0; triangleIndex < mesh.TriangleCount (); triangleIndex++) {
|
||||
let triangle = mesh.GetTriangle (triangleIndex);
|
||||
let v0 = triangle.v0 + vertexOffset + 1;
|
||||
let v1 = triangle.v1 + vertexOffset + 1;
|
||||
let v2 = triangle.v2 + vertexOffset + 1;
|
||||
let n0 = triangle.n0 + normalOffset + 1;
|
||||
let n1 = triangle.n1 + normalOffset + 1;
|
||||
let n2 = triangle.n2 + normalOffset + 1;
|
||||
if (triangle.mat !== null) {
|
||||
let material = model.GetMaterial (triangle.mat);
|
||||
let materialName = this.GetExportedMaterialName (material.name);
|
||||
if (materialName !== usedMaterialName) {
|
||||
objWriter.WriteArrayLine (['usemtl', materialName]);
|
||||
usedMaterialName = materialName;
|
||||
}
|
||||
}
|
||||
let u0 = '';
|
||||
let u1 = '';
|
||||
let u2 = '';
|
||||
if (triangle.HasTextureUVs ()) {
|
||||
u0 = triangle.u0 + uvOffset + 1;
|
||||
u1 = triangle.u1 + uvOffset + 1;
|
||||
u2 = triangle.u2 + uvOffset + 1;
|
||||
}
|
||||
objWriter.WriteArrayLine (['f', [v0, u0, n0].join ('/'), [v1, u1, n1].join ('/'), [v2, u2, n2].join ('/')]);
|
||||
}
|
||||
vertexOffset += mesh.VertexCount ();
|
||||
normalOffset += mesh.NormalCount ();
|
||||
uvOffset += mesh.TextureUVCount ();
|
||||
}
|
||||
|
||||
objFile.SetContent (objWriter.GetText ());
|
||||
}
|
||||
objFile.SetContent (objWriter.GetText ());
|
||||
}
|
||||
|
||||
GetHeaderText ()
|
||||
{
|
||||
return '# exported by https://3dviewer.net';
|
||||
}
|
||||
GetHeaderText ()
|
||||
{
|
||||
return '# exported by https://3dviewer.net';
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,218 +1,218 @@
|
||||
OV.File = class
|
||||
{
|
||||
constructor (file, source)
|
||||
{
|
||||
this.source = source;
|
||||
if (source === OV.FileSource.Url) {
|
||||
this.fileUrl = file;
|
||||
this.fileObject = null;
|
||||
this.name = OV.GetFileName (file);
|
||||
this.extension = OV.GetFileExtension (file);
|
||||
} else if (source === OV.FileSource.File) {
|
||||
this.fileUrl = null;
|
||||
this.fileObject = file;
|
||||
this.name = OV.GetFileName (file.name);
|
||||
this.extension = OV.GetFileExtension (file.name);
|
||||
}
|
||||
this.content = null;
|
||||
}
|
||||
constructor (file, source)
|
||||
{
|
||||
this.source = source;
|
||||
if (source === OV.FileSource.Url) {
|
||||
this.fileUrl = file;
|
||||
this.fileObject = null;
|
||||
this.name = OV.GetFileName (file);
|
||||
this.extension = OV.GetFileExtension (file);
|
||||
} else if (source === OV.FileSource.File) {
|
||||
this.fileUrl = null;
|
||||
this.fileObject = file;
|
||||
this.name = OV.GetFileName (file.name);
|
||||
this.extension = OV.GetFileExtension (file.name);
|
||||
}
|
||||
this.content = null;
|
||||
}
|
||||
};
|
||||
|
||||
OV.FileList = class
|
||||
{
|
||||
constructor (importers)
|
||||
{
|
||||
this.files = [];
|
||||
this.importers = importers;
|
||||
}
|
||||
constructor (importers)
|
||||
{
|
||||
this.files = [];
|
||||
this.importers = importers;
|
||||
}
|
||||
|
||||
FillFromFileUrls (fileList)
|
||||
{
|
||||
this.Fill (fileList, OV.FileSource.Url);
|
||||
}
|
||||
FillFromFileUrls (fileList)
|
||||
{
|
||||
this.Fill (fileList, OV.FileSource.Url);
|
||||
}
|
||||
|
||||
FillFromFileObjects (fileList)
|
||||
{
|
||||
this.Fill (fileList, OV.FileSource.File);
|
||||
}
|
||||
FillFromFileObjects (fileList)
|
||||
{
|
||||
this.Fill (fileList, OV.FileSource.File);
|
||||
}
|
||||
|
||||
ExtendFromFileList (files)
|
||||
{
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let file = files[i];
|
||||
if (!this.ContainsFileByPath (file.name)) {
|
||||
this.files.push (file);
|
||||
}
|
||||
}
|
||||
}
|
||||
ExtendFromFileList (files)
|
||||
{
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let file = files[i];
|
||||
if (!this.ContainsFileByPath (file.name)) {
|
||||
this.files.push (file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GetFiles ()
|
||||
{
|
||||
return this.files;
|
||||
}
|
||||
GetFiles ()
|
||||
{
|
||||
return this.files;
|
||||
}
|
||||
|
||||
GetContent (onReady)
|
||||
{
|
||||
let obj = this;
|
||||
let taskRunner = new OV.TaskRunner ();
|
||||
taskRunner.Run (this.files.length, {
|
||||
runTask : function (index, complete) {
|
||||
obj.GetFileContent (obj.files[index], complete);
|
||||
},
|
||||
onReady : onReady
|
||||
});
|
||||
}
|
||||
GetContent (onReady)
|
||||
{
|
||||
let obj = this;
|
||||
let taskRunner = new OV.TaskRunner ();
|
||||
taskRunner.Run (this.files.length, {
|
||||
runTask : function (index, complete) {
|
||||
obj.GetFileContent (obj.files[index], complete);
|
||||
},
|
||||
onReady : onReady
|
||||
});
|
||||
}
|
||||
|
||||
ContainsFileByPath (filePath)
|
||||
{
|
||||
return this.FindFileByPath (filePath) !== null;
|
||||
}
|
||||
ContainsFileByPath (filePath)
|
||||
{
|
||||
return this.FindFileByPath (filePath) !== null;
|
||||
}
|
||||
|
||||
FindFileByPath (filePath)
|
||||
{
|
||||
let fileName = OV.GetFileName (filePath).toLowerCase ();
|
||||
for (let fileIndex = 0; fileIndex < this.files.length; fileIndex++) {
|
||||
let file = this.files[fileIndex];
|
||||
if (file.name.toLowerCase () === fileName) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
FindFileByPath (filePath)
|
||||
{
|
||||
let fileName = OV.GetFileName (filePath).toLowerCase ();
|
||||
for (let fileIndex = 0; fileIndex < this.files.length; fileIndex++) {
|
||||
let file = this.files[fileIndex];
|
||||
if (file.name.toLowerCase () === fileName) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
HasMainFile ()
|
||||
{
|
||||
return this.GetMainFile () !== null;
|
||||
}
|
||||
HasMainFile ()
|
||||
{
|
||||
return this.GetMainFile () !== null;
|
||||
}
|
||||
|
||||
GetMainFile ()
|
||||
{
|
||||
for (let fileIndex = 0; fileIndex < this.files.length; fileIndex++) {
|
||||
let file = this.files[fileIndex];
|
||||
let importer = this.FindImporter (file);
|
||||
if (importer !== null) {
|
||||
return {
|
||||
file : file,
|
||||
importer : importer
|
||||
};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
GetMainFile ()
|
||||
{
|
||||
for (let fileIndex = 0; fileIndex < this.files.length; fileIndex++) {
|
||||
let file = this.files[fileIndex];
|
||||
let importer = this.FindImporter (file);
|
||||
if (importer !== null) {
|
||||
return {
|
||||
file : file,
|
||||
importer : importer
|
||||
};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
IsOnlySource (source)
|
||||
{
|
||||
if (this.files.length === 0) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < this.files.length; i++) {
|
||||
let file = this.files[i];
|
||||
if (file.source !== source) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
IsOnlySource (source)
|
||||
{
|
||||
if (this.files.length === 0) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < this.files.length; i++) {
|
||||
let file = this.files[i];
|
||||
if (file.source !== source) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Fill (fileList, fileSource)
|
||||
{
|
||||
this.files = [];
|
||||
for (let fileIndex = 0; fileIndex < fileList.length; fileIndex++) {
|
||||
let fileObject = fileList[fileIndex];
|
||||
let file = new OV.File (fileObject, fileSource);
|
||||
this.AddFile (file);
|
||||
}
|
||||
}
|
||||
Fill (fileList, fileSource)
|
||||
{
|
||||
this.files = [];
|
||||
for (let fileIndex = 0; fileIndex < fileList.length; fileIndex++) {
|
||||
let fileObject = fileList[fileIndex];
|
||||
let file = new OV.File (fileObject, fileSource);
|
||||
this.AddFile (file);
|
||||
}
|
||||
}
|
||||
|
||||
AddFile (file)
|
||||
{
|
||||
this.files.push (file);
|
||||
}
|
||||
|
||||
GetFileContent (file, complete)
|
||||
{
|
||||
let callbacks = {
|
||||
success : function (content) {
|
||||
file.content = content;
|
||||
},
|
||||
error : function () {
|
||||
|
||||
},
|
||||
complete : function () {
|
||||
complete ();
|
||||
}
|
||||
};
|
||||
if (file.content !== null) {
|
||||
complete ();
|
||||
return;
|
||||
}
|
||||
let format = this.GetFileFormat (file);
|
||||
if (file.source === OV.FileSource.Url) {
|
||||
OV.RequestUrl (file.fileUrl, format, callbacks);
|
||||
} else if (file.source === OV.FileSource.File) {
|
||||
OV.ReadFile (file.fileObject, format, callbacks);
|
||||
}
|
||||
}
|
||||
|
||||
GetFileFormat (file)
|
||||
{
|
||||
for (let importerIndex = 0; importerIndex < this.importers.length; importerIndex++) {
|
||||
let importer = this.importers[importerIndex];
|
||||
let extension = file.extension.toLowerCase ();
|
||||
let knownFormats = importer.GetKnownFileFormats ();
|
||||
if (knownFormats[extension] !== undefined) {
|
||||
return knownFormats[extension];
|
||||
}
|
||||
}
|
||||
return OV.FileFormat.Binary;
|
||||
}
|
||||
AddFile (file)
|
||||
{
|
||||
this.files.push (file);
|
||||
}
|
||||
|
||||
GetFileContent (file, complete)
|
||||
{
|
||||
let callbacks = {
|
||||
success : function (content) {
|
||||
file.content = content;
|
||||
},
|
||||
error : function () {
|
||||
|
||||
},
|
||||
complete : function () {
|
||||
complete ();
|
||||
}
|
||||
};
|
||||
if (file.content !== null) {
|
||||
complete ();
|
||||
return;
|
||||
}
|
||||
let format = this.GetFileFormat (file);
|
||||
if (file.source === OV.FileSource.Url) {
|
||||
OV.RequestUrl (file.fileUrl, format, callbacks);
|
||||
} else if (file.source === OV.FileSource.File) {
|
||||
OV.ReadFile (file.fileObject, format, callbacks);
|
||||
}
|
||||
}
|
||||
|
||||
GetFileFormat (file)
|
||||
{
|
||||
for (let importerIndex = 0; importerIndex < this.importers.length; importerIndex++) {
|
||||
let importer = this.importers[importerIndex];
|
||||
let extension = file.extension.toLowerCase ();
|
||||
let knownFormats = importer.GetKnownFileFormats ();
|
||||
if (knownFormats[extension] !== undefined) {
|
||||
return knownFormats[extension];
|
||||
}
|
||||
}
|
||||
return OV.FileFormat.Binary;
|
||||
}
|
||||
|
||||
FindImporter (file)
|
||||
{
|
||||
for (let importerIndex = 0; importerIndex < this.importers.length; importerIndex++) {
|
||||
let importer = this.importers[importerIndex];
|
||||
if (importer.CanImportExtension (file.extension.toLowerCase ())) {
|
||||
return importer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
FindImporter (file)
|
||||
{
|
||||
for (let importerIndex = 0; importerIndex < this.importers.length; importerIndex++) {
|
||||
let importer = this.importers[importerIndex];
|
||||
if (importer.CanImportExtension (file.extension.toLowerCase ())) {
|
||||
return importer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
OV.ImportSettings = class
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
this.defaultColor = new OV.Color (200, 200, 200);
|
||||
}
|
||||
constructor ()
|
||||
{
|
||||
this.defaultColor = new OV.Color (200, 200, 200);
|
||||
}
|
||||
};
|
||||
|
||||
OV.ImportErrorCode =
|
||||
{
|
||||
NoImportableFile : 1,
|
||||
ImportFailed : 2,
|
||||
UnknownError : 3
|
||||
NoImportableFile : 1,
|
||||
ImportFailed : 2,
|
||||
UnknownError : 3
|
||||
};
|
||||
|
||||
OV.ImportError = class
|
||||
{
|
||||
constructor (code, message)
|
||||
{
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
constructor (code, message)
|
||||
{
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
};
|
||||
|
||||
OV.ImportResult = class
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
this.model = null;
|
||||
this.mainFile = null;
|
||||
this.upVector = null;
|
||||
this.usedFiles = null;
|
||||
this.missingFiles = null;
|
||||
}
|
||||
constructor ()
|
||||
{
|
||||
this.model = null;
|
||||
this.mainFile = null;
|
||||
this.upVector = null;
|
||||
this.usedFiles = null;
|
||||
this.missingFiles = null;
|
||||
}
|
||||
};
|
||||
|
||||
OV.ImportBuffers = class
|
||||
@ -257,149 +257,149 @@ OV.ImportBuffers = class
|
||||
|
||||
OV.Importer = class
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
this.importers = [
|
||||
new OV.ImporterObj (),
|
||||
new OV.ImporterStl (),
|
||||
new OV.ImporterOff (),
|
||||
new OV.ImporterPly (),
|
||||
new OV.Importer3ds (),
|
||||
new OV.ImporterGltf ()
|
||||
];
|
||||
this.fileList = new OV.FileList (this.importers);
|
||||
this.model = null;
|
||||
this.usedFiles = [];
|
||||
this.missingFiles = [];
|
||||
}
|
||||
|
||||
LoadFilesFromUrls (fileList, onReady)
|
||||
{
|
||||
this.LoadFiles (fileList, OV.FileSource.Url, onReady);
|
||||
}
|
||||
constructor ()
|
||||
{
|
||||
this.importers = [
|
||||
new OV.ImporterObj (),
|
||||
new OV.ImporterStl (),
|
||||
new OV.ImporterOff (),
|
||||
new OV.ImporterPly (),
|
||||
new OV.Importer3ds (),
|
||||
new OV.ImporterGltf ()
|
||||
];
|
||||
this.fileList = new OV.FileList (this.importers);
|
||||
this.model = null;
|
||||
this.usedFiles = [];
|
||||
this.missingFiles = [];
|
||||
}
|
||||
|
||||
LoadFilesFromUrls (fileList, onReady)
|
||||
{
|
||||
this.LoadFiles (fileList, OV.FileSource.Url, onReady);
|
||||
}
|
||||
|
||||
LoadFilesFromFileObjects (fileList, onReady)
|
||||
{
|
||||
this.LoadFiles (fileList, OV.FileSource.File, onReady);
|
||||
}
|
||||
LoadFilesFromFileObjects (fileList, onReady)
|
||||
{
|
||||
this.LoadFiles (fileList, OV.FileSource.File, onReady);
|
||||
}
|
||||
|
||||
Import (settings, callbacks)
|
||||
{
|
||||
let mainFile = this.fileList.GetMainFile ();
|
||||
if (mainFile === null || mainFile.file === null || mainFile.file.content === null) {
|
||||
callbacks.onError (new OV.ImportError (OV.ImportErrorCode.NoImportableFile, null));
|
||||
return;
|
||||
}
|
||||
Import (settings, callbacks)
|
||||
{
|
||||
let mainFile = this.fileList.GetMainFile ();
|
||||
if (mainFile === null || mainFile.file === null || mainFile.file.content === null) {
|
||||
callbacks.onError (new OV.ImportError (OV.ImportErrorCode.NoImportableFile, null));
|
||||
return;
|
||||
}
|
||||
|
||||
this.RevokeModelUrls ();
|
||||
this.model = null;
|
||||
this.usedFiles = [];
|
||||
this.missingFiles = [];
|
||||
this.usedFiles.push (mainFile.file.name);
|
||||
this.RevokeModelUrls ();
|
||||
this.model = null;
|
||||
this.usedFiles = [];
|
||||
this.missingFiles = [];
|
||||
this.usedFiles.push (mainFile.file.name);
|
||||
|
||||
let obj = this;
|
||||
let importer = mainFile.importer;
|
||||
let buffers = new OV.ImportBuffers (function (fileName) {
|
||||
let fileBuffer = null;
|
||||
let file = obj.fileList.FindFileByPath (fileName);
|
||||
if (file === null || file.content === null) {
|
||||
obj.missingFiles.push (fileName);
|
||||
fileBuffer = null;
|
||||
} else {
|
||||
fileBuffer = file.content;
|
||||
obj.usedFiles.push (fileName);
|
||||
}
|
||||
return fileBuffer;
|
||||
});
|
||||
let obj = this;
|
||||
let importer = mainFile.importer;
|
||||
let buffers = new OV.ImportBuffers (function (fileName) {
|
||||
let fileBuffer = null;
|
||||
let file = obj.fileList.FindFileByPath (fileName);
|
||||
if (file === null || file.content === null) {
|
||||
obj.missingFiles.push (fileName);
|
||||
fileBuffer = null;
|
||||
} else {
|
||||
fileBuffer = file.content;
|
||||
obj.usedFiles.push (fileName);
|
||||
}
|
||||
return fileBuffer;
|
||||
});
|
||||
|
||||
importer.Import (mainFile.file.content, mainFile.file.extension, {
|
||||
getDefaultMaterial : function () {
|
||||
let material = new OV.Material ();
|
||||
material.diffuse = settings.defaultColor;
|
||||
return material;
|
||||
},
|
||||
getFileBuffer : function (filePath) {
|
||||
return buffers.GetFileBuffer (filePath);
|
||||
},
|
||||
getTextureBuffer : function (filePath) {
|
||||
return buffers.GetTextureBuffer (filePath);
|
||||
},
|
||||
onSuccess : function () {
|
||||
obj.model = importer.GetModel ();
|
||||
obj.model.SetName (mainFile.file.name);
|
||||
|
||||
let result = new OV.ImportResult ();
|
||||
result.mainFile = mainFile.file.name;
|
||||
result.model = obj.model;
|
||||
result.usedFiles = obj.usedFiles;
|
||||
result.missingFiles = obj.missingFiles;
|
||||
result.upVector = importer.GetUpDirection ();
|
||||
callbacks.onSuccess (result);
|
||||
},
|
||||
onError : function () {
|
||||
let message = importer.GetMessage ();
|
||||
callbacks.onError (new OV.ImportError (OV.ImportErrorCode.ImportFailed, message));
|
||||
}
|
||||
});
|
||||
}
|
||||
importer.Import (mainFile.file.content, mainFile.file.extension, {
|
||||
getDefaultMaterial : function () {
|
||||
let material = new OV.Material ();
|
||||
material.diffuse = settings.defaultColor;
|
||||
return material;
|
||||
},
|
||||
getFileBuffer : function (filePath) {
|
||||
return buffers.GetFileBuffer (filePath);
|
||||
},
|
||||
getTextureBuffer : function (filePath) {
|
||||
return buffers.GetTextureBuffer (filePath);
|
||||
},
|
||||
onSuccess : function () {
|
||||
obj.model = importer.GetModel ();
|
||||
obj.model.SetName (mainFile.file.name);
|
||||
|
||||
let result = new OV.ImportResult ();
|
||||
result.mainFile = mainFile.file.name;
|
||||
result.model = obj.model;
|
||||
result.usedFiles = obj.usedFiles;
|
||||
result.missingFiles = obj.missingFiles;
|
||||
result.upVector = importer.GetUpDirection ();
|
||||
callbacks.onSuccess (result);
|
||||
},
|
||||
onError : function () {
|
||||
let message = importer.GetMessage ();
|
||||
callbacks.onError (new OV.ImportError (OV.ImportErrorCode.ImportFailed, message));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
LoadFiles (fileList, fileSource, onReady)
|
||||
{
|
||||
let newFileList = new OV.FileList (this.importers);
|
||||
if (fileSource === OV.FileSource.Url) {
|
||||
newFileList.FillFromFileUrls (fileList);
|
||||
} else if (fileSource === OV.FileSource.File) {
|
||||
newFileList.FillFromFileObjects (fileList);
|
||||
}
|
||||
let reset = false;
|
||||
if (newFileList.HasMainFile ()) {
|
||||
reset = true;
|
||||
} else {
|
||||
let foundMissingFile = false;
|
||||
for (let i = 0; i < this.missingFiles.length; i++) {
|
||||
let missingFile = this.missingFiles[i];
|
||||
if (newFileList.ContainsFileByPath (missingFile)) {
|
||||
foundMissingFile = true;
|
||||
}
|
||||
}
|
||||
if (!foundMissingFile) {
|
||||
reset = true;
|
||||
} else {
|
||||
let newFiles = newFileList.GetFiles ();
|
||||
this.fileList.ExtendFromFileList (newFiles);
|
||||
reset = false;
|
||||
}
|
||||
}
|
||||
if (reset) {
|
||||
this.fileList = newFileList;
|
||||
}
|
||||
this.fileList.GetContent (function () {
|
||||
onReady ();
|
||||
});
|
||||
}
|
||||
LoadFiles (fileList, fileSource, onReady)
|
||||
{
|
||||
let newFileList = new OV.FileList (this.importers);
|
||||
if (fileSource === OV.FileSource.Url) {
|
||||
newFileList.FillFromFileUrls (fileList);
|
||||
} else if (fileSource === OV.FileSource.File) {
|
||||
newFileList.FillFromFileObjects (fileList);
|
||||
}
|
||||
let reset = false;
|
||||
if (newFileList.HasMainFile ()) {
|
||||
reset = true;
|
||||
} else {
|
||||
let foundMissingFile = false;
|
||||
for (let i = 0; i < this.missingFiles.length; i++) {
|
||||
let missingFile = this.missingFiles[i];
|
||||
if (newFileList.ContainsFileByPath (missingFile)) {
|
||||
foundMissingFile = true;
|
||||
}
|
||||
}
|
||||
if (!foundMissingFile) {
|
||||
reset = true;
|
||||
} else {
|
||||
let newFiles = newFileList.GetFiles ();
|
||||
this.fileList.ExtendFromFileList (newFiles);
|
||||
reset = false;
|
||||
}
|
||||
}
|
||||
if (reset) {
|
||||
this.fileList = newFileList;
|
||||
}
|
||||
this.fileList.GetContent (function () {
|
||||
onReady ();
|
||||
});
|
||||
}
|
||||
|
||||
GetFileList ()
|
||||
{
|
||||
return this.fileList;
|
||||
}
|
||||
GetFileList ()
|
||||
{
|
||||
return this.fileList;
|
||||
}
|
||||
|
||||
IsOnlyFileSource (source)
|
||||
{
|
||||
return this.fileList.IsOnlySource (source);
|
||||
}
|
||||
IsOnlyFileSource (source)
|
||||
{
|
||||
return this.fileList.IsOnlySource (source);
|
||||
}
|
||||
|
||||
RevokeModelUrls ()
|
||||
{
|
||||
if (this.model === null) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < this.model.MaterialCount (); i++) {
|
||||
let material = this.model.GetMaterial (i);
|
||||
material.EnumerateTextureMaps (function (texture) {
|
||||
if (texture.url !== null) {
|
||||
OV.RevokeObjectUrl (texture.url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
RevokeModelUrls ()
|
||||
{
|
||||
if (this.model === null) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < this.model.MaterialCount (); i++) {
|
||||
let material = this.model.GetMaterial (i);
|
||||
material.EnumerateTextureMaps (function (texture) {
|
||||
if (texture.url !== null) {
|
||||
OV.RevokeObjectUrl (texture.url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -8,9 +8,9 @@ OV.ImporterBase = class
|
||||
this.error = null;
|
||||
this.message = null;
|
||||
}
|
||||
|
||||
Import (content, extension, callbacks)
|
||||
{
|
||||
|
||||
Import (content, extension, callbacks)
|
||||
{
|
||||
this.extension = extension;
|
||||
this.callbacks = callbacks;
|
||||
this.model = new OV.Model ();
|
||||
@ -18,11 +18,11 @@ OV.ImporterBase = class
|
||||
this.message = null;
|
||||
|
||||
let obj = this;
|
||||
obj.ResetState ();
|
||||
obj.ResetState ();
|
||||
obj.ImportContent (content, function () {
|
||||
obj.CreateResult (callbacks);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
CreateResult (callbacks)
|
||||
{
|
||||
@ -46,15 +46,15 @@ OV.ImporterBase = class
|
||||
|
||||
}
|
||||
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
GetUpDirection ()
|
||||
{
|
||||
|
||||
@ -1,40 +1,40 @@
|
||||
OV.GltfComponentType =
|
||||
{
|
||||
BYTE : 5120,
|
||||
UNSIGNED_BYTE : 5121,
|
||||
SHORT : 5122,
|
||||
UNSIGNED_SHORT : 5123,
|
||||
UNSIGNED_INT : 5125,
|
||||
FLOAT : 5126
|
||||
BYTE : 5120,
|
||||
UNSIGNED_BYTE : 5121,
|
||||
SHORT : 5122,
|
||||
UNSIGNED_SHORT : 5123,
|
||||
UNSIGNED_INT : 5125,
|
||||
FLOAT : 5126
|
||||
};
|
||||
|
||||
OV.GltfDataType =
|
||||
{
|
||||
SCALAR : 0,
|
||||
VEC2 : 1,
|
||||
VEC3 : 2,
|
||||
VEC4 : 3,
|
||||
MAT2 : 4,
|
||||
MAT3 : 5,
|
||||
SCALAR : 0,
|
||||
VEC2 : 1,
|
||||
VEC3 : 2,
|
||||
VEC4 : 3,
|
||||
MAT2 : 4,
|
||||
MAT3 : 5,
|
||||
MAT4 : 6
|
||||
};
|
||||
|
||||
OV.GltfRenderMode =
|
||||
{
|
||||
POINTS : 0,
|
||||
LINES : 1,
|
||||
LINE_LOOP : 2,
|
||||
LINE_STRIP : 3,
|
||||
TRIANGLES : 4,
|
||||
TRIANGLE_STRIP : 5,
|
||||
POINTS : 0,
|
||||
LINES : 1,
|
||||
LINE_LOOP : 2,
|
||||
LINE_STRIP : 3,
|
||||
TRIANGLES : 4,
|
||||
TRIANGLE_STRIP : 5,
|
||||
TRIANGLE_FAN : 6
|
||||
};
|
||||
|
||||
OV.GltfConstants =
|
||||
{
|
||||
GLTF_STRING : 0x46546C67,
|
||||
JSON_CHUNK_TYPE : 0x4E4F534A,
|
||||
BINARY_CHUNK_TYPE : 0x004E4942
|
||||
GLTF_STRING : 0x46546C67,
|
||||
JSON_CHUNK_TYPE : 0x4E4F534A,
|
||||
BINARY_CHUNK_TYPE : 0x004E4942
|
||||
};
|
||||
|
||||
OV.GltfNodeTree = class
|
||||
@ -345,50 +345,50 @@ OV.GltfExtensions = class
|
||||
|
||||
OV.ImporterGltf = class extends OV.ImporterBase
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
super ();
|
||||
constructor ()
|
||||
{
|
||||
super ();
|
||||
|
||||
this.bufferContents = null;
|
||||
this.gltfExtensions = null;
|
||||
this.imageIndexToTextureParams = null;
|
||||
}
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
}
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
this.bufferContents = [];
|
||||
this.gltfExtensions = new OV.GltfExtensions ();
|
||||
this.imageIndexToTextureParams = {};
|
||||
}
|
||||
}
|
||||
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'gltf' || extension === 'glb';
|
||||
}
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'gltf' || extension === 'glb';
|
||||
}
|
||||
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {
|
||||
'gltf' : OV.FileFormat.Text,
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {
|
||||
'gltf' : OV.FileFormat.Text,
|
||||
'glb' : OV.FileFormat.Binary,
|
||||
'bin' : OV.FileFormat.Binary
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
GetUpDirection ()
|
||||
{
|
||||
return OV.Direction.Y;
|
||||
}
|
||||
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
if (this.extension === 'gltf') {
|
||||
this.ProcessGltf (fileContent);
|
||||
} else if (this.extension === 'glb') {
|
||||
this.ProcessBinaryGltf (fileContent);
|
||||
}
|
||||
onFinish ();
|
||||
}
|
||||
}
|
||||
|
||||
ProcessGltf (fileContent)
|
||||
{
|
||||
|
||||
@ -1,388 +1,388 @@
|
||||
OV.ImporterObj = class extends OV.ImporterBase
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
super ();
|
||||
constructor ()
|
||||
{
|
||||
super ();
|
||||
|
||||
this.globalVertices = null;
|
||||
this.globalNormals = null;
|
||||
this.globalUvs = null;
|
||||
|
||||
this.currentMesh = null;
|
||||
this.currentMeshData = null;
|
||||
this.currentMaterial = null;
|
||||
this.currentMaterialIndex = null;
|
||||
|
||||
this.meshNameToMeshData = null;
|
||||
this.materialNameToIndex = null;
|
||||
}
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
this.globalVertices = [];
|
||||
this.globalNormals = [];
|
||||
this.globalUvs = [];
|
||||
this.globalVertices = null;
|
||||
this.globalNormals = null;
|
||||
this.globalUvs = null;
|
||||
|
||||
this.currentMesh = null;
|
||||
this.currentMeshData = null;
|
||||
this.currentMaterial = null;
|
||||
this.currentMaterialIndex = null;
|
||||
|
||||
this.meshNameToMeshData = null;
|
||||
this.materialNameToIndex = null;
|
||||
}
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
this.globalVertices = [];
|
||||
this.globalNormals = [];
|
||||
this.globalUvs = [];
|
||||
|
||||
this.currentMesh = null;
|
||||
this.currentMeshData = null;
|
||||
this.currentMaterial = null;
|
||||
this.currentMaterialIndex = null;
|
||||
this.currentMesh = null;
|
||||
this.currentMeshData = null;
|
||||
this.currentMaterial = null;
|
||||
this.currentMaterialIndex = null;
|
||||
|
||||
this.meshNameToMeshData = {};
|
||||
this.materialNameToIndex = {};
|
||||
}
|
||||
this.meshNameToMeshData = {};
|
||||
this.materialNameToIndex = {};
|
||||
}
|
||||
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'obj';
|
||||
}
|
||||
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {
|
||||
'obj' : OV.FileFormat.Text,
|
||||
'mtl' : OV.FileFormat.Text
|
||||
};
|
||||
}
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'obj';
|
||||
}
|
||||
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {
|
||||
'obj' : OV.FileFormat.Text,
|
||||
'mtl' : OV.FileFormat.Text
|
||||
};
|
||||
}
|
||||
|
||||
GetUpDirection ()
|
||||
GetUpDirection ()
|
||||
{
|
||||
return OV.Direction.Y;
|
||||
}
|
||||
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
let obj = this;
|
||||
OV.ReadLines (fileContent, function (line) {
|
||||
if (!obj.IsError ()) {
|
||||
obj.ProcessLine (line);
|
||||
}
|
||||
});
|
||||
onFinish ();
|
||||
}
|
||||
|
||||
ProcessLine (line)
|
||||
{
|
||||
if (line[0] === '#') {
|
||||
return;
|
||||
}
|
||||
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
let obj = this;
|
||||
OV.ReadLines (fileContent, function (line) {
|
||||
if (!obj.IsError ()) {
|
||||
obj.ProcessLine (line);
|
||||
}
|
||||
});
|
||||
onFinish ();
|
||||
}
|
||||
|
||||
ProcessLine (line)
|
||||
{
|
||||
if (line[0] === '#') {
|
||||
return;
|
||||
}
|
||||
|
||||
let parameters = OV.ParametersFromLine (line, '#');
|
||||
if (parameters.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let keyword = parameters[0].toLowerCase ();
|
||||
parameters.shift ();
|
||||
let parameters = OV.ParametersFromLine (line, '#');
|
||||
if (parameters.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let keyword = parameters[0].toLowerCase ();
|
||||
parameters.shift ();
|
||||
|
||||
if (this.ProcessMeshParameter (keyword, parameters, line)) {
|
||||
return;
|
||||
}
|
||||
if (this.ProcessMeshParameter (keyword, parameters, line)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.ProcessMaterialParameter (keyword, parameters, line)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AddNewMesh (name)
|
||||
{
|
||||
let meshData = this.meshNameToMeshData[name];
|
||||
if (meshData === undefined) {
|
||||
let mesh = new OV.Mesh ();
|
||||
if (name !== null) {
|
||||
mesh.SetName (name);
|
||||
}
|
||||
this.model.AddMesh (mesh);
|
||||
meshData = {
|
||||
mesh : mesh,
|
||||
data : {
|
||||
globalToCurrentVertices : {},
|
||||
globalToCurrentNormals : {},
|
||||
globalToCurrentUvs : {}
|
||||
}
|
||||
};
|
||||
this.meshNameToMeshData[name] = meshData;
|
||||
}
|
||||
this.currentMesh = meshData.mesh;
|
||||
this.currentMeshData = meshData.data;
|
||||
}
|
||||
if (this.ProcessMaterialParameter (keyword, parameters, line)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AddNewMesh (name)
|
||||
{
|
||||
let meshData = this.meshNameToMeshData[name];
|
||||
if (meshData === undefined) {
|
||||
let mesh = new OV.Mesh ();
|
||||
if (name !== null) {
|
||||
mesh.SetName (name);
|
||||
}
|
||||
this.model.AddMesh (mesh);
|
||||
meshData = {
|
||||
mesh : mesh,
|
||||
data : {
|
||||
globalToCurrentVertices : {},
|
||||
globalToCurrentNormals : {},
|
||||
globalToCurrentUvs : {}
|
||||
}
|
||||
};
|
||||
this.meshNameToMeshData[name] = meshData;
|
||||
}
|
||||
this.currentMesh = meshData.mesh;
|
||||
this.currentMeshData = meshData.data;
|
||||
}
|
||||
|
||||
ProcessMeshParameter (keyword, parameters, line)
|
||||
{
|
||||
if (keyword === 'g' || keyword === 'o') {
|
||||
if (parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
let name = OV.NameFromLine (line, keyword.length, '#');
|
||||
this.AddNewMesh (name);
|
||||
return true;
|
||||
} else if (keyword === 'v') {
|
||||
if (parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.globalVertices.push (new OV.Coord3D (
|
||||
parseFloat (parameters[0]),
|
||||
parseFloat (parameters[1]),
|
||||
parseFloat (parameters[2])
|
||||
));
|
||||
return true;
|
||||
} else if (keyword === 'vn') {
|
||||
if (parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.globalNormals.push (new OV.Coord3D (
|
||||
parseFloat (parameters[0]),
|
||||
parseFloat (parameters[1]),
|
||||
parseFloat (parameters[2])
|
||||
));
|
||||
return true;
|
||||
} else if (keyword === 'vt') {
|
||||
if (parameters.length < 2) {
|
||||
return true;
|
||||
}
|
||||
this.globalUvs.push (new OV.Coord2D (
|
||||
parseFloat (parameters[0]),
|
||||
parseFloat (parameters[1])
|
||||
));
|
||||
return true;
|
||||
} else if (keyword === 'f') {
|
||||
if (parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.ProcessFace (parameters);
|
||||
return true;
|
||||
}
|
||||
ProcessMeshParameter (keyword, parameters, line)
|
||||
{
|
||||
if (keyword === 'g' || keyword === 'o') {
|
||||
if (parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
let name = OV.NameFromLine (line, keyword.length, '#');
|
||||
this.AddNewMesh (name);
|
||||
return true;
|
||||
} else if (keyword === 'v') {
|
||||
if (parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.globalVertices.push (new OV.Coord3D (
|
||||
parseFloat (parameters[0]),
|
||||
parseFloat (parameters[1]),
|
||||
parseFloat (parameters[2])
|
||||
));
|
||||
return true;
|
||||
} else if (keyword === 'vn') {
|
||||
if (parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.globalNormals.push (new OV.Coord3D (
|
||||
parseFloat (parameters[0]),
|
||||
parseFloat (parameters[1]),
|
||||
parseFloat (parameters[2])
|
||||
));
|
||||
return true;
|
||||
} else if (keyword === 'vt') {
|
||||
if (parameters.length < 2) {
|
||||
return true;
|
||||
}
|
||||
this.globalUvs.push (new OV.Coord2D (
|
||||
parseFloat (parameters[0]),
|
||||
parseFloat (parameters[1])
|
||||
));
|
||||
return true;
|
||||
} else if (keyword === 'f') {
|
||||
if (parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.ProcessFace (parameters);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ProcessMaterialParameter (keyword, parameters, line)
|
||||
{
|
||||
function CreateColor (parameters)
|
||||
{
|
||||
return new OV.Color (
|
||||
parseInt (parseFloat (parameters[0] * 255.0), 10),
|
||||
parseInt (parseFloat (parameters[1] * 255.0), 10),
|
||||
parseInt (parseFloat (parameters[2] * 255.0), 10)
|
||||
);
|
||||
}
|
||||
ProcessMaterialParameter (keyword, parameters, line)
|
||||
{
|
||||
function CreateColor (parameters)
|
||||
{
|
||||
return new OV.Color (
|
||||
parseInt (parseFloat (parameters[0] * 255.0), 10),
|
||||
parseInt (parseFloat (parameters[1] * 255.0), 10),
|
||||
parseInt (parseFloat (parameters[2] * 255.0), 10)
|
||||
);
|
||||
}
|
||||
|
||||
function CreateTexture (keyword, line, callbacks)
|
||||
{
|
||||
let texture = new OV.TextureMap ();
|
||||
let textureName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let textureBuffer = callbacks.getTextureBuffer (textureName);
|
||||
texture.name = textureName;
|
||||
if (textureBuffer !== null) {
|
||||
texture.url = textureBuffer.url;
|
||||
texture.buffer = textureBuffer.buffer;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
function CreateTexture (keyword, line, callbacks)
|
||||
{
|
||||
let texture = new OV.TextureMap ();
|
||||
let textureName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let textureBuffer = callbacks.getTextureBuffer (textureName);
|
||||
texture.name = textureName;
|
||||
if (textureBuffer !== null) {
|
||||
texture.url = textureBuffer.url;
|
||||
texture.buffer = textureBuffer.buffer;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
let obj = this;
|
||||
if (keyword === 'newmtl') {
|
||||
if (parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let material = new OV.Material ();
|
||||
let materialName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let materialIndex = this.model.AddMaterial (material);
|
||||
material.name = materialName;
|
||||
this.currentMaterial = material;
|
||||
this.materialNameToIndex[materialName] = materialIndex;
|
||||
return true;
|
||||
} else if (keyword === 'usemtl') {
|
||||
if (parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let materialName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let materialIndex = this.materialNameToIndex[materialName];
|
||||
if (materialIndex !== undefined) {
|
||||
this.currentMaterialIndex = materialIndex;
|
||||
}
|
||||
return true;
|
||||
} else if (keyword === 'mtllib') {
|
||||
if (parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
let fileName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let fileBuffer = this.callbacks.getFileBuffer (fileName);
|
||||
if (fileBuffer !== null) {
|
||||
OV.ReadLines (fileBuffer, function (line) {
|
||||
if (!obj.IsError ()) {
|
||||
obj.ProcessLine (line);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
} else if (keyword === 'map_kd') {
|
||||
if (this.currentMaterial === null || parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.diffuseMap = CreateTexture (keyword, line, this.callbacks);
|
||||
return true;
|
||||
} else if (keyword === 'map_ks') {
|
||||
if (this.currentMaterial === null || parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.specularMap = CreateTexture (keyword, line, this.callbacks);
|
||||
return true;
|
||||
} else if (keyword === 'map_bump' || keyword === 'bump') {
|
||||
if (this.currentMaterial === null || parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.bumpMap = CreateTexture (keyword, line, this.callbacks);
|
||||
return true;
|
||||
} else if (keyword === 'ka') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.ambient = CreateColor (parameters);
|
||||
return true;
|
||||
} else if (keyword === 'kd') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.diffuse = CreateColor (parameters);
|
||||
return true;
|
||||
} else if (keyword === 'ks') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.specular = CreateColor (parameters);
|
||||
return true;
|
||||
} else if (keyword === 'ns') {
|
||||
if (this.currentMaterial === null || parameters.length < 1) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.shininess = parseFloat (parameters[0]) / 100.0;
|
||||
return true;
|
||||
} else if (keyword === 'tr') {
|
||||
if (this.currentMaterial === null || parameters.length < 1) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.opacity = 1.0 - parseFloat (parameters[0]);
|
||||
this.currentMaterial.transparent = OV.IsLower (this.currentMaterial.opacity, 1.0);
|
||||
return true;
|
||||
} else if (keyword === 'd') {
|
||||
if (this.currentMaterial === null || parameters.length < 1) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.opacity = parseFloat (parameters[0]);
|
||||
this.currentMaterial.transparent = OV.IsLower (this.currentMaterial.opacity, 1.0);
|
||||
return true;
|
||||
}
|
||||
let obj = this;
|
||||
if (keyword === 'newmtl') {
|
||||
if (parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let material = new OV.Material ();
|
||||
let materialName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let materialIndex = this.model.AddMaterial (material);
|
||||
material.name = materialName;
|
||||
this.currentMaterial = material;
|
||||
this.materialNameToIndex[materialName] = materialIndex;
|
||||
return true;
|
||||
} else if (keyword === 'usemtl') {
|
||||
if (parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let materialName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let materialIndex = this.materialNameToIndex[materialName];
|
||||
if (materialIndex !== undefined) {
|
||||
this.currentMaterialIndex = materialIndex;
|
||||
}
|
||||
return true;
|
||||
} else if (keyword === 'mtllib') {
|
||||
if (parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
let fileName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let fileBuffer = this.callbacks.getFileBuffer (fileName);
|
||||
if (fileBuffer !== null) {
|
||||
OV.ReadLines (fileBuffer, function (line) {
|
||||
if (!obj.IsError ()) {
|
||||
obj.ProcessLine (line);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
} else if (keyword === 'map_kd') {
|
||||
if (this.currentMaterial === null || parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.diffuseMap = CreateTexture (keyword, line, this.callbacks);
|
||||
return true;
|
||||
} else if (keyword === 'map_ks') {
|
||||
if (this.currentMaterial === null || parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.specularMap = CreateTexture (keyword, line, this.callbacks);
|
||||
return true;
|
||||
} else if (keyword === 'map_bump' || keyword === 'bump') {
|
||||
if (this.currentMaterial === null || parameters.length === 0) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.bumpMap = CreateTexture (keyword, line, this.callbacks);
|
||||
return true;
|
||||
} else if (keyword === 'ka') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.ambient = CreateColor (parameters);
|
||||
return true;
|
||||
} else if (keyword === 'kd') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.diffuse = CreateColor (parameters);
|
||||
return true;
|
||||
} else if (keyword === 'ks') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.specular = CreateColor (parameters);
|
||||
return true;
|
||||
} else if (keyword === 'ns') {
|
||||
if (this.currentMaterial === null || parameters.length < 1) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.shininess = parseFloat (parameters[0]) / 100.0;
|
||||
return true;
|
||||
} else if (keyword === 'tr') {
|
||||
if (this.currentMaterial === null || parameters.length < 1) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.opacity = 1.0 - parseFloat (parameters[0]);
|
||||
this.currentMaterial.transparent = OV.IsLower (this.currentMaterial.opacity, 1.0);
|
||||
return true;
|
||||
} else if (keyword === 'd') {
|
||||
if (this.currentMaterial === null || parameters.length < 1) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.opacity = parseFloat (parameters[0]);
|
||||
this.currentMaterial.transparent = OV.IsLower (this.currentMaterial.opacity, 1.0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ProcessFace (parameters)
|
||||
{
|
||||
function GetRelativeIndex (index, count)
|
||||
{
|
||||
if (index > 0) {
|
||||
return index - 1;
|
||||
} else {
|
||||
return count + index;
|
||||
}
|
||||
}
|
||||
|
||||
function GetLocalIndex (globalValueArray, globalToCurrentIndices, globalIndex, valueAdderFunc)
|
||||
{
|
||||
if (isNaN (globalIndex) || globalIndex < 0 || globalIndex >= globalValueArray.length) {
|
||||
return null;
|
||||
}
|
||||
let result = globalToCurrentIndices[globalIndex];
|
||||
if (result === undefined) {
|
||||
let globalValue = globalValueArray[globalIndex];
|
||||
if (globalValue === undefined) {
|
||||
return null;
|
||||
}
|
||||
result = valueAdderFunc (globalValue);
|
||||
globalToCurrentIndices[globalIndex] = result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function GetLocalVertexIndex (obj, mesh, globalIndex)
|
||||
{
|
||||
return GetLocalIndex (obj.globalVertices, obj.currentMeshData.globalToCurrentVertices, globalIndex, function (val) {
|
||||
return mesh.AddVertex (new OV.Coord3D (val.x, val.y, val.z));
|
||||
});
|
||||
}
|
||||
|
||||
function GetLocalNormalIndex (obj, mesh, globalIndex)
|
||||
{
|
||||
return GetLocalIndex (obj.globalNormals, obj.currentMeshData.globalToCurrentNormals, globalIndex, function (val) {
|
||||
return mesh.AddNormal (new OV.Coord3D (val.x, val.y, val.z));
|
||||
});
|
||||
}
|
||||
|
||||
function GetLocalUVIndex (obj, mesh, globalIndex)
|
||||
{
|
||||
return GetLocalIndex (obj.globalUvs, obj.currentMeshData.globalToCurrentUvs, globalIndex, function (val) {
|
||||
return mesh.AddTextureUV (new OV.Coord2D (val.x, val.y));
|
||||
});
|
||||
}
|
||||
|
||||
let vertices = [];
|
||||
let normals = [];
|
||||
let uvs = [];
|
||||
|
||||
for (let i = 0; i < parameters.length; i++) {
|
||||
let vertexParams = parameters[i].split ('/');
|
||||
vertices.push (GetRelativeIndex (parseInt (vertexParams[0], 10), this.globalVertices.length));
|
||||
if (vertexParams.length > 1 && vertexParams[1].length > 0) {
|
||||
uvs.push (GetRelativeIndex (parseInt (vertexParams[1], 10), this.globalUvs.length));
|
||||
}
|
||||
if (vertexParams.length > 2 && vertexParams[2].length > 0) {
|
||||
normals.push (GetRelativeIndex (parseInt (vertexParams[2], 10), this.globalNormals.length));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.currentMesh === null) {
|
||||
this.AddNewMesh ('');
|
||||
}
|
||||
|
||||
for (let i = 0; i < vertices.length - 2; i++) {
|
||||
let v0 = GetLocalVertexIndex (this, this.currentMesh, vertices[0]);
|
||||
let v1 = GetLocalVertexIndex (this, this.currentMesh, vertices[i + 1]);
|
||||
let v2 = GetLocalVertexIndex (this, this.currentMesh, vertices[i + 2]);
|
||||
if (v0 === null || v1 === null || v2 === null) {
|
||||
this.SetError ();
|
||||
this.SetMessage ('Invalid vertex index.');
|
||||
break;
|
||||
}
|
||||
let triangle = new OV.Triangle (v0, v1, v2);
|
||||
if (normals.length === vertices.length) {
|
||||
let n0 = GetLocalNormalIndex (this, this.currentMesh, normals[0]);
|
||||
let n1 = GetLocalNormalIndex (this, this.currentMesh, normals[i + 1]);
|
||||
let n2 = GetLocalNormalIndex (this, this.currentMesh, normals[i + 2]);
|
||||
if (n0 === null || n1 === null || n2 === null) {
|
||||
this.SetError ();
|
||||
this.SetMessage ('Invalid normal index.');
|
||||
break;
|
||||
}
|
||||
triangle.SetNormals (n0, n1, n2);
|
||||
}
|
||||
if (uvs.length === vertices.length) {
|
||||
let u0 = GetLocalUVIndex (this, this.currentMesh, uvs[0]);
|
||||
let u1 = GetLocalUVIndex (this, this.currentMesh, uvs[i + 1]);
|
||||
let u2 = GetLocalUVIndex (this, this.currentMesh, uvs[i + 2]);
|
||||
if (u0 === null || u1 === null || u2 === null) {
|
||||
this.SetError ();
|
||||
this.SetMessage ('Invalid uv index.');
|
||||
break;
|
||||
}
|
||||
triangle.SetTextureUVs (u0, u1, u2);
|
||||
}
|
||||
if (this.currentMaterialIndex !== null) {
|
||||
triangle.mat = this.currentMaterialIndex;
|
||||
}
|
||||
this.currentMesh.AddTriangle (triangle);
|
||||
}
|
||||
}
|
||||
ProcessFace (parameters)
|
||||
{
|
||||
function GetRelativeIndex (index, count)
|
||||
{
|
||||
if (index > 0) {
|
||||
return index - 1;
|
||||
} else {
|
||||
return count + index;
|
||||
}
|
||||
}
|
||||
|
||||
function GetLocalIndex (globalValueArray, globalToCurrentIndices, globalIndex, valueAdderFunc)
|
||||
{
|
||||
if (isNaN (globalIndex) || globalIndex < 0 || globalIndex >= globalValueArray.length) {
|
||||
return null;
|
||||
}
|
||||
let result = globalToCurrentIndices[globalIndex];
|
||||
if (result === undefined) {
|
||||
let globalValue = globalValueArray[globalIndex];
|
||||
if (globalValue === undefined) {
|
||||
return null;
|
||||
}
|
||||
result = valueAdderFunc (globalValue);
|
||||
globalToCurrentIndices[globalIndex] = result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function GetLocalVertexIndex (obj, mesh, globalIndex)
|
||||
{
|
||||
return GetLocalIndex (obj.globalVertices, obj.currentMeshData.globalToCurrentVertices, globalIndex, function (val) {
|
||||
return mesh.AddVertex (new OV.Coord3D (val.x, val.y, val.z));
|
||||
});
|
||||
}
|
||||
|
||||
function GetLocalNormalIndex (obj, mesh, globalIndex)
|
||||
{
|
||||
return GetLocalIndex (obj.globalNormals, obj.currentMeshData.globalToCurrentNormals, globalIndex, function (val) {
|
||||
return mesh.AddNormal (new OV.Coord3D (val.x, val.y, val.z));
|
||||
});
|
||||
}
|
||||
|
||||
function GetLocalUVIndex (obj, mesh, globalIndex)
|
||||
{
|
||||
return GetLocalIndex (obj.globalUvs, obj.currentMeshData.globalToCurrentUvs, globalIndex, function (val) {
|
||||
return mesh.AddTextureUV (new OV.Coord2D (val.x, val.y));
|
||||
});
|
||||
}
|
||||
|
||||
let vertices = [];
|
||||
let normals = [];
|
||||
let uvs = [];
|
||||
|
||||
for (let i = 0; i < parameters.length; i++) {
|
||||
let vertexParams = parameters[i].split ('/');
|
||||
vertices.push (GetRelativeIndex (parseInt (vertexParams[0], 10), this.globalVertices.length));
|
||||
if (vertexParams.length > 1 && vertexParams[1].length > 0) {
|
||||
uvs.push (GetRelativeIndex (parseInt (vertexParams[1], 10), this.globalUvs.length));
|
||||
}
|
||||
if (vertexParams.length > 2 && vertexParams[2].length > 0) {
|
||||
normals.push (GetRelativeIndex (parseInt (vertexParams[2], 10), this.globalNormals.length));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.currentMesh === null) {
|
||||
this.AddNewMesh ('');
|
||||
}
|
||||
|
||||
for (let i = 0; i < vertices.length - 2; i++) {
|
||||
let v0 = GetLocalVertexIndex (this, this.currentMesh, vertices[0]);
|
||||
let v1 = GetLocalVertexIndex (this, this.currentMesh, vertices[i + 1]);
|
||||
let v2 = GetLocalVertexIndex (this, this.currentMesh, vertices[i + 2]);
|
||||
if (v0 === null || v1 === null || v2 === null) {
|
||||
this.SetError ();
|
||||
this.SetMessage ('Invalid vertex index.');
|
||||
break;
|
||||
}
|
||||
let triangle = new OV.Triangle (v0, v1, v2);
|
||||
if (normals.length === vertices.length) {
|
||||
let n0 = GetLocalNormalIndex (this, this.currentMesh, normals[0]);
|
||||
let n1 = GetLocalNormalIndex (this, this.currentMesh, normals[i + 1]);
|
||||
let n2 = GetLocalNormalIndex (this, this.currentMesh, normals[i + 2]);
|
||||
if (n0 === null || n1 === null || n2 === null) {
|
||||
this.SetError ();
|
||||
this.SetMessage ('Invalid normal index.');
|
||||
break;
|
||||
}
|
||||
triangle.SetNormals (n0, n1, n2);
|
||||
}
|
||||
if (uvs.length === vertices.length) {
|
||||
let u0 = GetLocalUVIndex (this, this.currentMesh, uvs[0]);
|
||||
let u1 = GetLocalUVIndex (this, this.currentMesh, uvs[i + 1]);
|
||||
let u2 = GetLocalUVIndex (this, this.currentMesh, uvs[i + 2]);
|
||||
if (u0 === null || u1 === null || u2 === null) {
|
||||
this.SetError ();
|
||||
this.SetMessage ('Invalid uv index.');
|
||||
break;
|
||||
}
|
||||
triangle.SetTextureUVs (u0, u1, u2);
|
||||
}
|
||||
if (this.currentMaterialIndex !== null) {
|
||||
triangle.mat = this.currentMaterialIndex;
|
||||
}
|
||||
this.currentMesh.AddTriangle (triangle);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -7,9 +7,9 @@ OV.ImporterOff = class extends OV.ImporterBase
|
||||
this.mesh = null;
|
||||
this.status = null;
|
||||
}
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
this.mesh = new OV.Mesh ();
|
||||
this.model.AddMesh (this.mesh);
|
||||
this.status = {
|
||||
@ -18,47 +18,47 @@ OV.ImporterOff = class extends OV.ImporterBase
|
||||
foundVertex : 0,
|
||||
foundFace : 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'off';
|
||||
}
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'off';
|
||||
}
|
||||
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {
|
||||
'off' : OV.FileFormat.Text
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
return {
|
||||
'off' : OV.FileFormat.Text
|
||||
};
|
||||
}
|
||||
|
||||
GetUpDirection ()
|
||||
{
|
||||
return OV.Direction.Y;
|
||||
}
|
||||
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
let obj = this;
|
||||
OV.ReadLines (fileContent, function (line) {
|
||||
if (!obj.IsError ()) {
|
||||
obj.ProcessLine (line);
|
||||
}
|
||||
});
|
||||
OV.ReadLines (fileContent, function (line) {
|
||||
if (!obj.IsError ()) {
|
||||
obj.ProcessLine (line);
|
||||
}
|
||||
});
|
||||
onFinish ();
|
||||
}
|
||||
|
||||
ProcessLine (line)
|
||||
{
|
||||
if (line[0] === '#') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ProcessLine (line)
|
||||
{
|
||||
if (line[0] === '#') {
|
||||
return;
|
||||
}
|
||||
|
||||
let parameters = OV.ParametersFromLine (line, '#');
|
||||
if (parameters.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let parameters = OV.ParametersFromLine (line, '#');
|
||||
if (parameters.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (parameters[0] === 'OFF') {
|
||||
return;
|
||||
}
|
||||
@ -100,5 +100,5 @@ OV.ImporterOff = class extends OV.ImporterBase
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -92,32 +92,32 @@ OV.ImporterPly = class extends OV.ImporterBase
|
||||
this.model = null;
|
||||
this.mesh = null;
|
||||
}
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
this.mesh = new OV.Mesh ();
|
||||
this.model.AddMesh (this.mesh);
|
||||
}
|
||||
}
|
||||
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'ply';
|
||||
}
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'ply';
|
||||
}
|
||||
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {
|
||||
'ply' : OV.FileFormat.Binary
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
return {
|
||||
'ply' : OV.FileFormat.Binary
|
||||
};
|
||||
}
|
||||
|
||||
GetUpDirection ()
|
||||
{
|
||||
return OV.Direction.Y;
|
||||
}
|
||||
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
let headerString = this.GetHeaderContent (fileContent);
|
||||
let header = this.ReadHeader (headerString);
|
||||
if (header.Check ()) {
|
||||
@ -133,7 +133,7 @@ OV.ImporterPly = class extends OV.ImporterBase
|
||||
this.SetMessage ('Invalid header information.');
|
||||
}
|
||||
onFinish ();
|
||||
}
|
||||
}
|
||||
|
||||
GetHeaderContent (fileContent)
|
||||
{
|
||||
@ -180,7 +180,7 @@ OV.ImporterPly = class extends OV.ImporterBase
|
||||
header.AddSingleFormat (parameters[1], parameters[2]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return header;
|
||||
}
|
||||
@ -231,7 +231,7 @@ OV.ImporterPly = class extends OV.ImporterBase
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ReadBinaryContent (header, fileContent, headerLength)
|
||||
|
||||
@ -6,33 +6,33 @@ OV.ImporterStl = class extends OV.ImporterBase
|
||||
this.mesh = null;
|
||||
this.triangle = null;
|
||||
}
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
|
||||
ResetState ()
|
||||
{
|
||||
this.mesh = new OV.Mesh ();
|
||||
this.model.AddMesh (this.mesh);
|
||||
this.triangle = null;
|
||||
}
|
||||
}
|
||||
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'stl';
|
||||
}
|
||||
CanImportExtension (extension)
|
||||
{
|
||||
return extension === 'stl';
|
||||
}
|
||||
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {
|
||||
'stl' : OV.FileFormat.Binary
|
||||
};
|
||||
}
|
||||
|
||||
GetKnownFileFormats ()
|
||||
{
|
||||
return {
|
||||
'stl' : OV.FileFormat.Binary
|
||||
};
|
||||
}
|
||||
|
||||
GetUpDirection ()
|
||||
{
|
||||
return OV.Direction.Z;
|
||||
}
|
||||
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
ImportContent (fileContent, onFinish)
|
||||
{
|
||||
if (this.IsBinaryStlFile (fileContent)) {
|
||||
this.ProcessBinary (fileContent);
|
||||
} else {
|
||||
@ -45,10 +45,10 @@ OV.ImporterStl = class extends OV.ImporterBase
|
||||
});
|
||||
}
|
||||
onFinish ();
|
||||
}
|
||||
}
|
||||
|
||||
IsBinaryStlFile (fileContent)
|
||||
{
|
||||
IsBinaryStlFile (fileContent)
|
||||
{
|
||||
let byteLength = fileContent.byteLength;
|
||||
if (byteLength < 84) {
|
||||
return false;
|
||||
@ -65,17 +65,17 @@ OV.ImporterStl = class extends OV.ImporterBase
|
||||
return true;
|
||||
}
|
||||
|
||||
ProcessLine (line)
|
||||
{
|
||||
if (line[0] === '#') {
|
||||
return;
|
||||
}
|
||||
ProcessLine (line)
|
||||
{
|
||||
if (line[0] === '#') {
|
||||
return;
|
||||
}
|
||||
|
||||
let parameters = OV.ParametersFromLine (line, '#');
|
||||
if (parameters.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let parameters = OV.ParametersFromLine (line, '#');
|
||||
if (parameters.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let keyword = parameters[0];
|
||||
if (keyword === 'solid') {
|
||||
if (parameters.length > 1) {
|
||||
@ -133,7 +133,7 @@ OV.ImporterStl = class extends OV.ImporterBase
|
||||
}
|
||||
|
||||
ProcessBinary (fileContent)
|
||||
{
|
||||
{
|
||||
function ReadVector (reader)
|
||||
{
|
||||
let coord = new OV.Coord3D ();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user