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