File size: 2,711 Bytes
6cd9596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
 * 	SEA3D - o3dgc
 * 	@author Sunag / http://www.sunag.com.br/
 */

'use strict';

//
//	Lossy Compression
//

SEA3D.GeometryGC = function ( name, data, sea3d ) {

	this.name = name;
	this.data = data;
	this.sea3d = sea3d;

	var i;
	var attrib = data.readUShort();
	var uvIDs = [], jointID, weightID;

	this.isBig = ( attrib & 1 ) != 0;

	data.readVInt = this.isBig ? data.readUInt : data.readUShort;

	// Geometry Flags
	// ..
	// 1 isBig
	// 2 groups
	// 4 uv
	// 8 tangent
	// 16 colors
	// 32 joints
	// 64 morph
	// 128 vertex-animation
	// ..

	if ( attrib & 2 ) {

		this.groups = [];

		var numGroups = data.readUByte(),
			groupOffset = 0;

		for ( i = 0; i < numGroups; i ++ )		{

			var groupLength = data.readVInt() * 3;

			this.groups.push( {
				start: groupOffset,
				count: groupLength,
			} );

			groupOffset += groupLength;

		}

	} else {

		this.groups = [];

	}

	if ( attrib & 4 ) {

		this.uv = [];

		var uvCount = data.readUByte();

		for ( i = 0; i < uvCount; i ++ ) {

			uvIDs[ i ] = data.readUByte();

		}

	}

	if ( attrib & 32 ) {

		jointID = data.readUByte();
		weightID = data.readUByte();

	}

	var size = data.readUInt();
	var bytes = data.concat( data.position, size );

	var bstream = new o3dgc.BinaryStream( bytes.buffer );

	var decoder = new o3dgc.SC3DMCDecoder();
	var ifs = new o3dgc.IndexedFaceSet();

	decoder.DecodeHeader( ifs, bstream );

	var numIndexes = ifs.GetNCoordIndex();
	var numVertex = ifs.GetNCoord();

	if ( ! this.groups.length ) this.groups.push( { start: 0, count: numIndexes * 3 } );

	this.indexes = this.isBig ? new Uint32Array( numIndexes * 3 ) : new Uint16Array( numIndexes * 3 );
	this.vertex = new Float32Array( numVertex * 3 );

	ifs.SetCoordIndex( this.indexes );
	ifs.SetCoord( this.vertex );

	if ( ifs.GetNNormal() > 0 ) {

		this.normal = new Float32Array( numVertex * 3 );
		ifs.SetNormal( this.normal );

	}

	for ( i = 0; i < uvIDs.length; i ++ ) {

		this.uv[ i ] = new Float32Array( numVertex * 2 );
		ifs.SetFloatAttribute( uvIDs[ i ], this.uv[ i ] );

	}

	if ( jointID !== undefined ) {

		this.jointPerVertex = ifs.GetIntAttributeDim( jointID );

		this.joint = new Uint16Array( numVertex * this.jointPerVertex );
		this.weight = new Float32Array( numVertex * this.jointPerVertex );

		ifs.SetIntAttribute( jointID, this.joint );
		ifs.SetFloatAttribute( weightID, this.weight );

	}

	// decode mesh

	decoder.DecodePlayload( ifs, bstream );

};

SEA3D.GeometryGC.prototype.type = "s3D";

//
//	Extension
//

THREE.SEA3D.EXTENSIONS_LOADER.push( {

	setTypeRead: function () {

		this.file.addClass( SEA3D.GeometryGC, true );

		this.file.typeRead[ SEA3D.GeometryGC.prototype.type ] = this.readGeometryBuffer;

	}

} );