⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maxloader.java

📁 world wind java sdk load 3D model
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                case TYPE_MAT_XPFALL:
                    float xpf = readPercentage(currentChunk);
                    break;
                    
                case TYPE_MAT_REFBLUR:
                    float ref = readPercentage(currentChunk);
                    break;
                    
                case TYPE_MAT_SELF_ILPCT:
                    float il = readPercentage(currentChunk);
                    break;
                    
                case TYPE_MAT_SHADING:
                    short shading = readShort(currentChunk);
                    // Some kind of code for the rendering type: 1, 3, 4, etc.
                    break;
                    
                case TYPE_MAT_TEXMAP:
                    processMaterial(material, currentChunk);
                    readBytes(currentChunk, currentChunk.length - currentChunk.bytesRead);
                    break;
                    
                case TYPE_MAT_MAPNAME:
                    material.file = baseDir + readString(currentChunk);
                    readBytes(currentChunk, currentChunk.length - currentChunk.bytesRead);
                    break;
                    
                default:
                    readBytes(currentChunk, currentChunk.length - currentChunk.bytesRead);
                    break;
            }
            
            root.bytesRead += currentChunk.bytesRead;
        }
        
        currentChunk = root;
    }
    
    private void readObjectMaterial(Model3D.ModelObject object, Chunk root) throws IOException {
        String strMaterial = null;
        byte buffer[] = null;
        
        strMaterial = readString(root);
        
        for (int i=0; i<model.getNumberOfMaterials(); i++) {
            if (strMaterial.equals(model.getMaterial(i).name)) {
                object.materialID = i;
                Model3D.Material mat = model.getMaterial(i);
                if (mat.file != null)
                    object.hasTexture = true;
                break;
            }
        }
    }
    
    private void readUVCoordinates(Model3D.ModelObject object, Chunk root) throws IOException {
        int numTexVertex = readShort(root);
        
        object.texVerts = new Model3D.TexCoord[numTexVertex];
        for (int i=0; i<numTexVertex; i++)
            object.texVerts[i] = readPoint(root);
    }
    
    private void readVertices(Model3D.ModelObject object, Chunk root) throws IOException {
        int numOfVerts = readShort(root);
        
        object.verts = new Model3D.Vector3f[numOfVerts];
        for (int i=0; i<numOfVerts; i++)
            object.verts[i] = readVertex(root);
    }
    
    private void readFaceList(Model3D.ModelObject object, Chunk root) throws IOException {
        short index = 0;
        
        int numOfFaces = readShort(root);
        
        object.faces = new Model3D.Face[numOfFaces];
        for (int i=0; i<numOfFaces; i++) {
            object.faces[i] = new Model3D.Face();
            object.faces[i].vertIndex[0] = readShort(root);
            object.faces[i].vertIndex[1] = readShort(root);
            object.faces[i].vertIndex[2] = readShort(root);
            
            object.faces[i].coordIndex[0] = object.faces[i].vertIndex[0];
            object.faces[i].coordIndex[1] = object.faces[i].vertIndex[1];
            object.faces[i].coordIndex[2] = object.faces[i].vertIndex[2];
            
            
            // Read in the extra face info
            readShort(root); // Flags (?)
        }
    }
    
    /**
     * Reads a color from the input file.
     */
    protected Color readColor(Chunk c) throws IOException {
        Color color = null;
        
        readChunkHeader(tempChunk);
        switch(tempChunk.id) {
            case TYPE_COLOR_F:
            case TYPE_COLOR_LIN_F:
                color = new Color(readFloat(c),readFloat(c),readFloat(c));
            case TYPE_COLOR_I:
            case TYPE_COLOR_LIN_I:
                color = new Color(readUnsignedByte(c),readUnsignedByte(c),readUnsignedByte(c));
        }
        
        c.bytesRead += tempChunk.bytesRead;
        
        return color;
    }
    
    /**
     * Reads a percentage value from the input file.  Returns as a float
     * between 0 and 1.
     */
    protected float readPercentage(Chunk c) throws IOException {
        float value = 0;
        readChunkHeader(tempChunk);
        
        if (tempChunk.id == TYPE_PERCENT_I) {
            value = (float)readShort(c) / 100.0f;
        } else if(tempChunk.id == TYPE_PERCENT_F) {
            value = readFloat(c);
        }
        
        c.bytesRead += tempChunk.bytesRead;
        
        return value;
    }
    
    /**
     * Reads a String value from the input file.
     */
    protected String readString(Chunk c) throws IOException {
        DataInputStream in = dataInputStream;
        StringBuffer sb = new StringBuffer("");
        c.bytesRead++;
        byte ch = in.readByte();
        while(ch != (byte)0) {
            sb.append((char)ch);
            c.bytesRead++;
            ch = in.readByte();
        }
        return sb.toString();
    }
    
    protected byte[] readBytes(Chunk c, int num) throws IOException {
        byte[] buffer = new byte[num];
        c.bytesRead += dataInputStream.read(buffer, 0, num);
        return buffer;
    }
    
    /**
     * Reads a byte (8-bit) value from the input file.
     */
    protected byte readByte(Chunk c) throws IOException {
        c.bytesRead++;
        return dataInputStream.readByte();
    }
    
    /**
     * Reads an unsigned byte (8-bit) value from the input file.
     */
    protected int readUnsignedByte(Chunk c) throws IOException {
        c.bytesRead++;
        return dataInputStream.readUnsignedByte();
    }
    
    /**
     * Reads a short (16-bit) value from the input file.
     */
    protected short readShort(Chunk c) throws IOException {
        c.bytesRead += 2;
        return (short)(dataInputStream.read()+(dataInputStream.read() << 8));
    }
    
    /**
     * Reads an int (32-bit) value from the input file.
     */
    private int readInt(Chunk c) throws IOException {
        DataInputStream in = dataInputStream;
        c.bytesRead += 4;
        return (int)(in.read() + (in.read() << 8) + (in.read() << 16) + (in.read() << 24));
    }
    
    private float readFloat(Chunk c) throws IOException {
        return Float.intBitsToFloat(readInt(c));
    }
    
    private Model3D.Vector3f readVertex(Chunk c) throws IOException {
        float x = readFloat(c);
        float y = readFloat(c);
        float z = readFloat(c);
        
        if(x < minx) {
            minx = x;
        } else if(x > maxx) {
            maxx = x;
        }
        if(y < miny) {
            miny = y;
        } else if(y > maxy) {
            maxy = y;
        }
        if(z < minz) {
            minz = z;
        } else if(z > maxz) {
            maxz = z;
        }
        
        return new Model3D.Vector3f(x, y, z);
    }
    
    private Model3D.TexCoord readPoint(Chunk c) throws IOException {
        return new Model3D.TexCoord(readFloat(c), readFloat(c));
    }
    
    /**
     * Gets a type as a Hex string.
     */
    protected static String getTypeString(short type) {
        String temp = Integer.toHexString(type);
        int length = temp.length();
        if(length > 4) {
            return temp.substring(length-4, length);
        } else {
            return temp;
        }
    }
    
    private class Chunk {
        public short id = 0;
        public int length = 0;
        public int bytesRead = 0;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -