@@ -27,7 +27,7 @@ type MetaData = {
2727 format_version : "4.0" ;
2828 creation_time : number ;
2929 model_format : "bedrock" ;
30- box_uv : true ;
30+ box_uv : false ;
3131}
3232
3333export type CubeElement = {
@@ -42,7 +42,6 @@ export type CubeElement = {
4242 inflate ?: number
4343 origin : NumArray
4444 rotation ?: NumArray
45- uv_offset ?: NumArray < 2 >
4645 faces : {
4746 north : CubeElementFace
4847 east : CubeElementFace
@@ -152,7 +151,7 @@ const createBasicModelData = (): Pick<BBModelFormat,
152151 meta : {
153152 format_version : '4.0' ,
154153 creation_time : Math . floor ( Date . now ( ) / 1000 ) ,
155- box_uv : true ,
154+ box_uv : false ,
156155 model_format : "bedrock" ,
157156 } as const ,
158157 geometry_name : "Model" ,
@@ -365,6 +364,7 @@ const convertCubeAndBone = (dcmCube: DCMCube, cubes: CubeElement[], boneAcceptor
365364const convertCube = ( cube : DCMCube , positionCache : WorldPositionCache ) : CubeElement => {
366365 const position = getCubePosition ( cube , positionCache )
367366 const offset = _cloneArr ( cube . offset )
367+ const textureOffset = _cloneArr ( cube . textureOffset )
368368 const dimension = _cloneArr ( cube . dimension )
369369
370370 let cubeGrow = cube . cubeGrow . value ;
@@ -380,14 +380,13 @@ const convertCube = (cube: DCMCube, positionCache: WorldPositionCache): CubeElem
380380 color : 1 ,
381381 inflate : 0 ,
382382 origin : [ 0 , 0 , 0 ] ,
383- uv_offset : _cloneArr ( cube . textureOffset ) ,
384383 faces : {
385- north : getCubeFace ( cube , 0 ) ,
386- east : getCubeFace ( cube , 0 ) ,
387- south : getCubeFace ( cube , 0 ) ,
388- west : getCubeFace ( cube , 0 ) ,
389- up : getCubeFace ( cube , 0 ) ,
390- down : getCubeFace ( cube , 0 ) ,
384+ north : getCubeFace ( cube , dimension , textureOffset , 0 ) ,
385+ east : getCubeFace ( cube , dimension , textureOffset , 1 ) ,
386+ south : getCubeFace ( cube , dimension , textureOffset , 2 ) ,
387+ west : getCubeFace ( cube , dimension , textureOffset , 3 ) ,
388+ up : getCubeFace ( cube , dimension , textureOffset , 4 ) ,
389+ down : getCubeFace ( cube , dimension , textureOffset , 5 ) ,
391390 } ,
392391 type : "cube" ,
393392 uuid : v4 ( )
@@ -458,10 +457,42 @@ const getCubePosition = (cube: DCMCube, positionCache: WorldPositionCache): NumA
458457 ] as const
459458}
460459
461- const getCubeFace = ( cube : DCMCube , face : number ) : CubeElementFace => ( {
462- texture : 0 ,
463- uv : [ 0 , 0 , 1 , 1 ]
464- } )
460+ const getCubeFace = ( cube : DCMCube , dimension : NumArray , textureOffset : NumArray < 2 > , face : number ) : CubeElementFace => {
461+ const w = Math . round ( dimension [ 0 ] )
462+ const h = Math . round ( dimension [ 1 ] )
463+ const d = Math . round ( dimension [ 2 ] )
464+
465+ const u = Math . round ( textureOffset [ 0 ] )
466+ const v = Math . round ( textureOffset [ 1 ] )
467+
468+ let uv : [ number , number , number , number ] = [ 0 , 0 , 1 , 1 ]
469+
470+ switch ( face ) {
471+ case 0 : // north
472+ uv = [ u + d + w + d , v + d , u + d + w + d + w , v + d + h ]
473+ break
474+ case 1 : // east
475+ uv = [ u , v + d , u + d , v + d + h ]
476+ break
477+ case 2 : // south
478+ uv = [ u + d , v + d , u + d + w , v + d + h ]
479+ break
480+ case 3 : // west
481+ uv = [ u + d + w , v + d , u + d + w + d , v + d + h ]
482+ break
483+ case 4 : // up
484+ uv = [ u + d , v , u + d + w , v + d ]
485+ break
486+ case 5 : // down
487+ uv = [ u + d + w , v , u + d + w + w , v + d ]
488+ break
489+ }
490+
491+ return {
492+ texture : 0 ,
493+ uv
494+ }
495+ }
465496
466497const plusArr = ( arr1 : NumArray , arr2 : NumArray ) : NumArray => {
467498 return [
0 commit comments