SEA3DGC.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * SEA3D - o3dgc
  3. * @author Sunag / http://www.sunag.com.br/
  4. */
  5. 'use strict';
  6. //
  7. // Lossy Compression
  8. //
  9. SEA3D.GeometryGC = function ( name, data, sea3d ) {
  10. this.name = name;
  11. this.data = data;
  12. this.sea3d = sea3d;
  13. var i;
  14. var attrib = data.readUShort();
  15. var uvIDs = [], jointID, weightID;
  16. this.isBig = ( attrib & 1 ) != 0;
  17. data.readVInt = this.isBig ? data.readUInt : data.readUShort;
  18. // Geometry Flags
  19. // ..
  20. // 1 isBig
  21. // 2 groups
  22. // 4 uv
  23. // 8 tangent
  24. // 16 colors
  25. // 32 joints
  26. // 64 morph
  27. // 128 vertex-animation
  28. // ..
  29. if ( attrib & 2 ) {
  30. this.groups = [];
  31. var numGroups = data.readUByte(),
  32. groupOffset = 0;
  33. for ( i = 0; i < numGroups; i ++ ) {
  34. var groupLength = data.readVInt() * 3;
  35. this.groups.push( {
  36. start: groupOffset,
  37. count: groupLength,
  38. } );
  39. groupOffset += groupLength;
  40. }
  41. } else {
  42. this.groups = [];
  43. }
  44. if ( attrib & 4 ) {
  45. this.uv = [];
  46. var uvCount = data.readUByte();
  47. for ( i = 0; i < uvCount; i ++ ) {
  48. uvIDs[ i ] = data.readUByte();
  49. }
  50. }
  51. if ( attrib & 32 ) {
  52. jointID = data.readUByte();
  53. weightID = data.readUByte();
  54. }
  55. var size = data.readUInt();
  56. var bytes = data.concat( data.position, size );
  57. var bstream = new o3dgc.BinaryStream( bytes.buffer );
  58. var decoder = new o3dgc.SC3DMCDecoder();
  59. var ifs = new o3dgc.IndexedFaceSet();
  60. decoder.DecodeHeader( ifs, bstream );
  61. var numIndexes = ifs.GetNCoordIndex();
  62. var numVertex = ifs.GetNCoord();
  63. if ( ! this.groups.length ) this.groups.push( { start: 0, count: numIndexes * 3 } );
  64. this.indexes = this.isBig ? new Uint32Array( numIndexes * 3 ) : new Uint16Array( numIndexes * 3 );
  65. this.vertex = new Float32Array( numVertex * 3 );
  66. ifs.SetCoordIndex( this.indexes );
  67. ifs.SetCoord( this.vertex );
  68. if ( ifs.GetNNormal() > 0 ) {
  69. this.normal = new Float32Array( numVertex * 3 );
  70. ifs.SetNormal( this.normal );
  71. }
  72. for ( i = 0; i < uvIDs.length; i ++ ) {
  73. this.uv[ i ] = new Float32Array( numVertex * 2 );
  74. ifs.SetFloatAttribute( uvIDs[ i ], this.uv[ i ] );
  75. }
  76. if ( jointID !== undefined ) {
  77. this.jointPerVertex = ifs.GetIntAttributeDim( jointID );
  78. this.joint = new Uint16Array( numVertex * this.jointPerVertex );
  79. this.weight = new Float32Array( numVertex * this.jointPerVertex );
  80. ifs.SetIntAttribute( jointID, this.joint );
  81. ifs.SetFloatAttribute( weightID, this.weight );
  82. }
  83. // decode mesh
  84. decoder.DecodePlayload( ifs, bstream );
  85. };
  86. SEA3D.GeometryGC.prototype.type = "s3D";
  87. //
  88. // Extension
  89. //
  90. THREE.SEA3D.EXTENSIONS_LOADER.push( {
  91. setTypeRead: function () {
  92. this.file.addClass( SEA3D.GeometryGC, true );
  93. this.file.typeRead[ SEA3D.GeometryGC.prototype.type ] = this.readGeometryBuffer;
  94. }
  95. } );