@gltf-transform/extensions
Advanced tools
Comparing version 0.7.0-alpha.2 to 0.7.0-alpha.4
@@ -1,2 +0,2 @@ | ||
import { Extension, ExtensionConstructor } from './extension'; | ||
import { Extension } from './extension'; | ||
import { Accessor, Animation, AnimationChannel, AnimationSampler, Buffer, Camera, Material, Mesh, Node, Primitive, PrimitiveTarget, PropertyGraph, Root, Scene, Skin, Texture } from './properties'; | ||
@@ -106,3 +106,3 @@ import { Logger } from './utils'; | ||
*/ | ||
createExtension(ctor: ExtensionConstructor): Extension; | ||
createExtension<T extends Extension>(ctor: new (doc: Document) => T): T; | ||
/********************************************************************************************** | ||
@@ -141,3 +141,3 @@ * Property factory methods. | ||
*/ | ||
createAnimationChannel(): AnimationChannel; | ||
createAnimationChannel(name?: string): AnimationChannel; | ||
/** | ||
@@ -147,3 +147,3 @@ * Creates a new {@link AnimationSampler}. Samplers must be attached to an {@link Animation} | ||
*/ | ||
createAnimationSampler(): AnimationSampler; | ||
createAnimationSampler(name?: string): AnimationSampler; | ||
/** Creates a new {@link Accessor} attached to this document's {@link Root}. */ | ||
@@ -150,0 +150,0 @@ createAccessor(name?: string, buffer?: Buffer): Accessor; |
@@ -6,10 +6,2 @@ import { PropertyType } from './constants'; | ||
/** | ||
* Type alias allowing Extension constructors to be used as tokens for type checking. | ||
* @hidden | ||
*/ | ||
export declare type ExtensionConstructor = { | ||
new (doc: Document): Extension; | ||
EXTENSION_NAME: string; | ||
}; | ||
/** | ||
* # Extension | ||
@@ -16,0 +8,0 @@ * |
@@ -1,2 +0,2 @@ | ||
var e,t=require("@gltf-transform/core");function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,s=new Array(t);r<t;r++)s[r]=e[r];return s}function n(e){var t=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,t){if(e){if("string"==typeof e)return s(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,void 0):void 0}}(e)))return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}function o(t,r){var s;try{if((s=new e.DecoderBuffer).Init(new Int8Array(r),r.byteLength),t.GetEncodedGeometryType(s)!==e.TRIANGULAR_MESH)throw new Error("Unknown geometry type.");var n=new e.Mesh;if(!t.DecodeBufferToMesh(s,n).ok()||0===n.ptr)throw new Error("Decoding failure.");return n}finally{e.destroy(s)}}function a(t,r){for(var s=r.num_faces(),n=new Uint32Array(3*s),o=new e.DracoInt32Array,a=0;a<s;a++){t.GetFaceFromMesh(r,a,o);for(var i=0;i<3;++i)n[3*a+i]=o.GetValue(i)}return e.destroy(o),n}function i(t,r,s,n){var o,a,i=function(e){switch(e){case 5126:return Float32Array;case 5125:return Uint32Array;case 5123:return Uint16Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5120:return Int8Array}}(n.componentType),u=s.num_components(),c=r.num_points()*u;switch(i){case Float32Array:o=new e.DracoFloat32Array,t.GetAttributeFloatForAllPoints(r,s,o),a=new Float32Array(c);break;case Int8Array:o=new e.DracoInt8Array,t.GetAttributeInt8ForAllPoints(r,s,o),a=new Int8Array(c);break;case Int16Array:o=new e.DracoInt16Array,t.GetAttributeInt16ForAllPoints(r,s,o),a=new Int16Array(c);break;case Uint8Array:o=new e.DracoUInt8Array,t.GetAttributeUInt8ForAllPoints(r,s,o),a=new Uint8Array(c);break;case Uint16Array:o=new e.DracoUInt16Array,t.GetAttributeUInt16ForAllPoints(r,s,o),a=new Uint16Array(c);break;case Uint32Array:o=new e.DracoUInt32Array,t.GetAttributeUInt32ForAllPoints(r,s,o),a=new Uint32Array(c);break;default:throw new Error("Unexpected attribute type.")}for(var l=0;l<c;l++)a[l]=o.GetValue(l);return e.destroy(o),a}var u,c="KHR_draco_mesh_compression",l=function(s){function u(){var e;return(e=s.apply(this,arguments)||this).extensionName=c,e.provideTypes=[t.PropertyType.PRIMITIVE],e.dependencies=["draco3d.decoder"],e}r(u,s);var l=u.prototype;return l.install=function(t,r){return"draco3d.decoder"===t&&(this._decoderModule=r,e=this._decoderModule),this},l.provide=function(e){if(!this._decoderModule)throw new Error('Please install extension dependency, "draco3d.decoder".');for(var r,s=this.doc.getLogger(),u=e.jsonDoc,l=new this._decoderModule.Decoder,x=new Map,p=n(u.json.meshes);!(r=p()).done;){for(var h,f=n(r.value.primitives);!(h=f()).done;){var T=h.value;if(T.extensions&&T.extensions[c]){var g=T.extensions[c],m=x.get(g.bufferView);if(!m){var y=u.json.bufferViews[g.bufferView],d=u.json.buffers[y.buffer],v=new Uint8Array(d.uri?u.resources[d.uri]:u.resources[t.GLB_BUFFER],y.byteOffset||0,y.byteLength);m=o(l,v),x.set(g.bufferView,m),s.debug("Decompressed "+v.byteLength+" bytes.")}for(var _ in T.attributes){var C=e.jsonDoc.json.accessors[T.attributes[_]],I=l.GetAttributeByUniqueId(m,g.attributes[_]),E=i(l,m,I,C);e.accessors[T.attributes[_]].setArray(E)}var N=a(l,m);e.accessors[T.indices].setArray(N)}}this._decoderModule.destroy(l);for(var S=0,F=Array.from(x.values());S<F.length;S++)this._decoderModule.destroy(F[S])}return this},l.read=function(e){return this.dispose(),this},l.write=function(e){return this.doc.getLogger().warn("Writing "+this.extensionName+" not yet implemented."),this},u}(t.Extension);l.EXTENSION_NAME=c,(u=exports.LightType||(exports.LightType={})).POINT="point",u.SPOT="spot",u.DIRECTIONAL="directional";var x=function(e){function s(){var r;return(r=e.apply(this,arguments)||this).propertyType="Light",r.parentTypes=[t.PropertyType.NODE],r.extensionName="KHR_lights_punctual",r._color=[1,1,1],r._intensity=1,r._range=void 0,r._innerConeAngle=0,r._outerConeAngle=Math.PI/4,r}r(s,e);var n=s.prototype;return n.copy=function(r,s){return void 0===s&&(s=t.COPY_IDENTITY),e.prototype.copy.call(this,r,s),this._color=[].concat(r._color),this._intensity=r._intensity,this._type=r._type,this._range=r._range,this._innerConeAngle=r._innerConeAngle,this._outerConeAngle=r._outerConeAngle,this},n.getColor=function(){return this._color},n.setColor=function(e){return this._color=e,this},n.getColorHex=function(){return t.ColorUtils.factorToHex(this._color)},n.setColorHex=function(e){return t.ColorUtils.hexToFactor(e,this._color),this},n.getIntensity=function(){return this._intensity},n.setIntensity=function(e){return this._intensity=e,this},n.getType=function(){return this._type},n.setType=function(e){return this._type=e,this},n.getRange=function(){return this._range},n.setRange=function(e){return this._range=e,this},n.getInnerConeAngle=function(){return this._innerConeAngle},n.setInnerConeAngle=function(e){return this._innerConeAngle=e,this},n.getOuterConeAngle=function(){return this._outerConeAngle},n.setOuterConeAngle=function(e){return this._outerConeAngle=e,this},s}(t.ExtensionProperty);x.EXTENSION_NAME="KHR_lights_punctual";var p="KHR_lights_punctual",h=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=p,t}r(t,e);var s=t.prototype;return s.createLight=function(){return new x(this.doc.getGraph(),this)},s.read=function(e){var t=this,r=e.jsonDoc;if(!r.json.extensions||!r.json.extensions[p])return this;var s=(r.json.extensions[p].lights||[]).map(function(e){var r=t.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&r.setColor(e.color),void 0!==e.intensity&&r.setIntensity(e.intensity),void 0!==e.range&&r.setRange(e.range),void 0!==e.innerConeAngle&&r.setInnerConeAngle(e.innerConeAngle),void 0!==e.outerConeAngle&&r.setOuterConeAngle(e.outerConeAngle),r});return r.json.nodes.forEach(function(t,r){t.extensions&&t.extensions[p]&&e.nodes[r].setExtension(p,s[t.extensions[p].light])}),this},s.write=function(e){var t=e.jsonDoc;if(0===this.properties.size)return this;for(var r,s=[],o=new Map,a=n(this.properties);!(r=a()).done;){var i=r.value,u={type:i.getType(),color:i.getColor(),intensity:i.getIntensity(),range:i.getRange()};i.getName()&&(u.name=i.getName()),i.getType()===exports.LightType.SPOT&&(u.innerConeAngle=i.getInnerConeAngle(),u.outerConeAngle=i.getOuterConeAngle()),s.push(u),o.set(i,s.length-1)}return this.doc.getRoot().listNodes().forEach(function(r){var s=r.getExtension(p);if(s){var n=e.nodeIndexMap.get(r),a=t.json.nodes[n];a.extensions=a.extensions||{},a.extensions[p]={light:o.get(s)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[p]={lights:s},this},t}(t.Extension);function f(e,t,r,s){var n,o=arguments.length,a=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(n=e[i])&&(a=(o<3?n(a):o>3?n(t,r,a):n(t,r))||a);return o>3&&a&&Object.defineProperty(t,r,a),a}h.EXTENSION_NAME=p;var T=function(e){function s(){var r;return(r=e.apply(this,arguments)||this).propertyType="Clearcoat",r.parentTypes=[t.PropertyType.MATERIAL],r.extensionName="KHR_materials_clearcoat",r._clearcoatFactor=0,r._clearcoatRoughnessFactor=0,r._clearcoatNormalScale=1,r.clearcoatTexture=null,r.clearcoatRoughnessTexture=null,r.clearcoatNormalTexture=null,r}r(s,e);var n=s.prototype;return n.copy=function(r,s){return void 0===s&&(s=t.COPY_IDENTITY),e.prototype.copy.call(this,r,s),this._clearcoatFactor=r._clearcoatFactor,this._clearcoatRoughnessFactor=r._clearcoatRoughnessFactor,this._clearcoatNormalScale=r._clearcoatNormalScale,r.clearcoatTexture&&(this.setClearcoatTexture(s(r.clearcoatTexture.getChild())),this.clearcoatTexture.copy(r.clearcoatTexture)),r.clearcoatRoughnessTexture&&(this.setClearcoatRoughnessTexture(s(r.clearcoatRoughnessTexture.getChild())),this.clearcoatRoughnessTexture.copy(r.clearcoatRoughnessTexture)),r.clearcoatNormalTexture&&(this.setClearcoatNormalTexture(s(r.clearcoatNormalTexture.getChild())),this.clearcoatNormalTexture.copy(r.clearcoatNormalTexture)),this},n.getClearcoatFactor=function(){return this._clearcoatFactor},n.setClearcoatFactor=function(e){return this._clearcoatFactor=e,this},n.getClearcoatTexture=function(){return this.clearcoatTexture?this.clearcoatTexture.getChild():null},n.getClearcoatTextureInfo=function(){return this.clearcoatTexture?this.clearcoatTexture.textureInfo:null},n.getClearcoatTextureSampler=function(){return this.clearcoatTexture?this.clearcoatTexture.sampler:null},n.setClearcoatTexture=function(e){return this.clearcoatTexture=this.graph.linkTexture("clearcoatTexture",this,e),this},n.getClearcoatRoughnessFactor=function(){return this._clearcoatRoughnessFactor},n.setClearcoatRoughnessFactor=function(e){return this._clearcoatRoughnessFactor=e,this},n.getClearcoatRoughnessTexture=function(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTexture.getChild():null},n.getClearcoatRoughnessTextureInfo=function(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTexture.textureInfo:null},n.getClearcoatRoughnessTextureSampler=function(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTexture.sampler:null},n.setClearcoatRoughnessTexture=function(e){return this.clearcoatRoughnessTexture=this.graph.linkTexture("clearcoatRoughnessTexture",this,e),this},n.getClearcoatNormalScale=function(){return this._clearcoatNormalScale},n.setClearcoatNormalScale=function(e){return this._clearcoatNormalScale=e,this},n.getClearcoatNormalTexture=function(){return this.clearcoatNormalTexture?this.clearcoatNormalTexture.getChild():null},n.getClearcoatNormalTextureInfo=function(){return this.clearcoatNormalTexture?this.clearcoatNormalTexture.textureInfo:null},n.getClearcoatNormalTextureSampler=function(){return this.clearcoatNormalTexture?this.clearcoatNormalTexture.sampler:null},n.setClearcoatNormalTexture=function(e){return this.clearcoatNormalTexture=this.graph.linkTexture("clearcoatNormalTexture",this,e),this},s}(t.ExtensionProperty);T.EXTENSION_NAME="KHR_materials_clearcoat",f([t.GraphChild],T.prototype,"clearcoatTexture",void 0),f([t.GraphChild],T.prototype,"clearcoatRoughnessTexture",void 0),f([t.GraphChild],T.prototype,"clearcoatNormalTexture",void 0);var g="KHR_materials_clearcoat",m=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=g,t}r(t,e);var s=t.prototype;return s.createClearcoat=function(){return new T(this.doc.getGraph(),this)},s.read=function(e){var t=this,r=e.jsonDoc,s=r.json.textures||[];return(r.json.materials||[]).forEach(function(r,n){if(r.extensions&&r.extensions[g]){var o=t.createClearcoat();if(e.materials[n].setExtension(g,o),void 0!==r.extensions[g].clearcoatFactor&&o.setClearcoatFactor(r.extensions[g].clearcoatFactor),void 0!==r.extensions[g].clearcoatRoughnessFactor&&o.setClearcoatRoughnessFactor(r.extensions[g].clearcoatRoughnessFactor),void 0!==r.extensions[g].clearcoatTexture){var a=r.extensions[g].clearcoatTexture;o.setClearcoatTexture(e.textures[s[a.index].source]),e.setTextureInfo(o.getClearcoatTextureInfo(),a),e.setTextureSampler(o.getClearcoatTextureSampler(),a)}if(void 0!==r.extensions[g].clearcoatRoughnessTexture){var i=r.extensions[g].clearcoatRoughnessTexture;o.setClearcoatRoughnessTexture(e.textures[s[i.index].source]),e.setTextureInfo(o.getClearcoatRoughnessTextureInfo(),i),e.setTextureSampler(o.getClearcoatRoughnessTextureSampler(),i)}if(void 0!==r.extensions[g].clearcoatNormalTexture){var u=r.extensions[g].clearcoatNormalTexture;o.setClearcoatNormalTexture(e.textures[s[u.index].source]),e.setTextureInfo(o.getClearcoatNormalTextureInfo(),u),e.setTextureSampler(o.getClearcoatNormalTextureSampler(),u),void 0!==u.scale&&o.setClearcoatNormalScale(u.scale)}}}),this},s.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var s=r.getExtension(g);if(s){var n=e.materialIndexMap.get(r),o=t.json.materials[n];if(o.extensions=o.extensions||{},o.extensions[g]={clearcoatFactor:s.getClearcoatFactor(),clearcoatRoughnessFactor:s.getClearcoatRoughnessFactor()},s.getClearcoatTexture()){var a=s.getClearcoatTexture(),i=s.getClearcoatTextureInfo(),u=s.getClearcoatTextureSampler();o.extensions[g].clearcoatTexture=e.createTextureInfoDef(a,i,u)}if(s.getClearcoatRoughnessTexture()){var c=s.getClearcoatRoughnessTexture(),l=s.getClearcoatRoughnessTextureInfo(),x=s.getClearcoatRoughnessTextureSampler();o.extensions[g].clearcoatRoughnessTexture=e.createTextureInfoDef(c,l,x)}if(s.getClearcoatNormalTexture()){var p=s.getClearcoatNormalTexture(),h=s.getClearcoatNormalTextureInfo(),f=s.getClearcoatNormalTextureSampler();o.extensions[g].clearcoatNormalTexture=e.createTextureInfoDef(p,h,f),1!==s.getClearcoatNormalScale()&&(o.extensions[g].clearcoatNormalTexture.scale=s.getClearcoatNormalScale())}}}),this},t}(t.Extension);m.EXTENSION_NAME=g;var y=function(e){function s(){var r;return(r=e.apply(this,arguments)||this).propertyType="IOR",r.parentTypes=[t.PropertyType.MATERIAL],r.extensionName="KHR_materials_ior",r._ior=0,r}r(s,e);var n=s.prototype;return n.copy=function(r,s){return void 0===s&&(s=t.COPY_IDENTITY),e.prototype.copy.call(this,r,s),this._ior=r._ior,this},n.getIOR=function(){return this._ior},n.setIOR=function(e){return this._ior=e,this},s}(t.ExtensionProperty);y.EXTENSION_NAME="KHR_materials_ior";var d="KHR_materials_ior",v=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=d,t}r(t,e);var s=t.prototype;return s.createIOR=function(){return new y(this.doc.getGraph(),this)},s.read=function(e){var t=this;return(e.jsonDoc.json.materials||[]).forEach(function(r,s){if(r.extensions&&r.extensions[d]){var n=t.createIOR();e.materials[s].setExtension(d,n),void 0!==r.extensions[d].ior&&n.setIOR(r.extensions[d].ior)}}),this},s.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var s=r.getExtension(d);if(s){var n=e.materialIndexMap.get(r),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[d]={ior:s.getIOR()}}}),this},t}(t.Extension);v.EXTENSION_NAME=d;var _=function(e){function s(){var r;return(r=e.apply(this,arguments)||this).propertyType="PBRSpecularGlossiness",r.parentTypes=[t.PropertyType.MATERIAL],r.extensionName="KHR_materials_pbrSpecularGlossiness",r._diffuseFactor=[1,1,1,1],r._specularFactor=[1,1,1],r._glossinessFactor=1,r.diffuseTexture=null,r.specularGlossinessTexture=null,r}r(s,e);var n=s.prototype;return n.copy=function(r,s){return void 0===s&&(s=t.COPY_IDENTITY),e.prototype.copy.call(this,r,s),this._diffuseFactor=r._diffuseFactor,this._specularFactor=r._specularFactor,this._glossinessFactor=r._glossinessFactor,r.diffuseTexture&&(this.setDiffuseTexture(s(r.diffuseTexture.getChild())),this.diffuseTexture.copy(r.diffuseTexture)),r.specularGlossinessTexture&&(this.setSpecularGlossinessTexture(s(r.specularGlossinessTexture.getChild())),this.specularGlossinessTexture.copy(r.specularGlossinessTexture)),this},n.getDiffuseFactor=function(){return this._diffuseFactor},n.setDiffuseFactor=function(e){return this._diffuseFactor=e,this},n.getDiffuseHex=function(){return t.ColorUtils.factorToHex(this._diffuseFactor)},n.setDiffuseHex=function(e){return t.ColorUtils.hexToFactor(e,this._diffuseFactor),this},n.getDiffuseTexture=function(){return this.diffuseTexture?this.diffuseTexture.getChild():null},n.getDiffuseTextureInfo=function(){return this.diffuseTexture?this.diffuseTexture.textureInfo:null},n.getDiffuseTextureSampler=function(){return this.diffuseTexture?this.diffuseTexture.sampler:null},n.setDiffuseTexture=function(e){return this.diffuseTexture=this.graph.linkTexture("diffuseTexture",this,e),this},n.getSpecularFactor=function(){return this._specularFactor},n.setSpecularFactor=function(e){return this._specularFactor=e,this},n.getGlossinessFactor=function(){return this._glossinessFactor},n.setGlossinessFactor=function(e){return this._glossinessFactor=e,this},n.getSpecularGlossinessTexture=function(){return this.specularGlossinessTexture?this.specularGlossinessTexture.getChild():null},n.getSpecularGlossinessTextureInfo=function(){return this.specularGlossinessTexture?this.specularGlossinessTexture.textureInfo:null},n.getSpecularGlossinessTextureSampler=function(){return this.specularGlossinessTexture?this.specularGlossinessTexture.sampler:null},n.setSpecularGlossinessTexture=function(e){return this.specularGlossinessTexture=this.graph.linkTexture("specularGlossinessTexture",this,e),this},s}(t.ExtensionProperty);_.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness",f([t.GraphChild],_.prototype,"diffuseTexture",void 0),f([t.GraphChild],_.prototype,"specularGlossinessTexture",void 0);var C="KHR_materials_pbrSpecularGlossiness",I=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=C,t}r(t,e);var s=t.prototype;return s.createPBRSpecularGlossiness=function(){return new _(this.doc.getGraph(),this)},s.read=function(e){var t=this,r=e.jsonDoc,s=r.json.textures||[];return(r.json.materials||[]).forEach(function(r,n){if(r.extensions&&r.extensions[C]){var o=t.createPBRSpecularGlossiness();if(e.materials[n].setExtension(C,o),void 0!==r.extensions[C].diffuseFactor&&o.setDiffuseFactor(r.extensions[C].diffuseFactor),void 0!==r.extensions[C].specularFactor&&o.setSpecularFactor(r.extensions[C].specularFactor),void 0!==r.extensions[C].glossinessFactor&&o.setGlossinessFactor(r.extensions[C].glossinessFactor),void 0!==r.extensions[C].diffuseTexture){var a=r.extensions[C].diffuseTexture;o.setDiffuseTexture(e.textures[s[a.index].source]),e.setTextureInfo(o.getDiffuseTextureInfo(),a),e.setTextureSampler(o.getDiffuseTextureSampler(),a)}if(void 0!==r.extensions[C].specularGlossinessTexture){var i=r.extensions[C].specularGlossinessTexture;o.setSpecularGlossinessTexture(e.textures[s[i.index].source]),e.setTextureInfo(o.getSpecularGlossinessTextureInfo(),i),e.setTextureSampler(o.getSpecularGlossinessTextureSampler(),i)}}}),this},s.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var s=r.getExtension(C);if(s){var n=e.materialIndexMap.get(r),o=t.json.materials[n];if(o.extensions=o.extensions||{},o.extensions[C]={diffuseFactor:s.getDiffuseFactor(),specularFactor:s.getSpecularFactor(),glossinessFactor:s.getGlossinessFactor()},s.getDiffuseTexture()){var a=s.getDiffuseTexture(),i=s.getDiffuseTextureInfo(),u=s.getDiffuseTextureSampler();o.extensions[C].diffuseTexture=e.createTextureInfoDef(a,i,u)}if(s.getSpecularGlossinessTexture()){var c=s.getSpecularGlossinessTexture(),l=s.getSpecularGlossinessTextureInfo(),x=s.getSpecularGlossinessTextureSampler();o.extensions[C].specularGlossinessTexture=e.createTextureInfoDef(c,l,x)}}}),this},t}(t.Extension);I.EXTENSION_NAME=C;var E=function(e){function s(){var r;return(r=e.apply(this,arguments)||this).propertyType="Specular",r.parentTypes=[t.PropertyType.MATERIAL],r.extensionName="KHR_materials_specular",r._specularFactor=1,r._specularColorFactor=[1,1,1],r.specularTexture=null,r}r(s,e);var n=s.prototype;return n.copy=function(r,s){return void 0===s&&(s=t.COPY_IDENTITY),e.prototype.copy.call(this,r,s),this._specularFactor=r._specularFactor,r.specularTexture&&(this.setSpecularTexture(s(r.specularTexture.getChild())),this.specularTexture.copy(r.specularTexture)),this},n.getSpecularFactor=function(){return this._specularFactor},n.setSpecularFactor=function(e){return this._specularFactor=e,this},n.getSpecularColorFactor=function(){return this._specularColorFactor},n.setSpecularColorFactor=function(e){return this._specularColorFactor=e,this},n.getSpecularColorHex=function(){return t.ColorUtils.factorToHex(this._specularColorFactor)},n.setSpecularColorHex=function(e){return t.ColorUtils.hexToFactor(e,this._specularColorFactor),this},n.getSpecularTexture=function(){return this.specularTexture?this.specularTexture.getChild():null},n.getSpecularTextureInfo=function(){return this.specularTexture?this.specularTexture.textureInfo:null},n.getSpecularTextureSampler=function(){return this.specularTexture?this.specularTexture.sampler:null},n.setSpecularTexture=function(e){return this.specularTexture=this.graph.linkTexture("specularTexture",this,e),this},s}(t.ExtensionProperty);E.EXTENSION_NAME="KHR_materials_specular",f([t.GraphChild],E.prototype,"specularTexture",void 0);var N="KHR_materials_specular",S=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=N,t}r(t,e);var s=t.prototype;return s.createSpecular=function(){return new E(this.doc.getGraph(),this)},s.read=function(e){var t=this,r=e.jsonDoc,s=r.json.textures||[];return(r.json.materials||[]).forEach(function(r,n){if(r.extensions&&r.extensions[N]){var o=t.createSpecular();if(e.materials[n].setExtension(N,o),void 0!==r.extensions[N].specularFactor&&o.setSpecularFactor(r.extensions[N].specularFactor),void 0!==r.extensions[N].specularColorFactor&&o.setSpecularColorFactor(r.extensions[N].specularColorFactor),void 0!==r.extensions[N].specularTexture){var a=r.extensions[N].specularTexture;o.setSpecularTexture(e.textures[s[a.index].source]),e.setTextureInfo(o.getSpecularTextureInfo(),a),e.setTextureSampler(o.getSpecularTextureSampler(),a)}}}),this},s.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var s=r.getExtension(N);if(s){var n=e.materialIndexMap.get(r),o=t.json.materials[n];if(o.extensions=o.extensions||{},o.extensions[N]={specularFactor:s.getSpecularFactor(),specularColorFactor:s.getSpecularColorFactor()},s.getSpecularTexture()){var a=s.getSpecularTexture(),i=s.getSpecularTextureInfo(),u=s.getSpecularTextureSampler();o.extensions[N].specularTexture=e.createTextureInfoDef(a,i,u)}}}),this},t}(t.Extension);S.EXTENSION_NAME=N;var F=function(e){function s(){var r;return(r=e.apply(this,arguments)||this).propertyType="Transmission",r.parentTypes=[t.PropertyType.MATERIAL],r.extensionName="KHR_materials_transmission",r._transmissionFactor=0,r.transmissionTexture=null,r}r(s,e);var n=s.prototype;return n.copy=function(r,s){return void 0===s&&(s=t.COPY_IDENTITY),e.prototype.copy.call(this,r,s),this._transmissionFactor=r._transmissionFactor,r.transmissionTexture&&(this.setTransmissionTexture(s(r.transmissionTexture.getChild())),this.transmissionTexture.copy(r.transmissionTexture)),this},n.getTransmissionFactor=function(){return this._transmissionFactor},n.setTransmissionFactor=function(e){return this._transmissionFactor=e,this},n.getTransmissionTexture=function(){return this.transmissionTexture?this.transmissionTexture.getChild():null},n.getTransmissionTextureInfo=function(){return this.transmissionTexture?this.transmissionTexture.textureInfo:null},n.getTransmissionTextureSampler=function(){return this.transmissionTexture?this.transmissionTexture.sampler:null},n.setTransmissionTexture=function(e){return this.transmissionTexture=this.graph.linkTexture("transmissionTexture",this,e),this},s}(t.ExtensionProperty);F.EXTENSION_NAME="KHR_materials_transmission",f([t.GraphChild],F.prototype,"transmissionTexture",void 0);var R="KHR_materials_transmission",A=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=R,t}r(t,e);var s=t.prototype;return s.createTransmission=function(){return new F(this.doc.getGraph(),this)},s.read=function(e){var t=this,r=e.jsonDoc,s=r.json.textures||[];return(r.json.materials||[]).forEach(function(r,n){if(r.extensions&&r.extensions[R]){var o=t.createTransmission();if(e.materials[n].setExtension(R,o),void 0!==r.extensions[R].transmissionFactor&&o.setTransmissionFactor(r.extensions[R].transmissionFactor),void 0!==r.extensions[R].transmissionTexture){var a=r.extensions[R].transmissionTexture;o.setTransmissionTexture(e.textures[s[a.index].source]),e.setTextureInfo(o.getTransmissionTextureInfo(),a),e.setTextureSampler(o.getTransmissionTextureSampler(),a)}}}),this},s.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var s=r.getExtension(R);if(s){var n=e.materialIndexMap.get(r),o=t.json.materials[n];if(o.extensions=o.extensions||{},o.extensions[R]={transmissionFactor:s.getTransmissionFactor()},s.getTransmissionTexture()){var a=s.getTransmissionTexture(),i=s.getTransmissionTextureInfo(),u=s.getTransmissionTextureSampler();o.extensions[R].transmissionTexture=e.createTextureInfoDef(a,i,u)}}}),this},t}(t.Extension);A.EXTENSION_NAME=R;var G=function(e){function s(){var r;return(r=e.apply(this,arguments)||this).propertyType="Unlit",r.parentTypes=[t.PropertyType.MATERIAL],r.extensionName="KHR_materials_unlit",r}return r(s,e),s}(t.ExtensionProperty);G.EXTENSION_NAME="KHR_materials_unlit";var D="KHR_materials_unlit",M=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=D,t}r(t,e);var s=t.prototype;return s.createUnlit=function(){return new G(this.doc.getGraph(),this)},s.read=function(e){var t=this;return(e.jsonDoc.json.materials||[]).forEach(function(r,s){r.extensions&&r.extensions[D]&&e.materials[s].setExtension(D,t.createUnlit())}),this},s.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){if(r.getExtension(D)){var s=e.materialIndexMap.get(r),n=t.json.materials[s];n.extensions=n.extensions||{},n.extensions[D]={}}}),this},t}(t.Extension);M.EXTENSION_NAME=D;var w="KHR_mesh_quantization",j=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=w,t}r(t,e);var s=t.prototype;return s.read=function(e){return this},s.write=function(e){return this},t}(t.Extension);j.EXTENSION_NAME=w;var O="KHR_texture_basisu",b=function(e){function s(){var r;return(r=e.apply(this,arguments)||this).extensionName=O,r.provideTypes=[t.PropertyType.TEXTURE],r}r(s,e);var n=s.prototype;return n.provide=function(e){return e.jsonDoc.json.textures.forEach(function(e){e.extensions&&e.extensions[O]&&(e.source=e.extensions[O].source)}),this},n.read=function(e){return this},n.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listTextures().forEach(function(r){if("image/ktx2"===r.getMimeType()){var s=e.imageIndexMap.get(r);t.json.textures.forEach(function(e){e.source===s&&(e.extensions=e.extensions||{},e.extensions[O]={source:e.source},delete e.source)})}}),this},s}(t.Extension);b.EXTENSION_NAME=O;var P=[l,h,m,v,I,S,A,M,j,b];exports.Clearcoat=T,exports.DracoMeshCompression=l,exports.IOR=y,exports.KHRONOS_EXTENSIONS=P,exports.Light=x,exports.LightsPunctual=h,exports.MaterialsClearcoat=m,exports.MaterialsIOR=v,exports.MaterialsPBRSpecularGlossiness=I,exports.MaterialsSpecular=S,exports.MaterialsTransmission=A,exports.MaterialsUnlit=M,exports.MeshQuantization=j,exports.PBRSpecularGlossiness=_,exports.Specular=E,exports.TextureBasisu=b,exports.Transmission=F,exports.Unlit=G; | ||
var e,t,r,n=require("@gltf-transform/core");function o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function a(e){var t=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,t){if(e){if("string"==typeof e)return i(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,void 0):void 0}}(e)))return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}function u(t,r){var n;try{if((n=new e.DecoderBuffer).Init(new Int8Array(r),r.byteLength),t.GetEncodedGeometryType(n)!==e.TRIANGULAR_MESH)throw new Error("Unknown geometry type.");var o=new e.Mesh;if(!t.DecodeBufferToMesh(n,o).ok()||0===o.ptr)throw new Error("Decoding failure.");return o}finally{e.destroy(n)}}function c(t,r){var n=3*r.num_faces(),o=n*Uint32Array.BYTES_PER_ELEMENT,s=e._malloc(o);t.GetTrianglesUInt32Array(r,o,s);var i=new Uint32Array(e.HEAP32.buffer,s,n).slice();return e._free(s),i}function l(n,o,s,i){var a=r[i.componentType],u=t[i.componentType],c=s.num_components(),l=o.num_points()*c,f=l*u.BYTES_PER_ELEMENT,h=e._malloc(f);n.GetAttributeDataArrayForAllPoints(o,s,a,f,h);var p=new u(e.HEAPF32.buffer,h,l).slice();return e._free(h),p}var f,h="KHR_draco_mesh_compression",p=function(s){function i(){var e;return(e=s.apply(this,arguments)||this).extensionName=h,e.provideTypes=[n.PropertyType.PRIMITIVE],e.dependencies=["draco3d.decoder"],e}o(i,s);var f=i.prototype;return f.install=function(n,o){var s,i;return"draco3d.decoder"===n&&(this._decoderModule=o,e=this._decoderModule,(s={})[5126]=Float32Array,s[5125]=Uint32Array,s[5123]=Uint16Array,s[5121]=Uint8Array,s[5122]=Int16Array,s[5120]=Int8Array,t=s,(i={})[5126]=e.DT_FLOAT32,i[5125]=e.DT_UINT32,i[5123]=e.DT_UINT16,i[5121]=e.DT_UINT8,i[5122]=e.DT_INT16,i[5120]=e.DT_INT8,r=i),this},f.provide=function(e){if(!this._decoderModule)throw new Error('Please install extension dependency, "draco3d.decoder".');for(var t,r=this.doc.getLogger(),o=e.jsonDoc,s=new this._decoderModule.Decoder,i=new Map,f=a(o.json.meshes);!(t=f()).done;){for(var p,x=a(t.value.primitives);!(p=x()).done;){var T=p.value;if(T.extensions&&T.extensions[h]){var g=T.extensions[h],d=i.get(g.bufferView);if(!d){var y=o.json.bufferViews[g.bufferView],m=o.json.buffers[y.buffer],_=new Uint8Array(m.uri?o.resources[m.uri]:o.resources[n.GLB_BUFFER],y.byteOffset||0,y.byteLength);d=u(s,_),i.set(g.bufferView,d),r.debug("Decompressed "+_.byteLength+" bytes.")}for(var v in T.attributes){var I=e.jsonDoc.json.accessors[T.attributes[v]],C=s.GetAttributeByUniqueId(d,g.attributes[v]),E=l(s,d,C,I);e.accessors[T.attributes[v]].setArray(E)}var N=c(s,d);e.accessors[T.indices].setArray(N)}}this._decoderModule.destroy(s);for(var R=0,F=Array.from(i.values());R<F.length;R++)this._decoderModule.destroy(F[R])}return this},f.read=function(e){return this.dispose(),this},f.write=function(e){return this.doc.getLogger().warn("Writing "+this.extensionName+" not yet implemented."),this},i}(n.Extension);p.EXTENSION_NAME=h,(f=exports.LightType||(exports.LightType={})).POINT="point",f.SPOT="spot",f.DIRECTIONAL="directional";var x=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).propertyType="Light",t.parentTypes=[n.PropertyType.NODE],t.extensionName="KHR_lights_punctual",t._color=[1,1,1],t._intensity=1,t._range=void 0,t._innerConeAngle=0,t._outerConeAngle=Math.PI/4,t}o(t,e);var r=t.prototype;return r.copy=function(t,r){return void 0===r&&(r=n.COPY_IDENTITY),e.prototype.copy.call(this,t,r),this._color=[].concat(t._color),this._intensity=t._intensity,this._type=t._type,this._range=t._range,this._innerConeAngle=t._innerConeAngle,this._outerConeAngle=t._outerConeAngle,this},r.getColor=function(){return this._color},r.setColor=function(e){return this._color=e,this},r.getColorHex=function(){return n.ColorUtils.factorToHex(this._color)},r.setColorHex=function(e){return n.ColorUtils.hexToFactor(e,this._color),this},r.getIntensity=function(){return this._intensity},r.setIntensity=function(e){return this._intensity=e,this},r.getType=function(){return this._type},r.setType=function(e){return this._type=e,this},r.getRange=function(){return this._range},r.setRange=function(e){return this._range=e,this},r.getInnerConeAngle=function(){return this._innerConeAngle},r.setInnerConeAngle=function(e){return this._innerConeAngle=e,this},r.getOuterConeAngle=function(){return this._outerConeAngle},r.setOuterConeAngle=function(e){return this._outerConeAngle=e,this},t}(n.ExtensionProperty);x.EXTENSION_NAME="KHR_lights_punctual";var T="KHR_lights_punctual",g=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=T,t}o(t,e);var r=t.prototype;return r.createLight=function(){return new x(this.doc.getGraph(),this)},r.read=function(e){var t=this,r=e.jsonDoc;if(!r.json.extensions||!r.json.extensions[T])return this;var n=(r.json.extensions[T].lights||[]).map(function(e){var r=t.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&r.setColor(e.color),void 0!==e.intensity&&r.setIntensity(e.intensity),void 0!==e.range&&r.setRange(e.range),void 0!==e.innerConeAngle&&r.setInnerConeAngle(e.innerConeAngle),void 0!==e.outerConeAngle&&r.setOuterConeAngle(e.outerConeAngle),r});return r.json.nodes.forEach(function(t,r){t.extensions&&t.extensions[T]&&e.nodes[r].setExtension(T,n[t.extensions[T].light])}),this},r.write=function(e){var t=e.jsonDoc;if(0===this.properties.size)return this;for(var r,n=[],o=new Map,s=a(this.properties);!(r=s()).done;){var i=r.value,u={type:i.getType(),color:i.getColor(),intensity:i.getIntensity(),range:i.getRange()};i.getName()&&(u.name=i.getName()),i.getType()===exports.LightType.SPOT&&(u.innerConeAngle=i.getInnerConeAngle(),u.outerConeAngle=i.getOuterConeAngle()),n.push(u),o.set(i,n.length-1)}return this.doc.getRoot().listNodes().forEach(function(r){var n=r.getExtension(T);if(n){var s=e.nodeIndexMap.get(r),i=t.json.nodes[s];i.extensions=i.extensions||{},i.extensions[T]={light:o.get(n)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[T]={lights:n},this},t}(n.Extension);function d(e,t,r,n){var o,s=arguments.length,i=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(i=(s<3?o(i):s>3?o(t,r,i):o(t,r))||i);return s>3&&i&&Object.defineProperty(t,r,i),i}g.EXTENSION_NAME=T;var y=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).propertyType="Clearcoat",t.parentTypes=[n.PropertyType.MATERIAL],t.extensionName="KHR_materials_clearcoat",t._clearcoatFactor=0,t._clearcoatRoughnessFactor=0,t._clearcoatNormalScale=1,t.clearcoatTexture=null,t.clearcoatTextureInfo=t.graph.link("clearcoatTextureInfo",s(t),new n.TextureInfo(t.graph)),t.clearcoatRoughnessTexture=null,t.clearcoatRoughnessTextureInfo=t.graph.link("clearcoatRoughnessTextureInfo",s(t),new n.TextureInfo(t.graph)),t.clearcoatNormalTexture=null,t.clearcoatNormalTextureInfo=t.graph.link("clearcoatNormalTextureInfo",s(t),new n.TextureInfo(t.graph)),t}o(t,e);var r=t.prototype;return r.copy=function(t,r){return void 0===r&&(r=n.COPY_IDENTITY),e.prototype.copy.call(this,t,r),this._clearcoatFactor=t._clearcoatFactor,this._clearcoatRoughnessFactor=t._clearcoatRoughnessFactor,this._clearcoatNormalScale=t._clearcoatNormalScale,t.clearcoatTexture&&(this.setClearcoatTexture(r(t.clearcoatTexture.getChild())),this.getClearcoatTextureInfo().copy(r(t.clearcoatTextureInfo.getChild()))),t.clearcoatRoughnessTexture&&(this.setClearcoatRoughnessTexture(r(t.clearcoatRoughnessTexture.getChild())),this.getClearcoatRoughnessTextureInfo().copy(r(t.clearcoatRoughnessTextureInfo.getChild()))),t.clearcoatNormalTexture&&(this.setClearcoatNormalTexture(r(t.clearcoatNormalTexture.getChild())),this.getClearcoatNormalTextureInfo().copy(r(t.clearcoatNormalTextureInfo.getChild()))),this},r.getClearcoatFactor=function(){return this._clearcoatFactor},r.setClearcoatFactor=function(e){return this._clearcoatFactor=e,this},r.getClearcoatTexture=function(){return this.clearcoatTexture?this.clearcoatTexture.getChild():null},r.getClearcoatTextureInfo=function(){return this.clearcoatTexture?this.clearcoatTextureInfo.getChild():null},r.setClearcoatTexture=function(e){return this.clearcoatTexture=this.graph.link("clearcoatTexture",this,e),this},r.getClearcoatRoughnessFactor=function(){return this._clearcoatRoughnessFactor},r.setClearcoatRoughnessFactor=function(e){return this._clearcoatRoughnessFactor=e,this},r.getClearcoatRoughnessTexture=function(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTexture.getChild():null},r.getClearcoatRoughnessTextureInfo=function(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTextureInfo.getChild():null},r.setClearcoatRoughnessTexture=function(e){return this.clearcoatRoughnessTexture=this.graph.link("clearcoatRoughnessTexture",this,e),this},r.getClearcoatNormalScale=function(){return this._clearcoatNormalScale},r.setClearcoatNormalScale=function(e){return this._clearcoatNormalScale=e,this},r.getClearcoatNormalTexture=function(){return this.clearcoatNormalTexture?this.clearcoatNormalTexture.getChild():null},r.getClearcoatNormalTextureInfo=function(){return this.clearcoatNormalTexture?this.clearcoatNormalTextureInfo.getChild():null},r.setClearcoatNormalTexture=function(e){return this.clearcoatNormalTexture=this.graph.link("clearcoatNormalTexture",this,e),this},t}(n.ExtensionProperty);y.EXTENSION_NAME="KHR_materials_clearcoat",d([n.GraphChild],y.prototype,"clearcoatTexture",void 0),d([n.GraphChild],y.prototype,"clearcoatTextureInfo",void 0),d([n.GraphChild],y.prototype,"clearcoatRoughnessTexture",void 0),d([n.GraphChild],y.prototype,"clearcoatRoughnessTextureInfo",void 0),d([n.GraphChild],y.prototype,"clearcoatNormalTexture",void 0),d([n.GraphChild],y.prototype,"clearcoatNormalTextureInfo",void 0);var m="KHR_materials_clearcoat",_=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=m,t}o(t,e);var r=t.prototype;return r.createClearcoat=function(){return new y(this.doc.getGraph(),this)},r.read=function(e){var t=this,r=e.jsonDoc,n=r.json.textures||[];return(r.json.materials||[]).forEach(function(r,o){if(r.extensions&&r.extensions[m]){var s=t.createClearcoat();if(e.materials[o].setExtension(m,s),void 0!==r.extensions[m].clearcoatFactor&&s.setClearcoatFactor(r.extensions[m].clearcoatFactor),void 0!==r.extensions[m].clearcoatRoughnessFactor&&s.setClearcoatRoughnessFactor(r.extensions[m].clearcoatRoughnessFactor),void 0!==r.extensions[m].clearcoatTexture){var i=r.extensions[m].clearcoatTexture;s.setClearcoatTexture(e.textures[n[i.index].source]),e.setTextureInfo(s.getClearcoatTextureInfo(),i)}if(void 0!==r.extensions[m].clearcoatRoughnessTexture){var a=r.extensions[m].clearcoatRoughnessTexture;s.setClearcoatRoughnessTexture(e.textures[n[a.index].source]),e.setTextureInfo(s.getClearcoatRoughnessTextureInfo(),a)}if(void 0!==r.extensions[m].clearcoatNormalTexture){var u=r.extensions[m].clearcoatNormalTexture;s.setClearcoatNormalTexture(e.textures[n[u.index].source]),e.setTextureInfo(s.getClearcoatNormalTextureInfo(),u),void 0!==u.scale&&s.setClearcoatNormalScale(u.scale)}}}),this},r.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var n=r.getExtension(m);if(n){var o=e.materialIndexMap.get(r),s=t.json.materials[o];if(s.extensions=s.extensions||{},s.extensions[m]={clearcoatFactor:n.getClearcoatFactor(),clearcoatRoughnessFactor:n.getClearcoatRoughnessFactor()},n.getClearcoatTexture()){var i=n.getClearcoatTexture(),a=n.getClearcoatTextureInfo();s.extensions[m].clearcoatTexture=e.createTextureInfoDef(i,a)}if(n.getClearcoatRoughnessTexture()){var u=n.getClearcoatRoughnessTexture(),c=n.getClearcoatRoughnessTextureInfo();s.extensions[m].clearcoatRoughnessTexture=e.createTextureInfoDef(u,c)}if(n.getClearcoatNormalTexture()){var l=n.getClearcoatNormalTexture(),f=n.getClearcoatNormalTextureInfo();s.extensions[m].clearcoatNormalTexture=e.createTextureInfoDef(l,f),1!==n.getClearcoatNormalScale()&&(s.extensions[m].clearcoatNormalTexture.scale=n.getClearcoatNormalScale())}}}),this},t}(n.Extension);_.EXTENSION_NAME=m;var v=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).propertyType="IOR",t.parentTypes=[n.PropertyType.MATERIAL],t.extensionName="KHR_materials_ior",t._ior=0,t}o(t,e);var r=t.prototype;return r.copy=function(t,r){return void 0===r&&(r=n.COPY_IDENTITY),e.prototype.copy.call(this,t,r),this._ior=t._ior,this},r.getIOR=function(){return this._ior},r.setIOR=function(e){return this._ior=e,this},t}(n.ExtensionProperty);v.EXTENSION_NAME="KHR_materials_ior";var I="KHR_materials_ior",C=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=I,t}o(t,e);var r=t.prototype;return r.createIOR=function(){return new v(this.doc.getGraph(),this)},r.read=function(e){var t=this;return(e.jsonDoc.json.materials||[]).forEach(function(r,n){if(r.extensions&&r.extensions[I]){var o=t.createIOR();e.materials[n].setExtension(I,o),void 0!==r.extensions[I].ior&&o.setIOR(r.extensions[I].ior)}}),this},r.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var n=r.getExtension(I);if(n){var o=e.materialIndexMap.get(r),s=t.json.materials[o];s.extensions=s.extensions||{},s.extensions[I]={ior:n.getIOR()}}}),this},t}(n.Extension);C.EXTENSION_NAME=I;var E=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).propertyType="PBRSpecularGlossiness",t.parentTypes=[n.PropertyType.MATERIAL],t.extensionName="KHR_materials_pbrSpecularGlossiness",t._diffuseFactor=[1,1,1,1],t._specularFactor=[1,1,1],t._glossinessFactor=1,t.diffuseTexture=null,t.diffuseTextureInfo=t.graph.link("diffuseTextureInfo",s(t),new n.TextureInfo(t.graph)),t.specularGlossinessTexture=null,t.specularGlossinessTextureInfo=t.graph.link("specularGlossinessTextureInfo",s(t),new n.TextureInfo(t.graph)),t}o(t,e);var r=t.prototype;return r.copy=function(t,r){return void 0===r&&(r=n.COPY_IDENTITY),e.prototype.copy.call(this,t,r),this._diffuseFactor=t._diffuseFactor,this._specularFactor=t._specularFactor,this._glossinessFactor=t._glossinessFactor,t.diffuseTexture&&(this.setDiffuseTexture(r(t.diffuseTexture.getChild())),this.getDiffuseTextureInfo().copy(r(t.diffuseTextureInfo.getChild()))),t.specularGlossinessTexture&&(this.setSpecularGlossinessTexture(r(t.specularGlossinessTexture.getChild())),this.getSpecularGlossinessTextureInfo().copy(r(t.specularGlossinessTextureInfo.getChild()))),this},r.getDiffuseFactor=function(){return this._diffuseFactor},r.setDiffuseFactor=function(e){return this._diffuseFactor=e,this},r.getDiffuseHex=function(){return n.ColorUtils.factorToHex(this._diffuseFactor)},r.setDiffuseHex=function(e){return n.ColorUtils.hexToFactor(e,this._diffuseFactor),this},r.getDiffuseTexture=function(){return this.diffuseTexture?this.diffuseTexture.getChild():null},r.getDiffuseTextureInfo=function(){return this.diffuseTexture?this.diffuseTextureInfo.getChild():null},r.setDiffuseTexture=function(e){return this.diffuseTexture=this.graph.link("diffuseTexture",this,e),this},r.getSpecularFactor=function(){return this._specularFactor},r.setSpecularFactor=function(e){return this._specularFactor=e,this},r.getGlossinessFactor=function(){return this._glossinessFactor},r.setGlossinessFactor=function(e){return this._glossinessFactor=e,this},r.getSpecularGlossinessTexture=function(){return this.specularGlossinessTexture?this.specularGlossinessTexture.getChild():null},r.getSpecularGlossinessTextureInfo=function(){return this.specularGlossinessTexture?this.specularGlossinessTextureInfo.getChild():null},r.setSpecularGlossinessTexture=function(e){return this.specularGlossinessTexture=this.graph.link("specularGlossinessTexture",this,e),this},t}(n.ExtensionProperty);E.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness",d([n.GraphChild],E.prototype,"diffuseTexture",void 0),d([n.GraphChild],E.prototype,"diffuseTextureInfo",void 0),d([n.GraphChild],E.prototype,"specularGlossinessTexture",void 0),d([n.GraphChild],E.prototype,"specularGlossinessTextureInfo",void 0);var N="KHR_materials_pbrSpecularGlossiness",R=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=N,t}o(t,e);var r=t.prototype;return r.createPBRSpecularGlossiness=function(){return new E(this.doc.getGraph(),this)},r.read=function(e){var t=this,r=e.jsonDoc,n=r.json.textures||[];return(r.json.materials||[]).forEach(function(r,o){if(r.extensions&&r.extensions[N]){var s=t.createPBRSpecularGlossiness();if(e.materials[o].setExtension(N,s),void 0!==r.extensions[N].diffuseFactor&&s.setDiffuseFactor(r.extensions[N].diffuseFactor),void 0!==r.extensions[N].specularFactor&&s.setSpecularFactor(r.extensions[N].specularFactor),void 0!==r.extensions[N].glossinessFactor&&s.setGlossinessFactor(r.extensions[N].glossinessFactor),void 0!==r.extensions[N].diffuseTexture){var i=r.extensions[N].diffuseTexture;s.setDiffuseTexture(e.textures[n[i.index].source]),e.setTextureInfo(s.getDiffuseTextureInfo(),i)}if(void 0!==r.extensions[N].specularGlossinessTexture){var a=r.extensions[N].specularGlossinessTexture;s.setSpecularGlossinessTexture(e.textures[n[a.index].source]),e.setTextureInfo(s.getSpecularGlossinessTextureInfo(),a)}}}),this},r.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var n=r.getExtension(N);if(n){var o=e.materialIndexMap.get(r),s=t.json.materials[o];if(s.extensions=s.extensions||{},s.extensions[N]={diffuseFactor:n.getDiffuseFactor(),specularFactor:n.getSpecularFactor(),glossinessFactor:n.getGlossinessFactor()},n.getDiffuseTexture()){var i=n.getDiffuseTexture(),a=n.getDiffuseTextureInfo();s.extensions[N].diffuseTexture=e.createTextureInfoDef(i,a)}if(n.getSpecularGlossinessTexture()){var u=n.getSpecularGlossinessTexture(),c=n.getSpecularGlossinessTextureInfo();s.extensions[N].specularGlossinessTexture=e.createTextureInfoDef(u,c)}}}),this},t}(n.Extension);R.EXTENSION_NAME=N;var F=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).propertyType="Specular",t.parentTypes=[n.PropertyType.MATERIAL],t.extensionName="KHR_materials_specular",t._specularFactor=1,t._specularColorFactor=[1,1,1],t.specularTexture=null,t.specularTextureInfo=t.graph.link("specularTextureInfo",s(t),new n.TextureInfo(t.graph)),t}o(t,e);var r=t.prototype;return r.copy=function(t,r){return void 0===r&&(r=n.COPY_IDENTITY),e.prototype.copy.call(this,t,r),this._specularFactor=t._specularFactor,t.specularTexture&&(this.setSpecularTexture(r(t.specularTexture.getChild())),this.getSpecularTextureInfo().copy(r(t.specularTextureInfo.getChild()))),this},r.getSpecularFactor=function(){return this._specularFactor},r.setSpecularFactor=function(e){return this._specularFactor=e,this},r.getSpecularColorFactor=function(){return this._specularColorFactor},r.setSpecularColorFactor=function(e){return this._specularColorFactor=e,this},r.getSpecularColorHex=function(){return n.ColorUtils.factorToHex(this._specularColorFactor)},r.setSpecularColorHex=function(e){return n.ColorUtils.hexToFactor(e,this._specularColorFactor),this},r.getSpecularTexture=function(){return this.specularTexture?this.specularTexture.getChild():null},r.getSpecularTextureInfo=function(){return this.specularTexture?this.specularTextureInfo.getChild():null},r.setSpecularTexture=function(e){return this.specularTexture=this.graph.link("specularTexture",this,e),this},t}(n.ExtensionProperty);F.EXTENSION_NAME="KHR_materials_specular",d([n.GraphChild],F.prototype,"specularTexture",void 0),d([n.GraphChild],F.prototype,"specularTextureInfo",void 0);var S="KHR_materials_specular",A=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=S,t}o(t,e);var r=t.prototype;return r.createSpecular=function(){return new F(this.doc.getGraph(),this)},r.read=function(e){var t=this,r=e.jsonDoc,n=r.json.textures||[];return(r.json.materials||[]).forEach(function(r,o){if(r.extensions&&r.extensions[S]){var s=t.createSpecular();if(e.materials[o].setExtension(S,s),void 0!==r.extensions[S].specularFactor&&s.setSpecularFactor(r.extensions[S].specularFactor),void 0!==r.extensions[S].specularColorFactor&&s.setSpecularColorFactor(r.extensions[S].specularColorFactor),void 0!==r.extensions[S].specularTexture){var i=r.extensions[S].specularTexture;s.setSpecularTexture(e.textures[n[i.index].source]),e.setTextureInfo(s.getSpecularTextureInfo(),i)}}}),this},r.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var n=r.getExtension(S);if(n){var o=e.materialIndexMap.get(r),s=t.json.materials[o];if(s.extensions=s.extensions||{},s.extensions[S]={specularFactor:n.getSpecularFactor(),specularColorFactor:n.getSpecularColorFactor()},n.getSpecularTexture()){var i=n.getSpecularTexture(),a=n.getSpecularTextureInfo();s.extensions[S].specularTexture=e.createTextureInfoDef(i,a)}}}),this},t}(n.Extension);A.EXTENSION_NAME=S;var G=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).propertyType="Transmission",t.parentTypes=[n.PropertyType.MATERIAL],t.extensionName="KHR_materials_transmission",t._transmissionFactor=0,t.transmissionTexture=null,t.transmissionTextureInfo=t.graph.link("transmissionTextureInfo",s(t),new n.TextureInfo(t.graph)),t}o(t,e);var r=t.prototype;return r.copy=function(t,r){return void 0===r&&(r=n.COPY_IDENTITY),e.prototype.copy.call(this,t,r),this._transmissionFactor=t._transmissionFactor,t.transmissionTexture&&(this.setTransmissionTexture(r(t.transmissionTexture.getChild())),this.getTransmissionTextureInfo().copy(r(t.transmissionTextureInfo.getChild()))),this},r.getTransmissionFactor=function(){return this._transmissionFactor},r.setTransmissionFactor=function(e){return this._transmissionFactor=e,this},r.getTransmissionTexture=function(){return this.transmissionTexture?this.transmissionTexture.getChild():null},r.getTransmissionTextureInfo=function(){return this.transmissionTexture?this.transmissionTextureInfo.getChild():null},r.setTransmissionTexture=function(e){return this.transmissionTexture=this.graph.link("transmissionTexture",this,e),this},t}(n.ExtensionProperty);G.EXTENSION_NAME="KHR_materials_transmission",d([n.GraphChild],G.prototype,"transmissionTexture",void 0),d([n.GraphChild],G.prototype,"transmissionTextureInfo",void 0);var D="KHR_materials_transmission",M=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=D,t}o(t,e);var r=t.prototype;return r.createTransmission=function(){return new G(this.doc.getGraph(),this)},r.read=function(e){var t=this,r=e.jsonDoc,n=r.json.textures||[];return(r.json.materials||[]).forEach(function(r,o){if(r.extensions&&r.extensions[D]){var s=t.createTransmission();if(e.materials[o].setExtension(D,s),void 0!==r.extensions[D].transmissionFactor&&s.setTransmissionFactor(r.extensions[D].transmissionFactor),void 0!==r.extensions[D].transmissionTexture){var i=r.extensions[D].transmissionTexture;s.setTransmissionTexture(e.textures[n[i.index].source]),e.setTextureInfo(s.getTransmissionTextureInfo(),i)}}}),this},r.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){var n=r.getExtension(D);if(n){var o=e.materialIndexMap.get(r),s=t.json.materials[o];if(s.extensions=s.extensions||{},s.extensions[D]={transmissionFactor:n.getTransmissionFactor()},n.getTransmissionTexture()){var i=n.getTransmissionTexture(),a=n.getTransmissionTextureInfo();s.extensions[D].transmissionTexture=e.createTextureInfoDef(i,a)}}}),this},t}(n.Extension);M.EXTENSION_NAME=D;var j=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).propertyType="Unlit",t.parentTypes=[n.PropertyType.MATERIAL],t.extensionName="KHR_materials_unlit",t}return o(t,e),t}(n.ExtensionProperty);j.EXTENSION_NAME="KHR_materials_unlit";var O="KHR_materials_unlit",w=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=O,t}o(t,e);var r=t.prototype;return r.createUnlit=function(){return new j(this.doc.getGraph(),this)},r.read=function(e){var t=this;return(e.jsonDoc.json.materials||[]).forEach(function(r,n){r.extensions&&r.extensions[O]&&e.materials[n].setExtension(O,t.createUnlit())}),this},r.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(function(r){if(r.getExtension(O)){var n=e.materialIndexMap.get(r),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[O]={}}}),this},t}(n.Extension);w.EXTENSION_NAME=O;var b="KHR_mesh_quantization",P=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=b,t}o(t,e);var r=t.prototype;return r.read=function(e){return this},r.write=function(e){return this},t}(n.Extension);P.EXTENSION_NAME=b;var H="KHR_texture_basisu",U=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).extensionName=H,t.provideTypes=[n.PropertyType.TEXTURE],t}o(t,e);var r=t.prototype;return r.provide=function(e){return e.jsonDoc.json.textures.forEach(function(e){e.extensions&&e.extensions[H]&&(e.source=e.extensions[H].source)}),this},r.read=function(e){return this},r.write=function(e){var t=e.jsonDoc;return this.doc.getRoot().listTextures().forEach(function(r){if("image/ktx2"===r.getMimeType()){var n=e.imageIndexMap.get(r);t.json.textures.forEach(function(e){e.source===n&&(e.extensions=e.extensions||{},e.extensions[H]={source:e.source},delete e.source)})}}),this},t}(n.Extension);U.EXTENSION_NAME=H;var K=[p,g,_,C,R,A,M,w,P,U];exports.Clearcoat=y,exports.DracoMeshCompression=p,exports.IOR=v,exports.KHRONOS_EXTENSIONS=K,exports.Light=x,exports.LightsPunctual=g,exports.MaterialsClearcoat=_,exports.MaterialsIOR=C,exports.MaterialsPBRSpecularGlossiness=R,exports.MaterialsSpecular=A,exports.MaterialsTransmission=M,exports.MaterialsUnlit=w,exports.MeshQuantization=P,exports.PBRSpecularGlossiness=E,exports.Specular=F,exports.TextureBasisu=U,exports.Transmission=G,exports.Unlit=j; | ||
//# sourceMappingURL=extensions.js.map |
@@ -1,2 +0,2 @@ | ||
import{Extension as e,PropertyType as t,GLB_BUFFER as s,ExtensionProperty as r,COPY_IDENTITY as o,ColorUtils as n,GraphChild as a}from"@gltf-transform/core";let i;function c(e,t){let s;try{if(s=new i.DecoderBuffer,s.Init(new Int8Array(t),t.byteLength),e.GetEncodedGeometryType(s)!==i.TRIANGULAR_MESH)throw new Error("Unknown geometry type.");const r=new i.Mesh;if(!e.DecodeBufferToMesh(s,r).ok()||0===r.ptr)throw new Error("Decoding failure.");return r}finally{i.destroy(s)}}function u(e,t){const s=t.num_faces(),r=new Uint32Array(3*s),o=new i.DracoInt32Array;for(let n=0;n<s;n++){e.GetFaceFromMesh(t,n,o);for(let e=0;e<3;++e)r[3*n+e]=o.GetValue(e)}return i.destroy(o),r}function l(e,t,s,r){const o=function(e){switch(e){case 5126:return Float32Array;case 5125:return Uint32Array;case 5123:return Uint16Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5120:return Int8Array}}(r.componentType),n=s.num_components(),a=t.num_points()*n;let c,u;switch(o){case Float32Array:c=new i.DracoFloat32Array,e.GetAttributeFloatForAllPoints(t,s,c),u=new Float32Array(a);break;case Int8Array:c=new i.DracoInt8Array,e.GetAttributeInt8ForAllPoints(t,s,c),u=new Int8Array(a);break;case Int16Array:c=new i.DracoInt16Array,e.GetAttributeInt16ForAllPoints(t,s,c),u=new Int16Array(a);break;case Uint8Array:c=new i.DracoUInt8Array,e.GetAttributeUInt8ForAllPoints(t,s,c),u=new Uint8Array(a);break;case Uint16Array:c=new i.DracoUInt16Array,e.GetAttributeUInt16ForAllPoints(t,s,c),u=new Uint16Array(a);break;case Uint32Array:c=new i.DracoUInt32Array,e.GetAttributeUInt32ForAllPoints(t,s,c),u=new Uint32Array(a);break;default:throw new Error("Unexpected attribute type.")}for(let e=0;e<a;e++)u[e]=c.GetValue(e);return i.destroy(c),u}const x="KHR_draco_mesh_compression";class h extends e{constructor(){super(...arguments),this.extensionName=x,this.provideTypes=[t.PRIMITIVE],this.dependencies=["draco3d.decoder"]}install(e,t){return"draco3d.decoder"===e&&(this._decoderModule=t,i=this._decoderModule),this}provide(e){if(!this._decoderModule)throw new Error('Please install extension dependency, "draco3d.decoder".');const t=this.doc.getLogger(),r=e.jsonDoc,o=new this._decoderModule.Decoder,n=new Map;for(const a of r.json.meshes){for(const i of a.primitives){if(!i.extensions||!i.extensions[x])continue;const a=i.extensions[x];let h=n.get(a.bufferView);if(!h){const e=r.json.bufferViews[a.bufferView],i=r.json.buffers[e.buffer],u=new Uint8Array(i.uri?r.resources[i.uri]:r.resources[s],e.byteOffset||0,e.byteLength);h=c(o,u),n.set(a.bufferView,h),t.debug(`Decompressed ${u.byteLength} bytes.`)}for(const t in i.attributes){const s=e.jsonDoc.json.accessors[i.attributes[t]],r=o.GetAttributeByUniqueId(h,a.attributes[t]),n=l(o,h,r,s);e.accessors[i.attributes[t]].setArray(n)}const T=u(o,h);e.accessors[i.indices].setArray(T)}this._decoderModule.destroy(o);for(const e of Array.from(n.values()))this._decoderModule.destroy(e)}return this}read(e){return this.dispose(),this}write(e){return this.doc.getLogger().warn(`Writing ${this.extensionName} not yet implemented.`),this}}var T;h.EXTENSION_NAME=x,function(e){e.POINT="point",e.SPOT="spot",e.DIRECTIONAL="directional"}(T||(T={}));class p extends r{constructor(){super(...arguments),this.propertyType="Light",this.parentTypes=[t.NODE],this.extensionName="KHR_lights_punctual",this._color=[1,1,1],this._intensity=1,this._range=void 0,this._innerConeAngle=0,this._outerConeAngle=Math.PI/4}copy(e,t=o){return super.copy(e,t),this._color=[...e._color],this._intensity=e._intensity,this._type=e._type,this._range=e._range,this._innerConeAngle=e._innerConeAngle,this._outerConeAngle=e._outerConeAngle,this}getColor(){return this._color}setColor(e){return this._color=e,this}getColorHex(){return n.factorToHex(this._color)}setColorHex(e){return n.hexToFactor(e,this._color),this}getIntensity(){return this._intensity}setIntensity(e){return this._intensity=e,this}getType(){return this._type}setType(e){return this._type=e,this}getRange(){return this._range}setRange(e){return this._range=e,this}getInnerConeAngle(){return this._innerConeAngle}setInnerConeAngle(e){return this._innerConeAngle=e,this}getOuterConeAngle(){return this._outerConeAngle}setOuterConeAngle(e){return this._outerConeAngle=e,this}}p.EXTENSION_NAME="KHR_lights_punctual";const g="KHR_lights_punctual";class f extends e{constructor(){super(...arguments),this.extensionName=g}createLight(){return new p(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[g])return this;const s=(t.json.extensions[g].lights||[]).map(e=>{const t=this.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&t.setColor(e.color),void 0!==e.intensity&&t.setIntensity(e.intensity),void 0!==e.range&&t.setRange(e.range),void 0!==e.innerConeAngle&&t.setInnerConeAngle(e.innerConeAngle),void 0!==e.outerConeAngle&&t.setOuterConeAngle(e.outerConeAngle),t});return t.json.nodes.forEach((t,r)=>{t.extensions&&t.extensions[g]&&e.nodes[r].setExtension(g,s[t.extensions[g].light])}),this}write(e){const t=e.jsonDoc;if(0===this.properties.size)return this;const s=[],r=new Map;for(const e of this.properties){const t=e,o={type:t.getType(),color:t.getColor(),intensity:t.getIntensity(),range:t.getRange()};t.getName()&&(o.name=t.getName()),t.getType()===T.SPOT&&(o.innerConeAngle=t.getInnerConeAngle(),o.outerConeAngle=t.getOuterConeAngle()),s.push(o),r.set(t,s.length-1)}return this.doc.getRoot().listNodes().forEach(s=>{const o=s.getExtension(g);if(o){const n=e.nodeIndexMap.get(s),a=t.json.nodes[n];a.extensions=a.extensions||{},a.extensions[g]={light:r.get(o)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[g]={lights:s},this}}function m(e,t,s,r){var o,n=arguments.length,a=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,s,r);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(a=(n<3?o(a):n>3?o(t,s,a):o(t,s))||a);return n>3&&a&&Object.defineProperty(t,s,a),a}f.EXTENSION_NAME=g;class d extends r{constructor(){super(...arguments),this.propertyType="Clearcoat",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_clearcoat",this._clearcoatFactor=0,this._clearcoatRoughnessFactor=0,this._clearcoatNormalScale=1,this.clearcoatTexture=null,this.clearcoatRoughnessTexture=null,this.clearcoatNormalTexture=null}copy(e,t=o){return super.copy(e,t),this._clearcoatFactor=e._clearcoatFactor,this._clearcoatRoughnessFactor=e._clearcoatRoughnessFactor,this._clearcoatNormalScale=e._clearcoatNormalScale,e.clearcoatTexture&&(this.setClearcoatTexture(t(e.clearcoatTexture.getChild())),this.clearcoatTexture.copy(e.clearcoatTexture)),e.clearcoatRoughnessTexture&&(this.setClearcoatRoughnessTexture(t(e.clearcoatRoughnessTexture.getChild())),this.clearcoatRoughnessTexture.copy(e.clearcoatRoughnessTexture)),e.clearcoatNormalTexture&&(this.setClearcoatNormalTexture(t(e.clearcoatNormalTexture.getChild())),this.clearcoatNormalTexture.copy(e.clearcoatNormalTexture)),this}getClearcoatFactor(){return this._clearcoatFactor}setClearcoatFactor(e){return this._clearcoatFactor=e,this}getClearcoatTexture(){return this.clearcoatTexture?this.clearcoatTexture.getChild():null}getClearcoatTextureInfo(){return this.clearcoatTexture?this.clearcoatTexture.textureInfo:null}getClearcoatTextureSampler(){return this.clearcoatTexture?this.clearcoatTexture.sampler:null}setClearcoatTexture(e){return this.clearcoatTexture=this.graph.linkTexture("clearcoatTexture",this,e),this}getClearcoatRoughnessFactor(){return this._clearcoatRoughnessFactor}setClearcoatRoughnessFactor(e){return this._clearcoatRoughnessFactor=e,this}getClearcoatRoughnessTexture(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTexture.getChild():null}getClearcoatRoughnessTextureInfo(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTexture.textureInfo:null}getClearcoatRoughnessTextureSampler(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTexture.sampler:null}setClearcoatRoughnessTexture(e){return this.clearcoatRoughnessTexture=this.graph.linkTexture("clearcoatRoughnessTexture",this,e),this}getClearcoatNormalScale(){return this._clearcoatNormalScale}setClearcoatNormalScale(e){return this._clearcoatNormalScale=e,this}getClearcoatNormalTexture(){return this.clearcoatNormalTexture?this.clearcoatNormalTexture.getChild():null}getClearcoatNormalTextureInfo(){return this.clearcoatNormalTexture?this.clearcoatNormalTexture.textureInfo:null}getClearcoatNormalTextureSampler(){return this.clearcoatNormalTexture?this.clearcoatNormalTexture.sampler:null}setClearcoatNormalTexture(e){return this.clearcoatNormalTexture=this.graph.linkTexture("clearcoatNormalTexture",this,e),this}}d.EXTENSION_NAME="KHR_materials_clearcoat",m([a],d.prototype,"clearcoatTexture",void 0),m([a],d.prototype,"clearcoatRoughnessTexture",void 0),m([a],d.prototype,"clearcoatNormalTexture",void 0);const _="KHR_materials_clearcoat";class y extends e{constructor(){super(...arguments),this.extensionName=_}createClearcoat(){return new d(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[_]){const o=this.createClearcoat();if(e.materials[r].setExtension(_,o),void 0!==t.extensions[_].clearcoatFactor&&o.setClearcoatFactor(t.extensions[_].clearcoatFactor),void 0!==t.extensions[_].clearcoatRoughnessFactor&&o.setClearcoatRoughnessFactor(t.extensions[_].clearcoatRoughnessFactor),void 0!==t.extensions[_].clearcoatTexture){const r=t.extensions[_].clearcoatTexture;o.setClearcoatTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getClearcoatTextureInfo(),r),e.setTextureSampler(o.getClearcoatTextureSampler(),r)}if(void 0!==t.extensions[_].clearcoatRoughnessTexture){const r=t.extensions[_].clearcoatRoughnessTexture;o.setClearcoatRoughnessTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getClearcoatRoughnessTextureInfo(),r),e.setTextureSampler(o.getClearcoatRoughnessTextureSampler(),r)}if(void 0!==t.extensions[_].clearcoatNormalTexture){const r=t.extensions[_].clearcoatNormalTexture;o.setClearcoatNormalTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getClearcoatNormalTextureInfo(),r),e.setTextureSampler(o.getClearcoatNormalTextureSampler(),r),void 0!==r.scale&&o.setClearcoatNormalScale(r.scale)}}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(_);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];if(n.extensions=n.extensions||{},n.extensions[_]={clearcoatFactor:r.getClearcoatFactor(),clearcoatRoughnessFactor:r.getClearcoatRoughnessFactor()},r.getClearcoatTexture()){const t=r.getClearcoatTexture(),s=r.getClearcoatTextureInfo(),o=r.getClearcoatTextureSampler();n.extensions[_].clearcoatTexture=e.createTextureInfoDef(t,s,o)}if(r.getClearcoatRoughnessTexture()){const t=r.getClearcoatRoughnessTexture(),s=r.getClearcoatRoughnessTextureInfo(),o=r.getClearcoatRoughnessTextureSampler();n.extensions[_].clearcoatRoughnessTexture=e.createTextureInfoDef(t,s,o)}if(r.getClearcoatNormalTexture()){const t=r.getClearcoatNormalTexture(),s=r.getClearcoatNormalTextureInfo(),o=r.getClearcoatNormalTextureSampler();n.extensions[_].clearcoatNormalTexture=e.createTextureInfoDef(t,s,o),1!==r.getClearcoatNormalScale()&&(n.extensions[_].clearcoatNormalTexture.scale=r.getClearcoatNormalScale())}}}),this}}y.EXTENSION_NAME=_;class N extends r{constructor(){super(...arguments),this.propertyType="IOR",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_ior",this._ior=0}copy(e,t=o){return super.copy(e,t),this._ior=e._ior,this}getIOR(){return this._ior}setIOR(e){return this._ior=e,this}}N.EXTENSION_NAME="KHR_materials_ior";const I="KHR_materials_ior";class F extends e{constructor(){super(...arguments),this.extensionName=I}createIOR(){return new N(this.doc.getGraph(),this)}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[I]){const r=this.createIOR();e.materials[s].setExtension(I,r),void 0!==t.extensions[I].ior&&r.setIOR(t.extensions[I].ior)}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(I);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];n.extensions=n.extensions||{},n.extensions[I]={ior:r.getIOR()}}}),this}}F.EXTENSION_NAME=I;class C extends r{constructor(){super(...arguments),this.propertyType="PBRSpecularGlossiness",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_pbrSpecularGlossiness",this._diffuseFactor=[1,1,1,1],this._specularFactor=[1,1,1],this._glossinessFactor=1,this.diffuseTexture=null,this.specularGlossinessTexture=null}copy(e,t=o){return super.copy(e,t),this._diffuseFactor=e._diffuseFactor,this._specularFactor=e._specularFactor,this._glossinessFactor=e._glossinessFactor,e.diffuseTexture&&(this.setDiffuseTexture(t(e.diffuseTexture.getChild())),this.diffuseTexture.copy(e.diffuseTexture)),e.specularGlossinessTexture&&(this.setSpecularGlossinessTexture(t(e.specularGlossinessTexture.getChild())),this.specularGlossinessTexture.copy(e.specularGlossinessTexture)),this}getDiffuseFactor(){return this._diffuseFactor}setDiffuseFactor(e){return this._diffuseFactor=e,this}getDiffuseHex(){return n.factorToHex(this._diffuseFactor)}setDiffuseHex(e){return n.hexToFactor(e,this._diffuseFactor),this}getDiffuseTexture(){return this.diffuseTexture?this.diffuseTexture.getChild():null}getDiffuseTextureInfo(){return this.diffuseTexture?this.diffuseTexture.textureInfo:null}getDiffuseTextureSampler(){return this.diffuseTexture?this.diffuseTexture.sampler:null}setDiffuseTexture(e){return this.diffuseTexture=this.graph.linkTexture("diffuseTexture",this,e),this}getSpecularFactor(){return this._specularFactor}setSpecularFactor(e){return this._specularFactor=e,this}getGlossinessFactor(){return this._glossinessFactor}setGlossinessFactor(e){return this._glossinessFactor=e,this}getSpecularGlossinessTexture(){return this.specularGlossinessTexture?this.specularGlossinessTexture.getChild():null}getSpecularGlossinessTextureInfo(){return this.specularGlossinessTexture?this.specularGlossinessTexture.textureInfo:null}getSpecularGlossinessTextureSampler(){return this.specularGlossinessTexture?this.specularGlossinessTexture.sampler:null}setSpecularGlossinessTexture(e){return this.specularGlossinessTexture=this.graph.linkTexture("specularGlossinessTexture",this,e),this}}C.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness",m([a],C.prototype,"diffuseTexture",void 0),m([a],C.prototype,"specularGlossinessTexture",void 0);const S="KHR_materials_pbrSpecularGlossiness";class R extends e{constructor(){super(...arguments),this.extensionName=S}createPBRSpecularGlossiness(){return new C(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[S]){const o=this.createPBRSpecularGlossiness();if(e.materials[r].setExtension(S,o),void 0!==t.extensions[S].diffuseFactor&&o.setDiffuseFactor(t.extensions[S].diffuseFactor),void 0!==t.extensions[S].specularFactor&&o.setSpecularFactor(t.extensions[S].specularFactor),void 0!==t.extensions[S].glossinessFactor&&o.setGlossinessFactor(t.extensions[S].glossinessFactor),void 0!==t.extensions[S].diffuseTexture){const r=t.extensions[S].diffuseTexture;o.setDiffuseTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getDiffuseTextureInfo(),r),e.setTextureSampler(o.getDiffuseTextureSampler(),r)}if(void 0!==t.extensions[S].specularGlossinessTexture){const r=t.extensions[S].specularGlossinessTexture;o.setSpecularGlossinessTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getSpecularGlossinessTextureInfo(),r),e.setTextureSampler(o.getSpecularGlossinessTextureSampler(),r)}}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(S);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];if(n.extensions=n.extensions||{},n.extensions[S]={diffuseFactor:r.getDiffuseFactor(),specularFactor:r.getSpecularFactor(),glossinessFactor:r.getGlossinessFactor()},r.getDiffuseTexture()){const t=r.getDiffuseTexture(),s=r.getDiffuseTextureInfo(),o=r.getDiffuseTextureSampler();n.extensions[S].diffuseTexture=e.createTextureInfoDef(t,s,o)}if(r.getSpecularGlossinessTexture()){const t=r.getSpecularGlossinessTexture(),s=r.getSpecularGlossinessTextureInfo(),o=r.getSpecularGlossinessTextureSampler();n.extensions[S].specularGlossinessTexture=e.createTextureInfoDef(t,s,o)}}}),this}}R.EXTENSION_NAME=S;class A extends r{constructor(){super(...arguments),this.propertyType="Specular",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_specular",this._specularFactor=1,this._specularColorFactor=[1,1,1],this.specularTexture=null}copy(e,t=o){return super.copy(e,t),this._specularFactor=e._specularFactor,e.specularTexture&&(this.setSpecularTexture(t(e.specularTexture.getChild())),this.specularTexture.copy(e.specularTexture)),this}getSpecularFactor(){return this._specularFactor}setSpecularFactor(e){return this._specularFactor=e,this}getSpecularColorFactor(){return this._specularColorFactor}setSpecularColorFactor(e){return this._specularColorFactor=e,this}getSpecularColorHex(){return n.factorToHex(this._specularColorFactor)}setSpecularColorHex(e){return n.hexToFactor(e,this._specularColorFactor),this}getSpecularTexture(){return this.specularTexture?this.specularTexture.getChild():null}getSpecularTextureInfo(){return this.specularTexture?this.specularTexture.textureInfo:null}getSpecularTextureSampler(){return this.specularTexture?this.specularTexture.sampler:null}setSpecularTexture(e){return this.specularTexture=this.graph.linkTexture("specularTexture",this,e),this}}A.EXTENSION_NAME="KHR_materials_specular",m([a],A.prototype,"specularTexture",void 0);const E="KHR_materials_specular";class G extends e{constructor(){super(...arguments),this.extensionName=E}createSpecular(){return new A(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[E]){const o=this.createSpecular();if(e.materials[r].setExtension(E,o),void 0!==t.extensions[E].specularFactor&&o.setSpecularFactor(t.extensions[E].specularFactor),void 0!==t.extensions[E].specularColorFactor&&o.setSpecularColorFactor(t.extensions[E].specularColorFactor),void 0!==t.extensions[E].specularTexture){const r=t.extensions[E].specularTexture;o.setSpecularTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getSpecularTextureInfo(),r),e.setTextureSampler(o.getSpecularTextureSampler(),r)}}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(E);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];if(n.extensions=n.extensions||{},n.extensions[E]={specularFactor:r.getSpecularFactor(),specularColorFactor:r.getSpecularColorFactor()},r.getSpecularTexture()){const t=r.getSpecularTexture(),s=r.getSpecularTextureInfo(),o=r.getSpecularTextureSampler();n.extensions[E].specularTexture=e.createTextureInfoDef(t,s,o)}}}),this}}G.EXTENSION_NAME=E;class D extends r{constructor(){super(...arguments),this.propertyType="Transmission",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_transmission",this._transmissionFactor=0,this.transmissionTexture=null}copy(e,t=o){return super.copy(e,t),this._transmissionFactor=e._transmissionFactor,e.transmissionTexture&&(this.setTransmissionTexture(t(e.transmissionTexture.getChild())),this.transmissionTexture.copy(e.transmissionTexture)),this}getTransmissionFactor(){return this._transmissionFactor}setTransmissionFactor(e){return this._transmissionFactor=e,this}getTransmissionTexture(){return this.transmissionTexture?this.transmissionTexture.getChild():null}getTransmissionTextureInfo(){return this.transmissionTexture?this.transmissionTexture.textureInfo:null}getTransmissionTextureSampler(){return this.transmissionTexture?this.transmissionTexture.sampler:null}setTransmissionTexture(e){return this.transmissionTexture=this.graph.linkTexture("transmissionTexture",this,e),this}}D.EXTENSION_NAME="KHR_materials_transmission",m([a],D.prototype,"transmissionTexture",void 0);const w="KHR_materials_transmission";class M extends e{constructor(){super(...arguments),this.extensionName=w}createTransmission(){return new D(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[w]){const o=this.createTransmission();if(e.materials[r].setExtension(w,o),void 0!==t.extensions[w].transmissionFactor&&o.setTransmissionFactor(t.extensions[w].transmissionFactor),void 0!==t.extensions[w].transmissionTexture){const r=t.extensions[w].transmissionTexture;o.setTransmissionTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getTransmissionTextureInfo(),r),e.setTextureSampler(o.getTransmissionTextureSampler(),r)}}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(w);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];if(n.extensions=n.extensions||{},n.extensions[w]={transmissionFactor:r.getTransmissionFactor()},r.getTransmissionTexture()){const t=r.getTransmissionTexture(),s=r.getTransmissionTextureInfo(),o=r.getTransmissionTextureSampler();n.extensions[w].transmissionTexture=e.createTextureInfoDef(t,s,o)}}}),this}}M.EXTENSION_NAME=w;class j extends r{constructor(){super(...arguments),this.propertyType="Unlit",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_unlit"}}j.EXTENSION_NAME="KHR_materials_unlit";const v="KHR_materials_unlit";class b extends e{constructor(){super(...arguments),this.extensionName=v}createUnlit(){return new j(this.doc.getGraph(),this)}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[v]&&e.materials[s].setExtension(v,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{if(s.getExtension(v)){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{},o.extensions[v]={}}}),this}}b.EXTENSION_NAME=v;const O="KHR_mesh_quantization";class H extends e{constructor(){super(...arguments),this.extensionName=O}read(e){return this}write(e){return this}}H.EXTENSION_NAME=O;const U="KHR_texture_basisu";class K extends e{constructor(){super(...arguments),this.extensionName=U,this.provideTypes=[t.TEXTURE]}provide(e){return e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[U]&&(e.source=e.extensions[U].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listTextures().forEach(s=>{if("image/ktx2"===s.getMimeType()){const r=e.imageIndexMap.get(s);t.json.textures.forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[U]={source:e.source},delete e.source)})}}),this}}K.EXTENSION_NAME=U;const X=[h,f,y,F,R,G,M,b,H,K];export{d as Clearcoat,h as DracoMeshCompression,N as IOR,X as KHRONOS_EXTENSIONS,p as Light,T as LightType,f as LightsPunctual,y as MaterialsClearcoat,F as MaterialsIOR,R as MaterialsPBRSpecularGlossiness,G as MaterialsSpecular,M as MaterialsTransmission,b as MaterialsUnlit,H as MeshQuantization,C as PBRSpecularGlossiness,A as Specular,K as TextureBasisu,D as Transmission,j as Unlit}; | ||
import{Extension as e,PropertyType as t,GLB_BUFFER as s,ExtensionProperty as r,COPY_IDENTITY as o,ColorUtils as n,TextureInfo as i,GraphChild as a}from"@gltf-transform/core";let c,u,l;function h(e,t){let s;try{if(s=new c.DecoderBuffer,s.Init(new Int8Array(t),t.byteLength),e.GetEncodedGeometryType(s)!==c.TRIANGULAR_MESH)throw new Error("Unknown geometry type.");const r=new c.Mesh;if(!e.DecodeBufferToMesh(s,r).ok()||0===r.ptr)throw new Error("Decoding failure.");return r}finally{c.destroy(s)}}function x(e,t){const s=3*t.num_faces(),r=s*Uint32Array.BYTES_PER_ELEMENT,o=c._malloc(r);e.GetTrianglesUInt32Array(t,r,o);const n=new Uint32Array(c.HEAP32.buffer,o,s).slice();return c._free(o),n}function p(e,t,s,r){const o=l[r.componentType],n=u[r.componentType],i=s.num_components(),a=t.num_points()*i,h=a*n.BYTES_PER_ELEMENT,x=c._malloc(h);e.GetAttributeDataArrayForAllPoints(t,s,o,h,x);const p=new n(c.HEAPF32.buffer,x,a).slice();return c._free(x),p}const T="KHR_draco_mesh_compression";class g extends e{constructor(){super(...arguments),this.extensionName=T,this.provideTypes=[t.PRIMITIVE],this.dependencies=["draco3d.decoder"]}install(e,t){return"draco3d.decoder"===e&&(this._decoderModule=t,c=this._decoderModule,u={5126:Float32Array,5125:Uint32Array,5123:Uint16Array,5121:Uint8Array,5122:Int16Array,5120:Int8Array},l={5126:c.DT_FLOAT32,5125:c.DT_UINT32,5123:c.DT_UINT16,5121:c.DT_UINT8,5122:c.DT_INT16,5120:c.DT_INT8}),this}provide(e){if(!this._decoderModule)throw new Error('Please install extension dependency, "draco3d.decoder".');const t=this.doc.getLogger(),r=e.jsonDoc,o=new this._decoderModule.Decoder,n=new Map;for(const i of r.json.meshes){for(const a of i.primitives){if(!a.extensions||!a.extensions[T])continue;const i=a.extensions[T];let c=n.get(i.bufferView);if(!c){const e=r.json.bufferViews[i.bufferView],a=r.json.buffers[e.buffer],u=new Uint8Array(a.uri?r.resources[a.uri]:r.resources[s],e.byteOffset||0,e.byteLength);c=h(o,u),n.set(i.bufferView,c),t.debug(`Decompressed ${u.byteLength} bytes.`)}for(const t in a.attributes){const s=e.jsonDoc.json.accessors[a.attributes[t]],r=o.GetAttributeByUniqueId(c,i.attributes[t]),n=p(o,c,r,s);e.accessors[a.attributes[t]].setArray(n)}const u=x(o,c);e.accessors[a.indices].setArray(u)}this._decoderModule.destroy(o);for(const e of Array.from(n.values()))this._decoderModule.destroy(e)}return this}read(e){return this.dispose(),this}write(e){return this.doc.getLogger().warn(`Writing ${this.extensionName} not yet implemented.`),this}}var f;g.EXTENSION_NAME=T,function(e){e.POINT="point",e.SPOT="spot",e.DIRECTIONAL="directional"}(f||(f={}));class d extends r{constructor(){super(...arguments),this.propertyType="Light",this.parentTypes=[t.NODE],this.extensionName="KHR_lights_punctual",this._color=[1,1,1],this._intensity=1,this._range=void 0,this._innerConeAngle=0,this._outerConeAngle=Math.PI/4}copy(e,t=o){return super.copy(e,t),this._color=[...e._color],this._intensity=e._intensity,this._type=e._type,this._range=e._range,this._innerConeAngle=e._innerConeAngle,this._outerConeAngle=e._outerConeAngle,this}getColor(){return this._color}setColor(e){return this._color=e,this}getColorHex(){return n.factorToHex(this._color)}setColorHex(e){return n.hexToFactor(e,this._color),this}getIntensity(){return this._intensity}setIntensity(e){return this._intensity=e,this}getType(){return this._type}setType(e){return this._type=e,this}getRange(){return this._range}setRange(e){return this._range=e,this}getInnerConeAngle(){return this._innerConeAngle}setInnerConeAngle(e){return this._innerConeAngle=e,this}getOuterConeAngle(){return this._outerConeAngle}setOuterConeAngle(e){return this._outerConeAngle=e,this}}d.EXTENSION_NAME="KHR_lights_punctual";const m="KHR_lights_punctual";class _ extends e{constructor(){super(...arguments),this.extensionName=m}createLight(){return new d(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[m])return this;const s=(t.json.extensions[m].lights||[]).map(e=>{const t=this.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&t.setColor(e.color),void 0!==e.intensity&&t.setIntensity(e.intensity),void 0!==e.range&&t.setRange(e.range),void 0!==e.innerConeAngle&&t.setInnerConeAngle(e.innerConeAngle),void 0!==e.outerConeAngle&&t.setOuterConeAngle(e.outerConeAngle),t});return t.json.nodes.forEach((t,r)=>{t.extensions&&t.extensions[m]&&e.nodes[r].setExtension(m,s[t.extensions[m].light])}),this}write(e){const t=e.jsonDoc;if(0===this.properties.size)return this;const s=[],r=new Map;for(const e of this.properties){const t=e,o={type:t.getType(),color:t.getColor(),intensity:t.getIntensity(),range:t.getRange()};t.getName()&&(o.name=t.getName()),t.getType()===f.SPOT&&(o.innerConeAngle=t.getInnerConeAngle(),o.outerConeAngle=t.getOuterConeAngle()),s.push(o),r.set(t,s.length-1)}return this.doc.getRoot().listNodes().forEach(s=>{const o=s.getExtension(m);if(o){const n=e.nodeIndexMap.get(s),i=t.json.nodes[n];i.extensions=i.extensions||{},i.extensions[m]={light:r.get(o)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[m]={lights:s},this}}function I(e,t,s,r){var o,n=arguments.length,i=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,s,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(i=(n<3?o(i):n>3?o(t,s,i):o(t,s))||i);return n>3&&i&&Object.defineProperty(t,s,i),i}_.EXTENSION_NAME=m;class N extends r{constructor(){super(...arguments),this.propertyType="Clearcoat",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_clearcoat",this._clearcoatFactor=0,this._clearcoatRoughnessFactor=0,this._clearcoatNormalScale=1,this.clearcoatTexture=null,this.clearcoatTextureInfo=this.graph.link("clearcoatTextureInfo",this,new i(this.graph)),this.clearcoatRoughnessTexture=null,this.clearcoatRoughnessTextureInfo=this.graph.link("clearcoatRoughnessTextureInfo",this,new i(this.graph)),this.clearcoatNormalTexture=null,this.clearcoatNormalTextureInfo=this.graph.link("clearcoatNormalTextureInfo",this,new i(this.graph))}copy(e,t=o){return super.copy(e,t),this._clearcoatFactor=e._clearcoatFactor,this._clearcoatRoughnessFactor=e._clearcoatRoughnessFactor,this._clearcoatNormalScale=e._clearcoatNormalScale,e.clearcoatTexture&&(this.setClearcoatTexture(t(e.clearcoatTexture.getChild())),this.getClearcoatTextureInfo().copy(t(e.clearcoatTextureInfo.getChild()))),e.clearcoatRoughnessTexture&&(this.setClearcoatRoughnessTexture(t(e.clearcoatRoughnessTexture.getChild())),this.getClearcoatRoughnessTextureInfo().copy(t(e.clearcoatRoughnessTextureInfo.getChild()))),e.clearcoatNormalTexture&&(this.setClearcoatNormalTexture(t(e.clearcoatNormalTexture.getChild())),this.getClearcoatNormalTextureInfo().copy(t(e.clearcoatNormalTextureInfo.getChild()))),this}getClearcoatFactor(){return this._clearcoatFactor}setClearcoatFactor(e){return this._clearcoatFactor=e,this}getClearcoatTexture(){return this.clearcoatTexture?this.clearcoatTexture.getChild():null}getClearcoatTextureInfo(){return this.clearcoatTexture?this.clearcoatTextureInfo.getChild():null}setClearcoatTexture(e){return this.clearcoatTexture=this.graph.link("clearcoatTexture",this,e),this}getClearcoatRoughnessFactor(){return this._clearcoatRoughnessFactor}setClearcoatRoughnessFactor(e){return this._clearcoatRoughnessFactor=e,this}getClearcoatRoughnessTexture(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTexture.getChild():null}getClearcoatRoughnessTextureInfo(){return this.clearcoatRoughnessTexture?this.clearcoatRoughnessTextureInfo.getChild():null}setClearcoatRoughnessTexture(e){return this.clearcoatRoughnessTexture=this.graph.link("clearcoatRoughnessTexture",this,e),this}getClearcoatNormalScale(){return this._clearcoatNormalScale}setClearcoatNormalScale(e){return this._clearcoatNormalScale=e,this}getClearcoatNormalTexture(){return this.clearcoatNormalTexture?this.clearcoatNormalTexture.getChild():null}getClearcoatNormalTextureInfo(){return this.clearcoatNormalTexture?this.clearcoatNormalTextureInfo.getChild():null}setClearcoatNormalTexture(e){return this.clearcoatNormalTexture=this.graph.link("clearcoatNormalTexture",this,e),this}}N.EXTENSION_NAME="KHR_materials_clearcoat",I([a],N.prototype,"clearcoatTexture",void 0),I([a],N.prototype,"clearcoatTextureInfo",void 0),I([a],N.prototype,"clearcoatRoughnessTexture",void 0),I([a],N.prototype,"clearcoatRoughnessTextureInfo",void 0),I([a],N.prototype,"clearcoatNormalTexture",void 0),I([a],N.prototype,"clearcoatNormalTextureInfo",void 0);const C="KHR_materials_clearcoat";class y extends e{constructor(){super(...arguments),this.extensionName=C}createClearcoat(){return new N(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[C]){const o=this.createClearcoat();if(e.materials[r].setExtension(C,o),void 0!==t.extensions[C].clearcoatFactor&&o.setClearcoatFactor(t.extensions[C].clearcoatFactor),void 0!==t.extensions[C].clearcoatRoughnessFactor&&o.setClearcoatRoughnessFactor(t.extensions[C].clearcoatRoughnessFactor),void 0!==t.extensions[C].clearcoatTexture){const r=t.extensions[C].clearcoatTexture;o.setClearcoatTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getClearcoatTextureInfo(),r)}if(void 0!==t.extensions[C].clearcoatRoughnessTexture){const r=t.extensions[C].clearcoatRoughnessTexture;o.setClearcoatRoughnessTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getClearcoatRoughnessTextureInfo(),r)}if(void 0!==t.extensions[C].clearcoatNormalTexture){const r=t.extensions[C].clearcoatNormalTexture;o.setClearcoatNormalTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getClearcoatNormalTextureInfo(),r),void 0!==r.scale&&o.setClearcoatNormalScale(r.scale)}}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(C);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];if(n.extensions=n.extensions||{},n.extensions[C]={clearcoatFactor:r.getClearcoatFactor(),clearcoatRoughnessFactor:r.getClearcoatRoughnessFactor()},r.getClearcoatTexture()){const t=r.getClearcoatTexture(),s=r.getClearcoatTextureInfo();n.extensions[C].clearcoatTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatRoughnessTexture()){const t=r.getClearcoatRoughnessTexture(),s=r.getClearcoatRoughnessTextureInfo();n.extensions[C].clearcoatRoughnessTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatNormalTexture()){const t=r.getClearcoatNormalTexture(),s=r.getClearcoatNormalTextureInfo();n.extensions[C].clearcoatNormalTexture=e.createTextureInfoDef(t,s),1!==r.getClearcoatNormalScale()&&(n.extensions[C].clearcoatNormalTexture.scale=r.getClearcoatNormalScale())}}}),this}}y.EXTENSION_NAME=C;class E extends r{constructor(){super(...arguments),this.propertyType="IOR",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_ior",this._ior=0}copy(e,t=o){return super.copy(e,t),this._ior=e._ior,this}getIOR(){return this._ior}setIOR(e){return this._ior=e,this}}E.EXTENSION_NAME="KHR_materials_ior";const F="KHR_materials_ior";class R extends e{constructor(){super(...arguments),this.extensionName=F}createIOR(){return new E(this.doc.getGraph(),this)}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[F]){const r=this.createIOR();e.materials[s].setExtension(F,r),void 0!==t.extensions[F].ior&&r.setIOR(t.extensions[F].ior)}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(F);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];n.extensions=n.extensions||{},n.extensions[F]={ior:r.getIOR()}}}),this}}R.EXTENSION_NAME=F;class A extends r{constructor(){super(...arguments),this.propertyType="PBRSpecularGlossiness",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_pbrSpecularGlossiness",this._diffuseFactor=[1,1,1,1],this._specularFactor=[1,1,1],this._glossinessFactor=1,this.diffuseTexture=null,this.diffuseTextureInfo=this.graph.link("diffuseTextureInfo",this,new i(this.graph)),this.specularGlossinessTexture=null,this.specularGlossinessTextureInfo=this.graph.link("specularGlossinessTextureInfo",this,new i(this.graph))}copy(e,t=o){return super.copy(e,t),this._diffuseFactor=e._diffuseFactor,this._specularFactor=e._specularFactor,this._glossinessFactor=e._glossinessFactor,e.diffuseTexture&&(this.setDiffuseTexture(t(e.diffuseTexture.getChild())),this.getDiffuseTextureInfo().copy(t(e.diffuseTextureInfo.getChild()))),e.specularGlossinessTexture&&(this.setSpecularGlossinessTexture(t(e.specularGlossinessTexture.getChild())),this.getSpecularGlossinessTextureInfo().copy(t(e.specularGlossinessTextureInfo.getChild()))),this}getDiffuseFactor(){return this._diffuseFactor}setDiffuseFactor(e){return this._diffuseFactor=e,this}getDiffuseHex(){return n.factorToHex(this._diffuseFactor)}setDiffuseHex(e){return n.hexToFactor(e,this._diffuseFactor),this}getDiffuseTexture(){return this.diffuseTexture?this.diffuseTexture.getChild():null}getDiffuseTextureInfo(){return this.diffuseTexture?this.diffuseTextureInfo.getChild():null}setDiffuseTexture(e){return this.diffuseTexture=this.graph.link("diffuseTexture",this,e),this}getSpecularFactor(){return this._specularFactor}setSpecularFactor(e){return this._specularFactor=e,this}getGlossinessFactor(){return this._glossinessFactor}setGlossinessFactor(e){return this._glossinessFactor=e,this}getSpecularGlossinessTexture(){return this.specularGlossinessTexture?this.specularGlossinessTexture.getChild():null}getSpecularGlossinessTextureInfo(){return this.specularGlossinessTexture?this.specularGlossinessTextureInfo.getChild():null}setSpecularGlossinessTexture(e){return this.specularGlossinessTexture=this.graph.link("specularGlossinessTexture",this,e),this}}A.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness",I([a],A.prototype,"diffuseTexture",void 0),I([a],A.prototype,"diffuseTextureInfo",void 0),I([a],A.prototype,"specularGlossinessTexture",void 0),I([a],A.prototype,"specularGlossinessTextureInfo",void 0);const S="KHR_materials_pbrSpecularGlossiness";class D extends e{constructor(){super(...arguments),this.extensionName=S}createPBRSpecularGlossiness(){return new A(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[S]){const o=this.createPBRSpecularGlossiness();if(e.materials[r].setExtension(S,o),void 0!==t.extensions[S].diffuseFactor&&o.setDiffuseFactor(t.extensions[S].diffuseFactor),void 0!==t.extensions[S].specularFactor&&o.setSpecularFactor(t.extensions[S].specularFactor),void 0!==t.extensions[S].glossinessFactor&&o.setGlossinessFactor(t.extensions[S].glossinessFactor),void 0!==t.extensions[S].diffuseTexture){const r=t.extensions[S].diffuseTexture;o.setDiffuseTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getDiffuseTextureInfo(),r)}if(void 0!==t.extensions[S].specularGlossinessTexture){const r=t.extensions[S].specularGlossinessTexture;o.setSpecularGlossinessTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getSpecularGlossinessTextureInfo(),r)}}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(S);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];if(n.extensions=n.extensions||{},n.extensions[S]={diffuseFactor:r.getDiffuseFactor(),specularFactor:r.getSpecularFactor(),glossinessFactor:r.getGlossinessFactor()},r.getDiffuseTexture()){const t=r.getDiffuseTexture(),s=r.getDiffuseTextureInfo();n.extensions[S].diffuseTexture=e.createTextureInfoDef(t,s)}if(r.getSpecularGlossinessTexture()){const t=r.getSpecularGlossinessTexture(),s=r.getSpecularGlossinessTextureInfo();n.extensions[S].specularGlossinessTexture=e.createTextureInfoDef(t,s)}}}),this}}D.EXTENSION_NAME=S;class M extends r{constructor(){super(...arguments),this.propertyType="Specular",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_specular",this._specularFactor=1,this._specularColorFactor=[1,1,1],this.specularTexture=null,this.specularTextureInfo=this.graph.link("specularTextureInfo",this,new i(this.graph))}copy(e,t=o){return super.copy(e,t),this._specularFactor=e._specularFactor,e.specularTexture&&(this.setSpecularTexture(t(e.specularTexture.getChild())),this.getSpecularTextureInfo().copy(t(e.specularTextureInfo.getChild()))),this}getSpecularFactor(){return this._specularFactor}setSpecularFactor(e){return this._specularFactor=e,this}getSpecularColorFactor(){return this._specularColorFactor}setSpecularColorFactor(e){return this._specularColorFactor=e,this}getSpecularColorHex(){return n.factorToHex(this._specularColorFactor)}setSpecularColorHex(e){return n.hexToFactor(e,this._specularColorFactor),this}getSpecularTexture(){return this.specularTexture?this.specularTexture.getChild():null}getSpecularTextureInfo(){return this.specularTexture?this.specularTextureInfo.getChild():null}setSpecularTexture(e){return this.specularTexture=this.graph.link("specularTexture",this,e),this}}M.EXTENSION_NAME="KHR_materials_specular",I([a],M.prototype,"specularTexture",void 0),I([a],M.prototype,"specularTextureInfo",void 0);const j="KHR_materials_specular";class G extends e{constructor(){super(...arguments),this.extensionName=j}createSpecular(){return new M(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[j]){const o=this.createSpecular();if(e.materials[r].setExtension(j,o),void 0!==t.extensions[j].specularFactor&&o.setSpecularFactor(t.extensions[j].specularFactor),void 0!==t.extensions[j].specularColorFactor&&o.setSpecularColorFactor(t.extensions[j].specularColorFactor),void 0!==t.extensions[j].specularTexture){const r=t.extensions[j].specularTexture;o.setSpecularTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getSpecularTextureInfo(),r)}}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(j);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];if(n.extensions=n.extensions||{},n.extensions[j]={specularFactor:r.getSpecularFactor(),specularColorFactor:r.getSpecularColorFactor()},r.getSpecularTexture()){const t=r.getSpecularTexture(),s=r.getSpecularTextureInfo();n.extensions[j].specularTexture=e.createTextureInfoDef(t,s)}}}),this}}G.EXTENSION_NAME=j;class v extends r{constructor(){super(...arguments),this.propertyType="Transmission",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_transmission",this._transmissionFactor=0,this.transmissionTexture=null,this.transmissionTextureInfo=this.graph.link("transmissionTextureInfo",this,new i(this.graph))}copy(e,t=o){return super.copy(e,t),this._transmissionFactor=e._transmissionFactor,e.transmissionTexture&&(this.setTransmissionTexture(t(e.transmissionTexture.getChild())),this.getTransmissionTextureInfo().copy(t(e.transmissionTextureInfo.getChild()))),this}getTransmissionFactor(){return this._transmissionFactor}setTransmissionFactor(e){return this._transmissionFactor=e,this}getTransmissionTexture(){return this.transmissionTexture?this.transmissionTexture.getChild():null}getTransmissionTextureInfo(){return this.transmissionTexture?this.transmissionTextureInfo.getChild():null}setTransmissionTexture(e){return this.transmissionTexture=this.graph.link("transmissionTexture",this,e),this}}v.EXTENSION_NAME="KHR_materials_transmission",I([a],v.prototype,"transmissionTexture",void 0),I([a],v.prototype,"transmissionTextureInfo",void 0);const w="KHR_materials_transmission";class O extends e{constructor(){super(...arguments),this.extensionName=w}createTransmission(){return new v(this.doc.getGraph(),this)}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[w]){const o=this.createTransmission();if(e.materials[r].setExtension(w,o),void 0!==t.extensions[w].transmissionFactor&&o.setTransmissionFactor(t.extensions[w].transmissionFactor),void 0!==t.extensions[w].transmissionTexture){const r=t.extensions[w].transmissionTexture;o.setTransmissionTexture(e.textures[s[r.index].source]),e.setTextureInfo(o.getTransmissionTextureInfo(),r)}}}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(w);if(r){const o=e.materialIndexMap.get(s),n=t.json.materials[o];if(n.extensions=n.extensions||{},n.extensions[w]={transmissionFactor:r.getTransmissionFactor()},r.getTransmissionTexture()){const t=r.getTransmissionTexture(),s=r.getTransmissionTextureInfo();n.extensions[w].transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}O.EXTENSION_NAME=w;class H extends r{constructor(){super(...arguments),this.propertyType="Unlit",this.parentTypes=[t.MATERIAL],this.extensionName="KHR_materials_unlit"}}H.EXTENSION_NAME="KHR_materials_unlit";const b="KHR_materials_unlit";class K extends e{constructor(){super(...arguments),this.extensionName=b}createUnlit(){return new H(this.doc.getGraph(),this)}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[b]&&e.materials[s].setExtension(b,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listMaterials().forEach(s=>{if(s.getExtension(b)){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{},o.extensions[b]={}}}),this}}K.EXTENSION_NAME=b;const L="KHR_mesh_quantization";class X extends e{constructor(){super(...arguments),this.extensionName=L}read(e){return this}write(e){return this}}X.EXTENSION_NAME=L;const k="KHR_texture_basisu";class U extends e{constructor(){super(...arguments),this.extensionName=k,this.provideTypes=[t.TEXTURE]}provide(e){return e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[k]&&(e.source=e.extensions[k].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.doc.getRoot().listTextures().forEach(s=>{if("image/ktx2"===s.getMimeType()){const r=e.imageIndexMap.get(s);t.json.textures.forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[k]={source:e.source},delete e.source)})}}),this}}U.EXTENSION_NAME=k;const P=[g,_,y,R,D,G,O,K,X,U];export{N as Clearcoat,g as DracoMeshCompression,E as IOR,P as KHRONOS_EXTENSIONS,d as Light,f as LightType,_ as LightsPunctual,y as MaterialsClearcoat,R as MaterialsIOR,D as MaterialsPBRSpecularGlossiness,G as MaterialsSpecular,O as MaterialsTransmission,K as MaterialsUnlit,X as MeshQuantization,A as PBRSpecularGlossiness,M as Specular,U as TextureBasisu,v as Transmission,H as Unlit}; | ||
//# sourceMappingURL=extensions.modern.js.map |
{ | ||
"name": "@gltf-transform/extensions", | ||
"version": "0.7.0-alpha.2", | ||
"version": "0.7.0-alpha.4", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
@@ -24,3 +24,3 @@ "description": "Adds extension support to @gltf-transform/core", | ||
"dependencies": { | ||
"@gltf-transform/core": "^0.7.0-alpha.2" | ||
"@gltf-transform/core": "^0.7.0-alpha.4" | ||
}, | ||
@@ -33,3 +33,3 @@ "files": [ | ||
], | ||
"gitHead": "c13e71257c34aaf7a05114d4740e5a2aec375807" | ||
"gitHead": "ad8d8d07a524a4ddfea3dc89e823278922987d17" | ||
} |
@@ -1,8 +0,8 @@ | ||
import { TypedArray } from '@gltf-transform/core'; | ||
import { TypedArray, TypedArrayConstructor } from '@gltf-transform/core'; | ||
export let decoderModule: DRACO.DecoderModule; | ||
export function initDecoderModule (_decoderModule: DRACO.DecoderModule): void { | ||
decoderModule = _decoderModule; | ||
} | ||
// Initialized when decoder module loads. | ||
let COMPONENT_ARRAY: {[key: number]: TypedArrayConstructor}; | ||
let DATA_TYPE: {[key: number]: DRACO.DataType}; | ||
@@ -33,18 +33,13 @@ export function decodeGeometry(decoder: DRACO.Decoder, arrayBuffer: ArrayBuffer): DRACO.Mesh { | ||
export function decodeIndex(decoder: DRACO.Decoder, geometry: DRACO.Mesh): Uint32Array { | ||
const numFaces = geometry.num_faces(); | ||
export function decodeIndex(decoder: DRACO.Decoder, mesh: DRACO.Mesh): Uint32Array { | ||
const numFaces = mesh.num_faces(); | ||
const numIndices = numFaces * 3; | ||
const index = new Uint32Array( numIndices ); | ||
const dracoIndices = new decoderModule.DracoInt32Array(); | ||
const byteLength = numIndices * Uint32Array.BYTES_PER_ELEMENT; | ||
for (let i = 0; i < numFaces; i++) { | ||
decoder.GetFaceFromMesh(geometry, i, dracoIndices); | ||
for (let j = 0; j < 3; ++ j) { | ||
index[ i * 3 + j ] = dracoIndices.GetValue( j ); | ||
} | ||
} | ||
const ptr = decoderModule._malloc(byteLength); | ||
decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr); | ||
const indices = new Uint32Array(decoderModule.HEAP32.buffer, ptr, numIndices).slice(); | ||
decoderModule._free(ptr); | ||
decoderModule.destroy(dracoIndices); | ||
return index; | ||
return indices; | ||
} | ||
@@ -54,87 +49,42 @@ | ||
decoder: DRACO.Decoder, | ||
geometry: DRACO.Mesh, | ||
mesh: DRACO.Mesh, | ||
attribute: DRACO.Attribute, | ||
accessorDef: GLTF.IAccessor): TypedArray { | ||
const componentType = componentTypeToArray(accessorDef.componentType); | ||
const dataType = DATA_TYPE[accessorDef.componentType]; | ||
const ArrayCtor = COMPONENT_ARRAY[accessorDef.componentType]; | ||
const numComponents = attribute.num_components(); | ||
const numPoints = geometry.num_points(); | ||
const numPoints = mesh.num_points(); | ||
const numValues = numPoints * numComponents; | ||
const byteLength: number = numValues * ArrayCtor.BYTES_PER_ELEMENT; | ||
let dracoArray; | ||
let array; | ||
const ptr = decoderModule._malloc(byteLength); | ||
decoder.GetAttributeDataArrayForAllPoints(mesh, attribute, dataType, byteLength, ptr); | ||
const array: TypedArray = new ArrayCtor(decoderModule.HEAPF32.buffer, ptr, numValues).slice(); | ||
decoderModule._free(ptr); | ||
switch (componentType) { | ||
case Float32Array: | ||
dracoArray = new decoderModule.DracoFloat32Array(); | ||
decoder.GetAttributeFloatForAllPoints(geometry, attribute, dracoArray); | ||
array = new Float32Array(numValues); | ||
break; | ||
case Int8Array: | ||
dracoArray = new decoderModule.DracoInt8Array(); | ||
decoder.GetAttributeInt8ForAllPoints(geometry, attribute, dracoArray); | ||
array = new Int8Array(numValues); | ||
break; | ||
case Int16Array: | ||
dracoArray = new decoderModule.DracoInt16Array(); | ||
decoder.GetAttributeInt16ForAllPoints(geometry, attribute, dracoArray); | ||
array = new Int16Array(numValues); | ||
break; | ||
case Uint8Array: | ||
dracoArray = new decoderModule.DracoUInt8Array(); | ||
decoder.GetAttributeUInt8ForAllPoints(geometry, attribute, dracoArray); | ||
array = new Uint8Array(numValues); | ||
break; | ||
case Uint16Array: | ||
dracoArray = new decoderModule.DracoUInt16Array(); | ||
decoder.GetAttributeUInt16ForAllPoints(geometry, attribute, dracoArray); | ||
array = new Uint16Array(numValues); | ||
break; | ||
case Uint32Array: | ||
dracoArray = new decoderModule.DracoUInt32Array(); | ||
decoder.GetAttributeUInt32ForAllPoints(geometry, attribute, dracoArray); | ||
array = new Uint32Array(numValues); | ||
break; | ||
default: | ||
throw new Error('Unexpected attribute type.'); | ||
} | ||
for (let i = 0; i < numValues; i ++) { | ||
array[i] = dracoArray.GetValue(i); | ||
} | ||
decoderModule.destroy(dracoArray); | ||
return array; | ||
} | ||
function componentTypeToArray (componentType: GLTF.AccessorComponentType): new () => TypedArray { | ||
switch (componentType) { | ||
export function initDecoderModule (_decoderModule: DRACO.DecoderModule): void { | ||
decoderModule = _decoderModule; | ||
case GLTF.AccessorComponentType.FLOAT: | ||
return Float32Array; | ||
COMPONENT_ARRAY = { | ||
[GLTF.AccessorComponentType.FLOAT]: Float32Array, | ||
[GLTF.AccessorComponentType.UNSIGNED_INT]: Uint32Array, | ||
[GLTF.AccessorComponentType.UNSIGNED_SHORT]: Uint16Array, | ||
[GLTF.AccessorComponentType.UNSIGNED_BYTE]: Uint8Array, | ||
[GLTF.AccessorComponentType.SHORT]: Int16Array, | ||
[GLTF.AccessorComponentType.BYTE]: Int8Array, | ||
}; | ||
case GLTF.AccessorComponentType.UNSIGNED_INT: | ||
return Uint32Array; | ||
DATA_TYPE = { | ||
[GLTF.AccessorComponentType.FLOAT]: decoderModule.DT_FLOAT32, | ||
[GLTF.AccessorComponentType.UNSIGNED_INT]: decoderModule.DT_UINT32, | ||
[GLTF.AccessorComponentType.UNSIGNED_SHORT]: decoderModule.DT_UINT16, | ||
[GLTF.AccessorComponentType.UNSIGNED_BYTE]: decoderModule.DT_UINT8, | ||
[GLTF.AccessorComponentType.SHORT]: decoderModule.DT_INT16, | ||
[GLTF.AccessorComponentType.BYTE]: decoderModule.DT_INT8, | ||
}; | ||
} | ||
case GLTF.AccessorComponentType.UNSIGNED_SHORT: | ||
return Uint16Array; | ||
case GLTF.AccessorComponentType.UNSIGNED_BYTE: | ||
return Uint8Array; | ||
case GLTF.AccessorComponentType.SHORT: | ||
return Int16Array; | ||
case GLTF.AccessorComponentType.BYTE: | ||
return Int8Array; | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { COPY_IDENTITY, ExtensionProperty, GraphChild, PropertyType, Texture, TextureInfo, TextureLink, TextureSampler } from '@gltf-transform/core'; | ||
import { COPY_IDENTITY, ExtensionProperty, GraphChild, Link, PropertyType, Texture, TextureInfo } from '@gltf-transform/core'; | ||
import { KHR_MATERIALS_CLEARCOAT } from '../constants'; | ||
@@ -15,6 +15,14 @@ | ||
@GraphChild private clearcoatTexture: TextureLink = null; | ||
@GraphChild private clearcoatRoughnessTexture: TextureLink = null; | ||
@GraphChild private clearcoatNormalTexture: TextureLink = null; | ||
@GraphChild private clearcoatTexture: Link<this, Texture> = null; | ||
@GraphChild private clearcoatTextureInfo: Link<this, TextureInfo> = | ||
this.graph.link('clearcoatTextureInfo', this, new TextureInfo(this.graph)); | ||
@GraphChild private clearcoatRoughnessTexture: Link<this, Texture> = null; | ||
@GraphChild private clearcoatRoughnessTextureInfo: Link<this, TextureInfo> = | ||
this.graph.link('clearcoatRoughnessTextureInfo', this, new TextureInfo(this.graph)); | ||
@GraphChild private clearcoatNormalTexture: Link<this, Texture> = null; | ||
@GraphChild private clearcoatNormalTextureInfo: Link<this, TextureInfo> = | ||
this.graph.link('clearcoatNormalTextureInfo', this, new TextureInfo(this.graph)); | ||
public copy(other: this, resolve = COPY_IDENTITY): this { | ||
@@ -29,11 +37,11 @@ super.copy(other, resolve); | ||
this.setClearcoatTexture(resolve(other.clearcoatTexture.getChild())); | ||
this.clearcoatTexture.copy(other.clearcoatTexture); | ||
this.getClearcoatTextureInfo().copy(resolve(other.clearcoatTextureInfo.getChild())); | ||
} | ||
if (other.clearcoatRoughnessTexture) { | ||
this.setClearcoatRoughnessTexture(resolve(other.clearcoatRoughnessTexture.getChild())); | ||
this.clearcoatRoughnessTexture.copy(other.clearcoatRoughnessTexture); | ||
this.getClearcoatRoughnessTextureInfo().copy(resolve(other.clearcoatRoughnessTextureInfo.getChild())); | ||
} | ||
if (other.clearcoatNormalTexture) { | ||
this.setClearcoatNormalTexture(resolve(other.clearcoatNormalTexture.getChild())); | ||
this.clearcoatNormalTexture.copy(other.clearcoatNormalTexture); | ||
this.getClearcoatNormalTextureInfo().copy(resolve(other.clearcoatNormalTextureInfo.getChild())); | ||
} | ||
@@ -71,16 +79,8 @@ | ||
public getClearcoatTextureInfo(): TextureInfo { | ||
return this.clearcoatTexture ? this.clearcoatTexture.textureInfo : null; | ||
return this.clearcoatTexture ? this.clearcoatTextureInfo.getChild() : null; | ||
} | ||
/** | ||
* Settings affecting the material's use of its clearcoat texture. If no texture is attached, | ||
* {@link TextureSampler} is `null`. | ||
*/ | ||
public getClearcoatTextureSampler(): TextureSampler { | ||
return this.clearcoatTexture ? this.clearcoatTexture.sampler : null; | ||
} | ||
/** Sets clearcoat texture. See {@link getClearcoatTexture}. */ | ||
public setClearcoatTexture(texture: Texture): this { | ||
this.clearcoatTexture = this.graph.linkTexture('clearcoatTexture', this, texture); | ||
this.clearcoatTexture = this.graph.link('clearcoatTexture', this, texture); | ||
return this; | ||
@@ -115,16 +115,8 @@ } | ||
public getClearcoatRoughnessTextureInfo(): TextureInfo { | ||
return this.clearcoatRoughnessTexture ? this.clearcoatRoughnessTexture.textureInfo : null; | ||
return this.clearcoatRoughnessTexture ? this.clearcoatRoughnessTextureInfo.getChild() : null; | ||
} | ||
/** | ||
* Settings affecting the material's use of its clearcoat roughness texture. If no texture is | ||
* attached, {@link TextureSampler} is `null`. | ||
*/ | ||
public getClearcoatRoughnessTextureSampler(): TextureSampler { | ||
return this.clearcoatRoughnessTexture ? this.clearcoatRoughnessTexture.sampler : null; | ||
} | ||
/** Sets clearcoat roughness texture. See {@link getClearcoatRoughnessTexture}. */ | ||
public setClearcoatRoughnessTexture(texture: Texture): this { | ||
this.clearcoatRoughnessTexture = this.graph.linkTexture('clearcoatRoughnessTexture', this, texture); | ||
this.clearcoatRoughnessTexture = this.graph.link('clearcoatRoughnessTexture', this, texture); | ||
return this; | ||
@@ -158,18 +150,10 @@ } | ||
public getClearcoatNormalTextureInfo(): TextureInfo { | ||
return this.clearcoatNormalTexture ? this.clearcoatNormalTexture.textureInfo : null; | ||
return this.clearcoatNormalTexture ? this.clearcoatNormalTextureInfo.getChild() : null; | ||
} | ||
/** | ||
* Settings affecting the material's use of its clearcoat normal texture. If no texture is | ||
* attached, {@link TextureSampler} is `null`. | ||
*/ | ||
public getClearcoatNormalTextureSampler(): TextureSampler { | ||
return this.clearcoatNormalTexture ? this.clearcoatNormalTexture.sampler : null; | ||
} | ||
/** Sets clearcoat normal texture. See {@link getClearcoatNormalTexture}. */ | ||
public setClearcoatNormalTexture(texture: Texture): this { | ||
this.clearcoatNormalTexture = this.graph.linkTexture('clearcoatNormalTexture', this, texture); | ||
this.clearcoatNormalTexture = this.graph.link('clearcoatNormalTexture', this, texture); | ||
return this; | ||
} | ||
} |
@@ -41,3 +41,2 @@ import { Extension, ReaderContext, WriterContext } from '@gltf-transform/core'; | ||
context.setTextureInfo(clearcoat.getClearcoatTextureInfo(), textureInfoDef); | ||
context.setTextureSampler(clearcoat.getClearcoatTextureSampler(), textureInfoDef); | ||
} | ||
@@ -48,4 +47,3 @@ if (materialDef.extensions[NAME].clearcoatRoughnessTexture !== undefined) { | ||
clearcoat.setClearcoatRoughnessTexture(texture); | ||
context.setTextureInfo(clearcoat.getClearcoatRoughnessTextureInfo(), textureInfoDef); | ||
context.setTextureSampler(clearcoat.getClearcoatRoughnessTextureSampler(), textureInfoDef); | ||
context.setTextureInfo(clearcoat.getClearcoatRoughnessTextureInfo(), textureInfoDef);; | ||
} | ||
@@ -57,3 +55,2 @@ if (materialDef.extensions[NAME].clearcoatNormalTexture !== undefined) { | ||
context.setTextureInfo(clearcoat.getClearcoatNormalTextureInfo(), textureInfoDef); | ||
context.setTextureSampler(clearcoat.getClearcoatNormalTextureSampler(), textureInfoDef); | ||
if (textureInfoDef.scale !== undefined) { | ||
@@ -93,4 +90,3 @@ clearcoat.setClearcoatNormalScale(textureInfoDef.scale); | ||
const textureInfo = clearcoat.getClearcoatTextureInfo(); | ||
const textureSampler = clearcoat.getClearcoatTextureSampler(); | ||
materialDef.extensions[NAME].clearcoatTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.extensions[NAME].clearcoatTexture = context.createTextureInfoDef(texture, textureInfo); | ||
} | ||
@@ -100,4 +96,3 @@ if (clearcoat.getClearcoatRoughnessTexture()) { | ||
const textureInfo = clearcoat.getClearcoatRoughnessTextureInfo(); | ||
const textureSampler = clearcoat.getClearcoatRoughnessTextureSampler(); | ||
materialDef.extensions[NAME].clearcoatRoughnessTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.extensions[NAME].clearcoatRoughnessTexture = context.createTextureInfoDef(texture, textureInfo); | ||
} | ||
@@ -107,4 +102,3 @@ if (clearcoat.getClearcoatNormalTexture()) { | ||
const textureInfo = clearcoat.getClearcoatNormalTextureInfo(); | ||
const textureSampler = clearcoat.getClearcoatNormalTextureSampler(); | ||
materialDef.extensions[NAME].clearcoatNormalTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.extensions[NAME].clearcoatNormalTexture = context.createTextureInfoDef(texture, textureInfo); | ||
if (clearcoat.getClearcoatNormalScale() !== 1) { | ||
@@ -111,0 +105,0 @@ materialDef.extensions[NAME].clearcoatNormalTexture.scale = clearcoat.getClearcoatNormalScale(); |
@@ -44,3 +44,2 @@ import { Extension, ReaderContext, WriterContext } from '@gltf-transform/core'; | ||
context.setTextureInfo(specGloss.getDiffuseTextureInfo(), textureInfoDef); | ||
context.setTextureSampler(specGloss.getDiffuseTextureSampler(), textureInfoDef); | ||
} | ||
@@ -52,3 +51,2 @@ if (materialDef.extensions[NAME].specularGlossinessTexture !== undefined) { | ||
context.setTextureInfo(specGloss.getSpecularGlossinessTextureInfo(), textureInfoDef); | ||
context.setTextureSampler(specGloss.getSpecularGlossinessTextureSampler(), textureInfoDef); | ||
} | ||
@@ -86,4 +84,3 @@ } | ||
const textureInfo = specGloss.getDiffuseTextureInfo(); | ||
const textureSampler = specGloss.getDiffuseTextureSampler(); | ||
materialDef.extensions[NAME].diffuseTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.extensions[NAME].diffuseTexture = context.createTextureInfoDef(texture, textureInfo); | ||
} | ||
@@ -93,4 +90,3 @@ if (specGloss.getSpecularGlossinessTexture()) { | ||
const textureInfo = specGloss.getSpecularGlossinessTextureInfo(); | ||
const textureSampler = specGloss.getSpecularGlossinessTextureSampler(); | ||
materialDef.extensions[NAME].specularGlossinessTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.extensions[NAME].specularGlossinessTexture = context.createTextureInfoDef(texture, textureInfo); | ||
} | ||
@@ -97,0 +93,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { COPY_IDENTITY, ColorUtils, ExtensionProperty, GraphChild, PropertyType, Texture, TextureInfo, TextureLink, TextureSampler, vec3, vec4 } from '@gltf-transform/core'; | ||
import { COPY_IDENTITY, ColorUtils, ExtensionProperty, GraphChild, Link, PropertyType, Texture, TextureInfo, vec3, vec4 } from '@gltf-transform/core'; | ||
import { KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS } from '../constants'; | ||
@@ -15,5 +15,10 @@ | ||
@GraphChild private diffuseTexture: TextureLink = null; | ||
@GraphChild private specularGlossinessTexture: TextureLink = null; | ||
@GraphChild private diffuseTexture: Link<this, Texture> = null; | ||
@GraphChild private diffuseTextureInfo: Link<this, TextureInfo> = | ||
this.graph.link('diffuseTextureInfo', this, new TextureInfo(this.graph)); | ||
@GraphChild private specularGlossinessTexture: Link<this, Texture> = null; | ||
@GraphChild private specularGlossinessTextureInfo: Link<this, TextureInfo> = | ||
this.graph.link('specularGlossinessTextureInfo', this, new TextureInfo(this.graph)); | ||
public copy(other: this, resolve = COPY_IDENTITY): this { | ||
@@ -26,10 +31,9 @@ super.copy(other, resolve); | ||
if (other.diffuseTexture) { | ||
this.setDiffuseTexture(resolve(other.diffuseTexture.getChild())); | ||
this.diffuseTexture.copy(other.diffuseTexture); | ||
this.getDiffuseTextureInfo().copy(resolve(other.diffuseTextureInfo.getChild())); | ||
} | ||
if (other.specularGlossinessTexture) { | ||
this.setSpecularGlossinessTexture(resolve(other.specularGlossinessTexture.getChild())); | ||
this.specularGlossinessTexture.copy(other.specularGlossinessTexture); | ||
this.getSpecularGlossinessTextureInfo().copy(resolve(other.specularGlossinessTextureInfo.getChild())); | ||
} | ||
@@ -75,16 +79,8 @@ | ||
public getDiffuseTextureInfo(): TextureInfo { | ||
return this.diffuseTexture ? this.diffuseTexture.textureInfo : null; | ||
return this.diffuseTexture ? this.diffuseTextureInfo.getChild() : null; | ||
} | ||
/** | ||
* Settings affecting the material's use of its diffuse texture. If no texture is attached, | ||
* {@link TextureSampler} is `null`. | ||
*/ | ||
public getDiffuseTextureSampler(): TextureSampler { | ||
return this.diffuseTexture ? this.diffuseTexture.sampler : null; | ||
} | ||
/** Sets diffuse texture. See {@link getDiffuseTexture}. */ | ||
public setDiffuseTexture(texture: Texture): this { | ||
this.diffuseTexture = this.graph.linkTexture('diffuseTexture', this, texture); | ||
this.diffuseTexture = this.graph.link('diffuseTexture', this, texture); | ||
return this; | ||
@@ -133,18 +129,10 @@ } | ||
public getSpecularGlossinessTextureInfo(): TextureInfo { | ||
return this.specularGlossinessTexture ? this.specularGlossinessTexture.textureInfo : null; | ||
return this.specularGlossinessTexture ? this.specularGlossinessTextureInfo.getChild() : null; | ||
} | ||
/** | ||
* Settings affecting the material's use of its spec/gloss texture. If no texture is attached, | ||
* {@link TextureSampler} is `null`. | ||
*/ | ||
public getSpecularGlossinessTextureSampler(): TextureSampler { | ||
return this.specularGlossinessTexture ? this.specularGlossinessTexture.sampler : null; | ||
} | ||
/** Spec/gloss texture; linear multiplier. */ | ||
public setSpecularGlossinessTexture(texture: Texture): this { | ||
this.specularGlossinessTexture = this.graph.linkTexture('specularGlossinessTexture', this, texture); | ||
this.specularGlossinessTexture = this.graph.link('specularGlossinessTexture', this, texture); | ||
return this; | ||
} | ||
} |
@@ -41,3 +41,2 @@ import { Extension, ReaderContext, WriterContext } from '@gltf-transform/core'; | ||
context.setTextureInfo(specular.getSpecularTextureInfo(), textureInfoDef); | ||
context.setTextureSampler(specular.getSpecularTextureSampler(), textureInfoDef); | ||
} | ||
@@ -74,4 +73,3 @@ } | ||
const textureInfo = specular.getSpecularTextureInfo(); | ||
const textureSampler = specular.getSpecularTextureSampler(); | ||
materialDef.extensions[NAME].specularTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.extensions[NAME].specularTexture = context.createTextureInfoDef(texture, textureInfo); | ||
} | ||
@@ -78,0 +76,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { COPY_IDENTITY, ColorUtils, ExtensionProperty, GraphChild, PropertyType, Texture, TextureInfo, TextureLink, TextureSampler, vec3 } from '@gltf-transform/core'; | ||
import { COPY_IDENTITY, ColorUtils, ExtensionProperty, GraphChild, Link, PropertyType, Texture, TextureInfo, vec3 } from '@gltf-transform/core'; | ||
import { KHR_MATERIALS_SPECULAR } from '../constants'; | ||
@@ -14,3 +14,5 @@ | ||
@GraphChild private specularTexture: TextureLink = null; | ||
@GraphChild private specularTexture: Link<this, Texture> = null; | ||
@GraphChild private specularTextureInfo: Link<this, TextureInfo> = | ||
this.graph.link('specularTextureInfo', this, new TextureInfo(this.graph)); | ||
@@ -24,3 +26,3 @@ public copy(other: this, resolve = COPY_IDENTITY): this { | ||
this.setSpecularTexture(resolve(other.specularTexture.getChild())); | ||
this.specularTexture.copy(other.specularTexture); | ||
this.getSpecularTextureInfo().copy(resolve(other.specularTextureInfo.getChild())); | ||
} | ||
@@ -82,18 +84,10 @@ | ||
public getSpecularTextureInfo(): TextureInfo { | ||
return this.specularTexture ? this.specularTexture.textureInfo : null; | ||
return this.specularTexture ? this.specularTextureInfo.getChild() : null; | ||
} | ||
/** | ||
* Settings affecting the material's use of its specular texture. If no texture is attached, | ||
* {@link TextureSampler} is `null`. | ||
*/ | ||
public getSpecularTextureSampler(): TextureSampler { | ||
return this.specularTexture ? this.specularTexture.sampler : null; | ||
} | ||
/** Sets specular texture. See {@link getSpecularTexture}. */ | ||
public setSpecularTexture(texture: Texture): this { | ||
this.specularTexture = this.graph.linkTexture('specularTexture', this, texture); | ||
this.specularTexture = this.graph.link('specularTexture', this, texture); | ||
return this; | ||
} | ||
} |
@@ -38,3 +38,2 @@ import { Extension, ReaderContext, WriterContext } from '@gltf-transform/core'; | ||
context.setTextureInfo(transmission.getTransmissionTextureInfo(), textureInfoDef); | ||
context.setTextureSampler(transmission.getTransmissionTextureSampler(), textureInfoDef); | ||
} | ||
@@ -70,4 +69,3 @@ } | ||
const textureInfo = transmission.getTransmissionTextureInfo(); | ||
const textureSampler = transmission.getTransmissionTextureSampler(); | ||
materialDef.extensions[NAME].transmissionTexture = context.createTextureInfoDef(texture, textureInfo, textureSampler); | ||
materialDef.extensions[NAME].transmissionTexture = context.createTextureInfoDef(texture, textureInfo); | ||
} | ||
@@ -74,0 +72,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { COPY_IDENTITY, ExtensionProperty, GraphChild, PropertyType, Texture, TextureInfo, TextureLink, TextureSampler } from '@gltf-transform/core'; | ||
import { COPY_IDENTITY, ExtensionProperty, GraphChild, Link, PropertyType, Texture, TextureInfo } from '@gltf-transform/core'; | ||
import { KHR_MATERIALS_TRANSMISSION } from '../constants'; | ||
@@ -13,3 +13,5 @@ | ||
@GraphChild private transmissionTexture: TextureLink = null; | ||
@GraphChild private transmissionTexture: Link<this, Texture> = null; | ||
@GraphChild private transmissionTextureInfo: Link<this, TextureInfo> = | ||
this.graph.link('transmissionTextureInfo', this, new TextureInfo(this.graph)); | ||
@@ -23,3 +25,3 @@ public copy(other: this, resolve = COPY_IDENTITY): this { | ||
this.setTransmissionTexture(resolve(other.transmissionTexture.getChild())); | ||
this.transmissionTexture.copy(other.transmissionTexture); | ||
this.getTransmissionTextureInfo().copy(resolve(other.transmissionTextureInfo.getChild())); | ||
} | ||
@@ -58,18 +60,10 @@ | ||
public getTransmissionTextureInfo(): TextureInfo { | ||
return this.transmissionTexture ? this.transmissionTexture.textureInfo : null; | ||
return this.transmissionTexture ? this.transmissionTextureInfo.getChild() : null; | ||
} | ||
/** | ||
* Settings affecting the material's use of its transmission texture. If no texture is attached, | ||
* {@link TextureSampler} is `null`. | ||
*/ | ||
public getTransmissionTextureSampler(): TextureSampler { | ||
return this.transmissionTexture ? this.transmissionTexture.sampler : null; | ||
} | ||
/** Sets transmission texture. See {@link getTransmissionTexture}. */ | ||
public setTransmissionTexture(texture: Texture): this { | ||
this.transmissionTexture = this.graph.linkTexture('transmissionTexture', this, texture); | ||
this.transmissionTexture = this.graph.link('transmissionTexture', this, texture); | ||
return this; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
462840
166
5537