From e9f9e06fc9f21bf1b92114405029ef680c38b68c Mon Sep 17 00:00:00 2001 From: Andriy Sheredko Date: Wed, 20 Aug 2025 15:40:56 +0300 Subject: [PATCH] ENG-8627 | Fix .3ds files not rendering in MFR viewer --- mfr/extensions/jsc3d/static/js/jsc3d.3ds.js | 97 ++++++++++++++++----- 1 file changed, 73 insertions(+), 24 deletions(-) diff --git a/mfr/extensions/jsc3d/static/js/jsc3d.3ds.js b/mfr/extensions/jsc3d/static/js/jsc3d.3ds.js index 117a33f69..539e05009 100644 --- a/mfr/extensions/jsc3d/static/js/jsc3d.3ds.js +++ b/mfr/extensions/jsc3d/static/js/jsc3d.3ds.js @@ -77,11 +77,13 @@ JSC3D.Autodesk3DSLoader.prototype.loadFromUrl = function(urlName) { xhr.onreadystatechange = function() { if(this.readyState == 4) { if(this.status == 200 || this.status == 0) { - if(JSC3D.console) + if(JSC3D.console) { JSC3D.console.logInfo('Finished loading 3DS file "' + urlName + '".'); + } if(self.onload) { - if(self.onprogress) + if(self.onprogress) { self.onprogress('Loading 3DS file ...', 1); + } // if(JSC3D.PlatformInfo.browser == 'ie' && JSC3D.PlatformInfo.version >= '10') { // // asynchronously decode blob to binary string // var blobReader = new FileReader; @@ -107,10 +109,12 @@ JSC3D.Autodesk3DSLoader.prototype.loadFromUrl = function(urlName) { } } else { - if(JSC3D.console) + if(JSC3D.console) { JSC3D.console.logError('Failed to load 3DS file "' + urlName + '".'); - if(self.onerror) + } + if(self.onerror) { self.onerror('Failed to load 3DS file "' + urlName + '".'); + } } self.request = null; } @@ -199,9 +203,12 @@ JSC3D.Autodesk3DSLoader.prototype.readAmount = function(reader,end) { len = reader.readUInt32(); switch (cid) { - case 0x0030: // Floats + case 0x0030: amount = reader.readUInt16(); break; + case 0x0031: + amount = reader.readFloat32() * 100.0; + break; default: break; } @@ -461,14 +468,16 @@ JSC3D.Autodesk3DSLoader.prototype.parseObjectAnimation = function (reader,end) { if (name != '$$$DUMMY' && this._unfinalized_objects.hasOwnProperty(name)) { vo = this._unfinalized_objects[name]; // todo vasea - if(JSC3D.console) + if(JSC3D.console) { JSC3D.console.logInfo('Construct object '+vo.name); + } // this._cur_obj = null; obj = null;//this.constructObject(vo, pivot); if (obj) { - if(JSC3D.console) + if(JSC3D.console) { JSC3D.console.logInfo('finished loading the object '+vo.name); + } } delete this._unfinalized_objects[name]; @@ -489,8 +498,8 @@ JSC3D.Autodesk3DSLoader.prototype.parseSmoothingGroups = function (reader) { JSC3D.Autodesk3DSLoader.prototype.finalizeCurrentMaterial = function () { var mat = new JSC3D.Material; - if (this._cur_mat.colorMap) { - mat.textureFileName = this._cur_mat.colorMap.texture; + if (this._cur_mat.colorMap && this._cur_mat.colorMap.url) { + mat.textureFileName = this._cur_mat.colorMap.url; } else { mat.diffuseColor = this._cur_mat.diffuseColor; @@ -517,8 +526,9 @@ JSC3D.Autodesk3DSLoader.prototype.setupTexture = function(meshList, textureUrlNa texture.onready = function() { for(var i=0; i0); - mesh.isDoubleSided = true;//currentMaterial.twoSided; - mesh.material.transparency = currentMaterial.transparency>0?(currentMaterial.transparency)/100:0; + + // Transparency: normalize (0..1), snap tiny values to 0 to avoid z-sort artifacts + var t = currentMaterial.transparency; + if (typeof t === 'number') { + var alpha = (t > 1) ? (t / 100.0) : t; + alpha = Math.max(0, Math.min(1, alpha)); + if (alpha < 0.01) alpha = 0; + mesh.material.transparency = alpha; + } else { + mesh.material.transparency = 0; + } + + var two = (currentMaterial.twoSided !== undefined) ? !!currentMaterial.twoSided : true; + mesh.isDoubleSided = two; + mesh.material.bothSides = two; } + if (!sawMaterial) { + mesh.isDoubleSided = true; + mesh.material.bothSides = true; + mesh.material.transparency = 0; + } + if (!mesh.texCoordBuffer || !mesh.texCoordIndexBuffer) { + mesh.texCoordBuffer = null; + mesh.texCoordIndexBuffer = null; + } //mesh.faceNormalBuffer = []; // mesh.init(); @@ -672,7 +721,7 @@ JSC3D.Autodesk3DSLoader.prototype.parse3DS = function(scene, data) { this._cur_obj = {}; this._cur_obj.name = this.readNulTermString(reader); this._cur_obj.materials = []; - this._cur_obj.materialFaces = []; + this._cur_obj.materialFaces = {}; break; case 0x4100: // OBJ_TRIMESH