mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Use double precision instead of float for terrain asset (#13920)
This commit is contained in:
@@ -46,6 +46,7 @@ export const TERRAIN_DATA_VERSION3 = 0x01010003;
|
||||
export const TERRAIN_DATA_VERSION4 = 0x01010004;
|
||||
export const TERRAIN_DATA_VERSION5 = 0x01010005;
|
||||
export const TERRAIN_DATA_VERSION6 = 0x01010006;
|
||||
export const TERRAIN_DATA_VERSION7 = 0x01010007;
|
||||
export const TERRAIN_DATA_VERSION_DEFAULT = 0x01010111;
|
||||
|
||||
class TerrainBuffer {
|
||||
@@ -126,6 +127,22 @@ class TerrainBuffer {
|
||||
this.length += 4 * value.length;
|
||||
}
|
||||
|
||||
public writeDouble (value: number) {
|
||||
this.reserve(this.length + 8);
|
||||
|
||||
this._buffView.setFloat64(this.length, value, true);
|
||||
this.length += 8;
|
||||
}
|
||||
|
||||
public writeDoubleArray (value: number[]) {
|
||||
this.reserve(this.length + 8 * value.length);
|
||||
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
this._buffView.setFloat64(this.length + i * 8, value[i], true);
|
||||
}
|
||||
this.length += 8 * value.length;
|
||||
}
|
||||
|
||||
public writeString (value: string) {
|
||||
this.reserve(this.length + value.length + 4);
|
||||
|
||||
@@ -176,6 +193,20 @@ class TerrainBuffer {
|
||||
return value;
|
||||
}
|
||||
|
||||
public readDouble () {
|
||||
const value = this._buffView.getFloat64(this._seekPos, true);
|
||||
this._seekPos += 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
public readDoubleArray (value: number[]) {
|
||||
for (let i = 0; i < value.length; ++i) {
|
||||
value[i] = this._buffView.getFloat64(this._seekPos + i * 4, true);
|
||||
}
|
||||
this._seekPos += 8 * value.length;
|
||||
return value;
|
||||
}
|
||||
|
||||
public readString () {
|
||||
const length = this.readInt();
|
||||
|
||||
@@ -443,12 +474,17 @@ export class TerrainAsset extends Asset {
|
||||
&& this._version !== TERRAIN_DATA_VERSION3
|
||||
&& this._version !== TERRAIN_DATA_VERSION4
|
||||
&& this._version !== TERRAIN_DATA_VERSION5
|
||||
&& this._version !== TERRAIN_DATA_VERSION6) {
|
||||
&& this._version !== TERRAIN_DATA_VERSION6
|
||||
&& this._version !== TERRAIN_DATA_VERSION7) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// geometry info
|
||||
this.tileSize = stream.readFloat();
|
||||
if (this._version >= TERRAIN_DATA_VERSION7) {
|
||||
this.tileSize = stream.readDouble();
|
||||
} else {
|
||||
this.tileSize = stream.readFloat();
|
||||
}
|
||||
this.tileSize = Math.floor(this.tileSize * 100) / 100.0;
|
||||
|
||||
stream.readIntArray(this._blockCount);
|
||||
@@ -494,13 +530,22 @@ export class TerrainAsset extends Asset {
|
||||
for (let i = 0; i < this._layerBinaryInfos.length; ++i) {
|
||||
this._layerBinaryInfos[i] = new TerrainLayerBinaryInfo();
|
||||
this._layerBinaryInfos[i].slot = stream.readInt();
|
||||
this._layerBinaryInfos[i].tileSize = stream.readFloat();
|
||||
if (this._version >= TERRAIN_DATA_VERSION7) {
|
||||
this._layerBinaryInfos[i].tileSize = stream.readDouble();
|
||||
} else {
|
||||
this._layerBinaryInfos[i].tileSize = stream.readFloat();
|
||||
}
|
||||
|
||||
this._layerBinaryInfos[i].detailMapId = stream.readString();
|
||||
if (this._version >= TERRAIN_DATA_VERSION4) {
|
||||
this._layerBinaryInfos[i].normalMapId = stream.readString();
|
||||
this._layerBinaryInfos[i].roughness = stream.readFloat();
|
||||
this._layerBinaryInfos[i].metallic = stream.readFloat();
|
||||
if (this._version >= TERRAIN_DATA_VERSION7) {
|
||||
this._layerBinaryInfos[i].roughness = stream.readDouble();
|
||||
this._layerBinaryInfos[i].metallic = stream.readDouble();
|
||||
} else {
|
||||
this._layerBinaryInfos[i].roughness = stream.readFloat();
|
||||
this._layerBinaryInfos[i].metallic = stream.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,10 +560,10 @@ export class TerrainAsset extends Asset {
|
||||
const stream = new TerrainBuffer();
|
||||
|
||||
// version
|
||||
stream.writeInt32(TERRAIN_DATA_VERSION6);
|
||||
stream.writeInt32(TERRAIN_DATA_VERSION7);
|
||||
|
||||
// geometry info
|
||||
stream.writeFloat(this.tileSize);
|
||||
stream.writeDouble(this.tileSize);
|
||||
stream.writeIntArray(this._blockCount);
|
||||
stream.writeInt16(this.weightMapSize);
|
||||
stream.writeInt16(this.lightMapSize);
|
||||
@@ -566,11 +611,11 @@ export class TerrainAsset extends Asset {
|
||||
stream.writeInt32(layerBinaryInfos.length);
|
||||
for (let i = 0; i < layerBinaryInfos.length; ++i) {
|
||||
stream.writeInt32(layerBinaryInfos[i].slot);
|
||||
stream.writeFloat(layerBinaryInfos[i].tileSize);
|
||||
stream.writeDouble(layerBinaryInfos[i].tileSize);
|
||||
stream.writeString(layerBinaryInfos[i].detailMapId);
|
||||
stream.writeString(layerBinaryInfos[i].normalMapId);
|
||||
stream.writeFloat(layerBinaryInfos[i].roughness);
|
||||
stream.writeFloat(layerBinaryInfos[i].metallic);
|
||||
stream.writeDouble(layerBinaryInfos[i].roughness);
|
||||
stream.writeDouble(layerBinaryInfos[i].metallic);
|
||||
}
|
||||
|
||||
return stream.buffer;
|
||||
|
||||
Reference in New Issue
Block a user