@needle-tools/three 0.145.2 → 0.145.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -783,9 +783,14 @@ function buildMesh( geometry ) {
783
783
  interpolation = "vertex"
784
784
  )
785
785
  point3f[] points = [${buildVector3Array( attributes.position, count )}]
786
- float2[] primvars:st = [${buildVector2Array( attributes.uv, count )}] (
786
+ ${attributes.uv ?
787
+ `float2[] primvars:st = [${buildVector2Array( attributes.uv, count )}] (
787
788
  interpolation = "vertex"
788
- )
789
+ )` : '' }
790
+ ${attributes.uv2 ?
791
+ `float2[] primvars:st2 = [${buildVector2Array( attributes.uv2, count )}] (
792
+ interpolation = "vertex"
793
+ )` : '' }
789
794
  uniform token subdivisionScheme = "none"
790
795
  }
791
796
  `;
@@ -934,26 +939,31 @@ function buildMaterial( material, textures ) {
934
939
  }
935
940
 
936
941
  textures[ id ] = texture;
942
+ const uvReader = mapType == 'occlusion' ? 'uvReader_st2' : 'uvReader_st';
943
+
944
+ const needsTextureTransform = ( repeat.x != 1 || repeat.y != 1 || offset.x != 0 || offset.y != 0 );
945
+ const textureTransformInput = `</Materials/Material_${material.id}/${uvReader}.outputs:result>`;
946
+ const textureTransformOutput = `</Materials/Material_${material.id}/Transform2d_${mapType}.outputs:result>`;
937
947
 
938
948
  return `
939
- def Shader "Transform2d_${mapType}" (
949
+ ${needsTextureTransform ? `def Shader "Transform2d_${mapType}" (
940
950
  sdrMetadata = {
941
951
  string role = "math"
942
952
  }
943
953
  )
944
954
  {
945
955
  uniform token info:id = "UsdTransform2d"
946
- float2 inputs:in.connect = </Materials/Material_${material.id}/uvReader_st.outputs:result>
956
+ float2 inputs:in.connect = ${textureTransformInput}
947
957
  float2 inputs:scale = ${buildVector2( repeat )}
948
958
  float2 inputs:translation = ${buildVector2( offset )}
949
959
  float2 outputs:result
950
960
  }
951
-
952
- def Shader "Texture_${texture.id}_${mapType}"
961
+ ` : '' }
962
+ def Shader "Texture_${texture.id}_${mapType}"
953
963
  {
954
964
  uniform token info:id = "UsdUVTexture"
955
965
  asset inputs:file = @textures/Texture_${id}.${isRGBA ? 'png' : 'jpg'}@
956
- float2 inputs:st.connect = </Materials/Material_${material.id}/Transform2d_${mapType}.outputs:result>
966
+ float2 inputs:st.connect = ${needsTextureTransform ? textureTransformOutput : textureTransformInput}
957
967
  float4 inputs:scale = (${color ? color.r + ', ' + color.g + ', ' + color.b : '1, 1, 1'}, ${opacity ? opacity : '1'})
958
968
  token inputs:wrapS = "${wrapS}"
959
969
  token inputs:wrapT = "${wrapT}"
@@ -966,6 +976,8 @@ function buildMaterial( material, textures ) {
966
976
 
967
977
  }
968
978
 
979
+ const effectiveOpacity = (material.transparent || material.alphaTest) ? material.opacity : 1;
980
+
969
981
  if ( material.side === DoubleSide ) {
970
982
 
971
983
  console.warn( 'THREE.USDZExporter: USDZ does not support double sided materials', material );
@@ -987,7 +999,7 @@ function buildMaterial( material, textures ) {
987
999
 
988
1000
  }
989
1001
 
990
- samplers.push( buildTexture( material.map, 'diffuse', material.color, material.opacity ) );
1002
+ samplers.push( buildTexture( material.map, 'diffuse', material.color, effectiveOpacity ) );
991
1003
 
992
1004
  } else {
993
1005
 
@@ -1056,7 +1068,7 @@ function buildMaterial( material, textures ) {
1056
1068
 
1057
1069
  } else {
1058
1070
 
1059
- inputs.push( `${pad}float inputs:opacity = ${material.opacity}` );
1071
+ inputs.push( `${pad}float inputs:opacity = ${effectiveOpacity}` );
1060
1072
 
1061
1073
  }
1062
1074
 
@@ -1080,12 +1092,19 @@ ${inputs.join( '\n' )}
1080
1092
  }
1081
1093
 
1082
1094
  token outputs:surface.connect = </Materials/Material_${material.id}/PreviewSurface.outputs:surface>
1083
- token inputs:frame:stPrimvarName = "st"
1084
1095
 
1085
1096
  def Shader "uvReader_st"
1086
1097
  {
1087
1098
  uniform token info:id = "UsdPrimvarReader_float2"
1088
- token inputs:varname.connect = </Materials/Material_${material.id}.inputs:frame:stPrimvarName>
1099
+ token inputs:varname = "st"
1100
+ float2 inputs:fallback = (0.0, 0.0)
1101
+ float2 outputs:result
1102
+ }
1103
+
1104
+ def Shader "uvReader_st2"
1105
+ {
1106
+ uniform token info:id = "UsdPrimvarReader_float2"
1107
+ token inputs:varname = "st2"
1089
1108
  float2 inputs:fallback = (0.0, 0.0)
1090
1109
  float2 outputs:result
1091
1110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/three",
3
- "version": "0.145.2",
3
+ "version": "0.145.4",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.js",
@@ -45,7 +45,7 @@ function WebGLCubeUVMaps( renderer ) {
45
45
 
46
46
  if ( ( isEquirectMap && image && image.height > 0 ) || ( isCubeMap && image && isCubeTextureComplete( image ) ) ) {
47
47
 
48
- if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
48
+ pmremGenerator = new PMREMGenerator( renderer );
49
49
 
50
50
  const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );
51
51
  cubeUVmaps.set( texture, renderTarget );