@blockv/threejs-to-v3d
Version:
Converts any format supported by ThreeJS to V3D.
61 lines (43 loc) • 1.31 kB
JavaScript
//
// Superclass. Represents a file.
module.exports = class DataFile {
static isSupported(fileData) {
return false;
}
constructor(path) {
// Properties
this.path = path;
this.error = null;
this.used = false;
}
/** @private Removes all ocurrences of a string from another string */
replaceText(haystack, needle, replaceWith) {
// Check args
if (!haystack) haystack = "";
if (!needle) return haystack;
if (!replaceWith) replaceWith = "";
// Replace it
var idx = 0;
while ((idx = haystack.indexOf(needle)) != -1)
haystack = haystack.substring(0, idx) + replaceWith + haystack.substring(idx + needle.length);
// Done
return haystack;
}
/** Get last path component */
get name() {
// Replace \ with /
var name = this.replaceText(this.path, "\\", "/");
var idx = name.lastIndexOf("/");
if (idx != -1)
name = name.substring(idx+1);
return name;
}
loadText() {
this.used = true;
return Promise.reject(this.error || new Error("No data."));
}
loadBytes() {
this.used = true;
return Promise.reject(this.error || new Error("No data."));
}
}