📄 geometrydecompressor.java
字号:
curU = -curU ; switch (curSex) { case 0: curSex = 4 ; break ; case 1: curSex = 5 ; break ; case 2: curSex = 3 ; break ; case 3: curSex = 2 ; break ; case 4: curSex = 0 ; break ; case 5: curSex = 1 ; break ; } } else if ((curU >= 0) && (curV < 0)) { // wrap on v, same sextant, different octant curV = -curV ; switch (curSex) { case 1: case 5: curOct = curOct ^ 4 ; // invert x axis break ; case 0: case 4: curOct = curOct ^ 2 ; // invert y axis break ; case 2: case 3: curOct = curOct ^ 1 ; // invert z axis break ; } } else if (curU + curV > 64) { // wrap on uv, same octant, different sextant curU = 64 - curU ; curV = 64 - curV ; switch (curSex) { case 0: curSex = 2 ; break ; case 1: curSex = 3 ; break ; case 2: curSex = 0 ; break ; case 3: curSex = 1 ; break ; case 4: curSex = 5 ; break ; case 5: curSex = 4 ; break ; } } else { throw new IllegalArgumentException (J3dUtilsI18N.getString("GeometryDecompressor1")) ; } } // do optional mesh buffer push if (mbp != 0) { if (debug) System.out.println(" pushing normal into mesh buffer at " + meshIndex) ; meshBuffer[meshIndex].sextant = (short)curSex ; meshBuffer[meshIndex].octant = (short)curOct ; meshBuffer[meshIndex].u = (short)curU ; meshBuffer[meshIndex].v = (short)curV ; } // convert normal back to [-1..1] floating point indexNormal(curSex, curOct, curU, curV, curNorm) ; // a set normal opcode when normals aren't bundled with the vertices // is a global normal change. if (! bundlingNorm) outputNormal(curNorm) ; } // // Get the floating point normal from its sextant, octant, u, and v. // private void indexNormal(int sex, int oct, int u, int v, Vector3f n) { float nx, ny, nz, t ; if (debug) System.out.println(" sextant " + sex + " octant " + oct + " u " + u + " v " + v) ; if (sex > 5) { // special normals switch (oct & 0x1) { case 0: // six coordinate axes switch (((sex & 0x1) << 1) | ((oct & 0x4) >> 2)) { case 0: nx = 1.0f ; ny = nz = 0.0f ; break ; case 1: ny = 1.0f ; nx = nz = 0.0f ; break ; default: case 2: nz = 1.0f ; nx = ny = 0.0f ; break ; } sex = 0 ; oct = (oct & 0x2) >> 1 ; oct = (oct << 2) | (oct << 1) | oct ; break ; case 1: // eight mid default: oct = ((sex & 0x1) << 2) | (oct >> 1) ; sex = 0 ; nx = ny = nz = (float)(1.0/Math.sqrt(3.0)) ; break ; } if ((oct & 0x1) != 0) nz = -nz ; if ((oct & 0x2) != 0) ny = -ny ; if ((oct & 0x4) != 0) nx = -nx ; } else { // regular normals nx = (float)gcNormals[v][u][0] ; ny = (float)gcNormals[v][u][1] ; nz = (float)gcNormals[v][u][2] ; // reverse the swap if ((sex & 0x4) != 0) { t = nx ; nx = nz ; nz = t ; } if ((sex & 0x2) != 0) { t = ny ; ny = nz ; nz = t ; } if ((sex & 0x1) != 0) { t = nx ; nx = ny ; ny = t ; } // reverse the sign flip if ((oct & 0x1) != 0) nz = -nz ; if ((oct & 0x2) != 0) ny = -ny ; if ((oct & 0x4) != 0) nx = -nx ; } // return resulting normal n.set(nx, ny, nz) ; if (debug) System.out.println(" result normal: " + nx + " " + ny + " " + nz) ; } // // Process a set current color command. // private void processSetColor(int mbp) { HuffmanTableEntry gct ; short dr, dg, db, da ; float fR, fG, fB, fA ; int r, g, b, a, index, dataLength ; int ii ; // If the next command is a mesh buffer reference, use this color. meshState &= ~USE_MESH_COLOR ; // Get the huffman table entry. gct = gctables[1][currentHeader & 0x3F] ; if (debug) System.out.println("GeometryDecompressor.processSetColor\n" + gct.toString()) ; // Get the true length of the data. dataLength = gct.dataLength - gct.rightShift ; // Read in red, green, blue, and possibly alpha. r = currentHeader & BMASK[6 - gct.tagLength] ; a = 0 ; if (gct.tagLength + dataLength == 6) { g = getBits(dataLength, "g") ; b = getBits(dataLength, "b") ; if (doingAlpha) a = getBits(dataLength, "a") ; } else if (gct.tagLength + dataLength < 6) { r = r >> (6 - gct.tagLength - dataLength) ; g = currentHeader & BMASK[6-gct.tagLength-dataLength] ; if (gct.tagLength + 2*dataLength == 6) { b = getBits(dataLength, "b") ; if (doingAlpha) a = getBits(dataLength, "a") ; } else if (gct.tagLength + 2*dataLength < 6) { g = g >> (6 - gct.tagLength - 2*dataLength) ; b = currentHeader & BMASK[6-gct.tagLength-2*dataLength] ; if (gct.tagLength + 3*dataLength == 6) { if (doingAlpha) a = getBits(dataLength, "a") ; } else if (gct.tagLength + 3*dataLength < 6) { b = b >> (6 - gct.tagLength - 3*dataLength) ; if (doingAlpha) { a = currentHeader & BMASK[6 - gct.tagLength - 4*dataLength] ; if (gct.tagLength + 4 * dataLength < 6) { a = a >> (6 - gct.tagLength - 3*dataLength) ; } else if (gct.tagLength + 4 * dataLength > 6) { ii = getBits(dataLength - (6-gct.tagLength - 3*dataLength), "a") ; a = (a << (dataLength - (6-gct.tagLength - 3*dataLength))) | ii ; } } } else { ii = getBits(dataLength - (6 - gct.tagLength - 2*dataLength), "b") ; b = (b << (dataLength - (6 - gct.tagLength - 2*dataLength))) | ii ; if (doingAlpha) a = getBits(dataLength, "a") ; } } else { ii = getBits(dataLength - (6 - gct.tagLength - dataLength), "g") ; g = (g << (dataLength - (6 - gct.tagLength - dataLength))) | ii ; b = getBits(dataLength, "b") ; if (doingAlpha) a = getBits(dataLength, "a") ; } } else { ii = getBits(dataLength - (6 - gct.tagLength), "r") ; r = (r << (dataLength - (6 - gct.tagLength))) | ii ; g = getBits(dataLength, "g") ; b = getBits(dataLength, "b") ; if (doingAlpha) a = getBits(dataLength, "a") ; } // Sign extend delta x y z components. r <<= (32 - dataLength) ; r >>= (32 - dataLength) ; g <<= (32 - dataLength) ; g >>= (32 - dataLength) ; b <<= (32 - dataLength) ; b >>= (32 - dataLength) ; a <<= (32 - dataLength) ; a >>= (32 - dataLength) ; // Normalize values. dr = (short)(r << gct.rightShift) ; dg = (short)(g << gct.rightShift) ; db = (short)(b << gct.rightShift) ; da = (short)(a << gct.rightShift) ; // Update current position, first adding deltas if in relative mode. if (gct.absolute != 0) { curR = dr ; curG = dg ; curB = db ; if (doingAlpha) curA = da ; if (debug) System.out.println(" absolute color: r " + curR + " g " + curG + " b " + curB + " a " + curA) ; } else { curR += dr ; curG += dg ; curB += db ; if (doingAlpha) curA += da ; if (debug) System.out.println(" delta color: dr " + dr + " dg " + dg + " db " + db + " da " + da) ; } // Do optional mesh buffer push. if (mbp != 0) { if (debug) System.out.println(" pushing color into mesh buffer at " + meshIndex) ; meshBuffer[meshIndex].r = curR ; meshBuffer[meshIndex].g = curG ; meshBuffer[meshIndex].b = curB ; meshBuffer[meshIndex].a = curA ; } // Convert point back to [-1..1] floating point. fR = curR ; fR /= 32768.0 ; fG = curG ; fG /= 32768.0 ; fB = curB ; fB /= 32768.0 ; fA = curA ; fA /= 32768.0 ; curColor.set(fR, fG, fB, fA) ; if (debug) System.out.println(" result color: " + fR + " " + fG + " " + fB + " " + fA) ; // A set color opcode when colors aren't bundled with the vertices // is a global color change. if (! bundlingColor) outputColor(curColor) ; } // // Process a mesh buffer reference command. // private void processMeshBR() { MeshBufferEntry entry ; int index, normal ; int ii ; if (debug) System.out.println("GeometryDecompressor.processMeshBR") ; ii = getBits(1, "mbr") ; index = (currentHeader >>> 1) & 0xF ; repCode = ((currentHeader & 0x1) << 1) | ii ; // Adjust index to proper place in fifo. index = (meshIndex - index) & 0xf ; if (debug) System.out.println(" using index " + index) ; // Get reference to mesh buffer entry. entry = meshBuffer[index] ; curX = entry.x ; curY = entry.y ; curZ = entry.z ; // Convert point back to [-1..1] floating point. curPos.set(((float)curX)/32768.0f, ((float)curY)/32768.0f, ((float)curZ)/32768.0f) ; if (debug) System.out.println(" retrieved position " + curPos.x + " " + curPos.y + " " + curPos.z + " replace code " + repCode) ; // Get mesh buffer normal if previous opcode was not a setNormal. if (bundlingNorm && ((meshState & USE_MESH_NORMAL) != 0)) { curSex = entry.sextant ; curOct = entry.octant ; curU = entry.u ; curV = entry.v ; // Convert normal back to -1.0 - 1.0 floating point from index. normal = (curSex<<15) | (curOct<<12) | (curU<<6) | curV ; if (debug) System.out.println(" retrieving normal") ; indexNormal(curSex, curOct, curU, curV, curNorm) ; } // Get mesh buffer color if previous opcode was not a setColor. if (bundlingColor && ((meshState & USE_MESH_COLOR) != 0)) { curR = entry.r ; curG = entry.g ; curB = entry.b ; // Convert point back to -1.0 - 1.0 floating point. curColor.x = curR ; curColor.x /= 32768.0 ; curColor.y = curG ; curColor.y /= 32768.0 ; curColor.z = curB ; curColor.z /= 32768.0 ; if (doingAlpha) { curA = entry.a ; curColor.w = curA ; curColor.w /= 32768.0 ; } if (debug) System.out.println(" retrieved color " + curColor.x + " " + curColor.y + " " + curColor.z + " " + curColor.w) ; } // Reset meshState. meshState = 0 ; } // Process a end-of-stream opcode. private void processEos() { if (debug) System.out.println("GeometryDecompressor.processEos") ; } // Process a variable length no-op opcode. private void processVNoop() { int ii, ct ; if (debug) System.out.println("GeometryDecompressor.processVNoop") ; ct = getBits(5, "noop count") ; ii = getBits(ct, "noop bits") ; } // Process a pass-through opcode. private void processPassThrough() { int ignore ; if (debug) System.out.println("GeometryDecompressor.processPassThrough") ; ignore = getBits(24, "passthrough") ; ignore = getBits(32, "passthrough") ; } // Process a skip-8 opcode. private void processSkip8() { int skip ; if (debug) System.out.println("GeometryDecompressor.processSkip8") ; skip = getBits(8, "skip8") ; } private void benchmarkStart(int length) { vertexCount = 0 ; System.out.println(" GeometryDecompressor: decompressing " + length + " bytes...") ; startTime = System.currentTimeMillis() ; } private void benchmarkPrint(int length) { float t = (System.currentTimeMillis() - startTime) / 1000.0f ; System.out.println (" done in " + t + " sec." + "\n" + " decompressed " + vertexCount + " vertices at " + (vertexCount/t) + " vertices/sec\n") ; System.out.print(" vertex data present: coords") ; int floatVertexSize = 12 ; if (bundlingNorm) { System.out.print(" normals") ; floatVertexSize += 12 ; } if (bundlingColor) { System.out.println(" colors") ; floatVertexSize += 12 ; } if (doingAlpha) { System.out.println(" alpha") ; floatVertexSize += 4 ; } System.out.println() ; System.out.println (" bytes of data in generalized strip output: " + (vertexCount * floatVertexSize) + "\n" + " compression ratio: " + (length / (float)(vertexCount * floatVertexSize)) + "\n") ; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -