@@ -12,16 +12,24 @@ override public void Preprocess()
12
12
{
13
13
terrain = unityComponent as Terrain ;
14
14
terrainData = terrain . terrainData ;
15
+ if ( terrainData == null ) return ;
16
+
17
+ SplatPrototype [ ] splats = terrainData . splatPrototypes ;
18
+ for ( int i = 0 ; i < splats . Length ; ++ i )
19
+ {
20
+ textures . Add ( BundleTexture . RegisterTexture ( splats [ i ] . texture , "SplatTex" ) ) ;
21
+ textureSizes . Add ( splats [ i ] . tileSize ) ;
22
+ textureOffsets . Add ( splats [ i ] . tileOffset ) ;
23
+ }
15
24
}
16
25
17
26
override public void Process ( )
18
27
{
28
+ if ( terrainData == null ) return ;
19
29
heightmapHeight = terrainData . heightmapHeight ;
20
30
heightmapWidth = terrainData . heightmapWidth ;
21
- heightmapResolution = terrainData . heightmapResolution ;
22
- heightmapScale = terrainData . heightmapScale ;
23
31
size = terrainData . size ;
24
-
32
+
25
33
float [ , ] heights = terrainData . GetHeights ( 0 , 0 , heightmapWidth , heightmapHeight ) ;
26
34
float [ ] arrayHeight = new float [ heightmapWidth * heightmapHeight ] ;
27
35
for ( int y = 0 ; y < heightmapHeight ; y ++ )
@@ -70,8 +78,6 @@ public override SceneComponent GetObjectData()
70
78
sceneData . type = "Terrain" ;
71
79
sceneData . heightmapHeight = heightmapHeight ;
72
80
sceneData . heightmapWidth = heightmapWidth ;
73
- sceneData . heightmapResolution = heightmapResolution ;
74
- sceneData . heightmapScale = heightmapScale ;
75
81
sceneData . size = size ;
76
82
sceneData . alphamapWidth = alphamapWidth ;
77
83
sceneData . alphamapHeight = alphamapHeight ;
@@ -84,27 +90,45 @@ public override SceneComponent GetObjectData()
84
90
sceneData . alphamapTexture = new SceneTexture ( ) ;
85
91
sceneData . alphamapTexture . base64PNG = base64Alpha ;
86
92
sceneData . alphamapTexture . base64PNGLength = base64AlphaLength ;
93
+
94
+ if ( textures . Count > 0 )
95
+ {
96
+ sceneData . textureIDs = new int [ textures . Count ] ;
97
+ for ( int i = 0 ; i < textures . Count ; i ++ )
98
+ sceneData . textureIDs [ i ] = textures [ i ] . uniqueID ;
99
+
100
+ sceneData . textureTilingOffsets = new Vector4 [ textures . Count ] ;
101
+ for ( int i = 0 ; i < textures . Count ; i ++ )
102
+ {
103
+ Vector2 sc = textureSizes [ i ] , of = textureOffsets [ i ] ;
104
+ sceneData . textureTilingOffsets [ i ] = new Vector4 ( sc . x , sc . y , of . x , of . y ) ;
105
+ }
106
+ }
107
+
108
+ if ( terrain != null )
109
+ {
110
+ sceneData . lightmapIndex = terrain . lightmapIndex ;
111
+ sceneData . lightmapTilingOffset = terrain . lightmapScaleOffset ;
112
+ }
87
113
return sceneData ;
88
114
}
89
115
90
116
public Terrain terrain ;
91
117
private TerrainData terrainData ;
92
118
93
- int heightmapHeight ;
94
- int heightmapWidth ;
95
- int heightmapResolution ;
96
- Vector3 heightmapScale ;
97
119
Vector3 size ;
98
-
99
- int alphamapWidth ;
100
- int alphamapHeight ;
101
- int alphamapLayers ;
120
+ int heightmapHeight , heightmapWidth ;
121
+ int alphamapWidth , alphamapHeight , alphamapLayers ;
102
122
103
123
public string base64Height ;
104
124
public int base64HeightLength ;
105
125
106
126
public string base64Alpha ;
107
127
public int base64AlphaLength ;
128
+
129
+ public List < BundleTexture > textures = new List < BundleTexture > ( ) ;
130
+ public List < Vector2 > textureSizes = new List < Vector2 > ( ) ;
131
+ public List < Vector2 > textureOffsets = new List < Vector2 > ( ) ;
108
132
}
109
133
110
134
}
0 commit comments