Package org.eaxy

Examples of org.eaxy.Element


    protected SkeletalMeshDataBuilder skeletonBuilder;

    protected void parseSkeletalMeshData(InputStream inputStream) throws ColladaParseException, IOException {
        Document document = Xml.readAndClose(inputStream);
        Element rootElement = document.getRootElement();

        parseMeshData(rootElement);
        parseSkeletalMeshData(rootElement);
    }
View Full Code Here


        parseSkeletalMeshData(rootElement);
    }

    protected void parseMeshData(InputStream inputStream) throws ColladaParseException, IOException {
        Document document = Xml.readAndClose(inputStream);
        Element rootElement = document.getRootElement();

        parseMeshData(rootElement);
    }
View Full Code Here

        for (Element controller : controllerSet) {
            ElementSet skinSet = controller.find("skin");
            if (1 != skinSet.size()) {
                throw new ColladaParseException("Found " + skinSet.size() + " skin sets for controller id=" + controller.id() + " name=" + controller.name());
            }
            Element skin = skinSet.first();

            ElementSet jointsSet = skin.find("joints");
            if (1 != jointsSet.size()) {
                throw new ColladaParseException("Found " + jointsSet.size() + " joints sets for controller id=" + controller.id() + " name=" + controller.name());
            }
            Element joints = jointsSet.first();

            ElementSet vertexWeightsSet = skin.find("vertex_weights");
            if (1 != vertexWeightsSet.size()) {
                throw new ColladaParseException("Found " + vertexWeightsSet.size() + " vertex weights sets for controller id=" + controller.id() + " name="
                                                + controller.name());
            }
            Element vertexWeights = vertexWeightsSet.first();
            String vertexWeightsCountString = vertexWeights.attr("count");
            int vertexWeightsCount = Integer.parseInt(vertexWeightsCountString);

            String[] jointNameArray = null;
            float[] inverseBindMatrixArray;
            Quat4f[] rotationArray;
            ElementSet jointsInputSet = joints.find("input");
            List<Input> inputList = parseInputs(jointsInputSet);
            for (Input jointsInput : inputList) {
                if ("JOINT".equals(jointsInput.semantic)) {
                    Element jointNameSourceElement = skin.select(jointsInput.sourceName);
                    Source jointNameSource = parseSource(jointNameSourceElement);
                    jointNameArray = jointNameSource.nameValues;
                }
                if ("INV_BIND_MATRIX".equals(jointsInput.semantic)) {
                    Element jointMatrixSourceElement = skin.select(jointsInput.sourceName);
                    Source jointMatrixSource = parseSource(jointMatrixSourceElement);
                    inverseBindMatrixArray = jointMatrixSource.floatValues;

                    rotationArray = quad4fArrayFromFloat16ArrayData(inverseBindMatrixArray);
                }
            }

            List<MD5Weight> md5WeightList = Lists.newArrayList();

            float[] weightsArray = null;

            ElementSet vertexWeightsInputSet = vertexWeights.find("input");
            List<Input> vertexWeightsInputList = parseInputs(vertexWeightsInputSet);

            // TODO: for now, assume the offsets will always perfectly match the sorted-by-offset list indexes
            Collections.sort(vertexWeightsInputList, new Comparator<Input>() {
                @Override
                public int compare(Input i1, Input i2) {
                    return i1.offset - i2.offset;
                }
            });
            for (int i = 0; i < vertexWeightsInputList.size(); i++) {
                Input input = vertexWeightsInputList.get(i);
                if (input.offset != i) {
                    throw new ColladaParseException("vertex weights input list offset does not match list index for vertex weights input " + input
                                                    + " for controller id=" + controller.id() + " name=" + controller.name());
                }
            }

            for (Input vertexWeightsInput : vertexWeightsInputList) {
                //                if ("JOINT".equals(vertexWeightsInput.semantic)) {
                //                    Element jointNameSourceElement =  skin.select(vertexWeightsInput.sourceName);
                //                    Source jointNameSource = parseSource(jointNameSourceElement);
                //                    jointNameArray = jointNameSource.nameValues;
                //                }
                if ("WEIGHT".equals(vertexWeightsInput.semantic)) {
                    Element jointMatrixSourceElement = skin.select(vertexWeightsInput.sourceName);
                    Source weightsArraySource = parseSource(jointMatrixSourceElement);
                    weightsArray = weightsArraySource.floatValues;
                }
            }

            ElementSet vertexWeightsVCountDataSet = vertexWeights.find("vcount");
            if (1 != vertexWeightsVCountDataSet.size()) {
                throw new ColladaParseException("Found " + vertexWeightsVCountDataSet.size()
                                                + " vertex weights vcount sets for controller id=" + controller.id() + " name=" + controller.name());
            }
            Element vertexWeightsVCountData = vertexWeightsVCountDataSet.first();
            String vertexWeightsVCountString = vertexWeightsVCountData.text();
            String[] vertexWeightsVCountStrings = getItemsInString(vertexWeightsVCountString);
            if (vertexWeightsVCountStrings.length != vertexWeightsCount) {
                throw new ColladaParseException("Expected " + vertexWeightsCount + " but was "
                                                + vertexWeightsVCountStrings.length + " for controller id=" + controller.id() + " name=" + controller.name());
            }

            ElementSet vertexWeightsVDataSet = vertexWeights.find("v");
            if (1 != vertexWeightsVDataSet.size()) {
                throw new ColladaParseException("Found " + vertexWeightsVDataSet.size()
                                                + " vertex weights v sets for controller id=" + controller.id() + " name=" + controller.name());
            }
            Element vertexWeightsVData = vertexWeightsVDataSet.first();
            String vertexWeightsVDataString = vertexWeightsVData.text();
            String[] vertexWeightsVStrings = getItemsInString(vertexWeightsVDataString);
            //            if (vertexWeightsVStrings.length != (vertexWeightsCount * vertexWeightsInputList.size())) {
            //                throw new ColladaParseException("Expected " + vertexWeightsCount + " * input count of "
            //                                                + vertexWeightsInputList.size() + " but was "
            //                                                + vertexWeightsVStrings.length + " for controller id=" + controller.id() + " name=" + controller.name());
View Full Code Here

    private MD5Joint createMD5Joint(Element jointNodeElement) throws ColladaParseException {
        MD5Joint md5Joint = new MD5Joint();

        ElementSet matrixSet = jointNodeElement.find("matrix");
        if (1 == matrixSet.size()) {
            Element matrix = matrixSet.first();

            String floatStringArray = matrix.text();
            String[] floatStrings = getItemsInString(floatStringArray);
            if (floatStrings.length != 16) {
                throw new ColladaParseException("Found float list of " + floatStrings.length + " instead of 16 for joint matrix sets for element " + jointNodeElement.id());
            }
            float[] matrixDataArray = new float[16];
View Full Code Here

        ElementSet upAxisSet = rootElement.find("asset", "up_axis");
        if (1 != upAxisSet.size()) {
            throw new ColladaParseException("Found multiple up_axis asset values");
        }
        Element upAxisElement = upAxisSet.first();
        String upAxis = upAxisElement.text();

        ElementSet unitSet = rootElement.find("asset", "unit");
        if (1 != unitSet.size()) {
            throw new ColladaParseException("Found multiple unit asset values");
        }
        Element unitElement = unitSet.first();
        String unitsPerMeterString = unitElement.attr("meter");
        if (null != unitsPerMeterString) {
            unitsPerMeter = Double.parseDouble(unitsPerMeterString);
        }

        boolean yUp = "Y_UP".equals(upAxis);
        boolean zUp = "Z_UP".equals(upAxis);
        boolean xUp = "X_UP".equals(upAxis);
        if (xUp) {
            throw new ColladaParseException("Not supporting X_UP as the upAxis value yet.");
        }

        // TODO: we shouldn't just cram everything into a single mesh, but should expect separate meshes with differing materials

        ElementSet geometrySet = rootElement.find("library_geometries", "geometry");
        for (Element geometry : geometrySet) {

            ElementSet meshSet = geometry.find("mesh");

            if (1 != meshSet.size()) {
                throw new ColladaParseException("Found " + meshSet.size() + " mesh sets for geometry id=" + geometry.id() + " name=" + geometry.name());
            }

            logger.info("Parsing geometry id=" + geometry.id() + " name=" + geometry.name());

            for (Element mesh : meshSet) {

                ElementSet trianglesSet = mesh.find("triangles");
                for (Element triangles : trianglesSet) {
                    vertCount = parseTriangles(rootElement, vertices, texCoord0,
                            normals, indices, colors,
                            vertCount, geometry, mesh, triangles,
                            yUp, zUp);
                }

                ElementSet polylistSet = mesh.find("polylist");
                for (Element polylist : polylistSet) {

                    ElementSet vCountSet = polylist.find("vcount");
                    if (1 != vCountSet.size()) {
                        throw new ColladaParseException("Found " + vCountSet.size() + " vcount sets for polylist in geometry id="
                                                        + geometry.id() + " name=" + geometry.name());
                    }
                    Element vCountElement = vCountSet.first();

                    TIntList vcountList = new TIntArrayList();
                    String[] vCountStrings = getItemsInString(vCountElement.text());
                    for (String string : vCountStrings) {

                        int vCount = Integer.parseInt(string);
                        vcountList.add(vCount);
                    }
View Full Code Here

        if (0 != libraryMaterialsSet.size()) {
            if (1 != libraryMaterialsSet.size()) {
                throw new ColladaParseException("Found " + libraryMaterialsSet.size() + " library Material sets for geometry id="
                                                + geometry.id() + " name=" + geometry.name());
            }
            Element libraryMaterials = libraryMaterialsSet.first();

            Element material;
            try {
                // TODO: this one isn't standard like the others, and sometimes it doesn't exist
                material = libraryMaterials.select("#" + facesMaterial);
                if (null == material) {
                    throw new ColladaParseException("No material for " + facesMaterial + " for geometry id=" + geometry.id() + " name=" + geometry.name());
                }
                ElementSet instanceEffectSet = material.find("instance_effect");
                if (1 != instanceEffectSet.size()) {
                    throw new ColladaParseException("Found " + instanceEffectSet.size() + " instance_effect sets for material " + facesMaterial + " for geometry id="
                                                    + geometry.id() + " name=" + geometry.name());
                }
                Element instanceEffect = instanceEffectSet.first();

                String effectUrl = instanceEffect.attr("url");

                ElementSet libraryEffectsSet = rootElement.find("library_effects");
                if (0 != libraryEffectsSet.size()) {
                    if (1 != libraryEffectsSet.size()) {
                        throw new ColladaParseException("Found " + libraryEffectsSet.size() + " library effects sets for geometry id=" + geometry.id() + " name="
                                                        + geometry.name());
                    }
                    Element libraryEffects = libraryEffectsSet.first();

                    Element effect = libraryEffects.select(effectUrl);
                    if (null == effect) {
                        throw new ColladaParseException("No effect for " + effectUrl + " for geometry id=" + geometry.id() + " name=" + geometry.name());
                    }

                    ElementSet colorSet = effect.find("profile_COMMON", "technique", "lambert", "diffuse", "color");
                    if (1 == colorSet.size()) {
                        Element color = colorSet.first();

                        String colorListString = color.text();
                        String[] colorString = getItemsInString(colorListString);
                        if (4 != colorString.length) {
                            throw new ColladaParseException("mesh only supports 4-float color arrays but color list was '" + colorListString + "' for geometry id="
                                                            + geometry.id() + " name=" + geometry.name());
                        }
                        vertexColors = new float[colorString.length];
                        for (int i = 0; i < colorString.length; i++) {
                            vertexColors[i] = Float.parseFloat(colorString[i]);
                        }
                    }
                }
            } catch (NonMatchingPathException e) {
                // If we don't find the material, then we're done.
            }
        }

        for (Input faceInput : faceInputs) {
            if ("VERTEX".equals(faceInput.semantic)) {
                ElementSet verticesSet = mesh.find("vertices");
                if (1 != verticesSet.size()) {
                    throw new ColladaParseException("Found " + verticesSet.size() + " vertices sets for geometry id=" + geometry.id() + " name=" + geometry.name());
                }
                Element verticesElement = verticesSet.first();
                ElementSet verticesInputSet = verticesElement.find("input");
                List<Input> verticesInputs = parseInputs(verticesInputSet);
                for (Input vertexInput : verticesInputs) {
                    if ("POSITION".equals(vertexInput.semantic)) {
                        Element vertexSourceElement = mesh.select(vertexInput.sourceName);
                        faceInput.vertexPositionSource = parseSource(vertexSourceElement);
                    } else if ("NORMAL".equals(vertexInput.semantic)) {
                        Element normalSourceElement = mesh.select(vertexInput.sourceName);
                        faceInput.vertexNormalSource = parseSource(normalSourceElement);
                    } else {
                        throw new ColladaParseException("Found unexpected vertex Input semantic " + vertexInput.semantic +
                                                        " for geometry id=" + geometry.id() + " name=" + geometry.name());
                    }
                }
            } else if ("NORMAL".equals(faceInput.semantic)) {
                Element normalSourceElement = mesh.select(faceInput.sourceName);
                faceInput.normalSource = parseSource(normalSourceElement);
                if (3 != faceInput.normalSource.stride) {
                    throw new ColladaParseException("Found stride of " + faceInput.normalSource.stride
                                                    + " for triangle Input semantic " + faceInput.semantic +
                                                    " for geometry id=" + geometry.id() + " name=" + geometry.name());
                }
            } else if ("TEXCOORD".equals(faceInput.semantic)) {
                Element texCoordSourceElement = mesh.select(faceInput.sourceName);
                faceInput.texCoordSource = parseSource(texCoordSourceElement);

                if (2 != faceInput.texCoordSource.stride) {
                    logger.warn("Found non-2 stride of " + faceInput.texCoordSource.stride
                                + " for vertex Input semantic " + faceInput.semantic +
                                " for geometry id=" + geometry.id() + " name=" + geometry.name()
                                + ". Ignoring all but first two texture coordinate values.");
                }

            } else {
                throw new ColladaParseException("Found unexpected triangle Input semantic " + faceInput.semantic +
                                                " for geometry id=" + geometry.id() + " name=" + geometry.name());
            }
        }
        ElementSet faceDataSet = faces.find("p");
        if (1 != faceDataSet.size()) {
            throw new ColladaParseException("Found " + faceDataSet.size() + " triangleData sets for geometry id=" + geometry.id() + " name=" + geometry.name());
        }
        Element faceData = faceDataSet.first();
        String faceDataString = faceData.text();
        String[] facesStrings = getItemsInString(faceDataString);

        // TODO: for now, assume the offsets will always perfectly match the sorted-by-offset list indexes
        Collections.sort(faceInputs, new Comparator<Input>() {
            @Override
View Full Code Here

        ElementSet accessorSet = sourceElement.find("technique_common", "accessor");
        if (1 != accessorSet.size()) {
            throw new ColladaParseException("Found " + accessorSet.size() + " accessor sets for sourceElement id=" + sourceElement.id() + " name=" + sourceElement.name());
        }
        Element accessor = accessorSet.first();
        String accessorCount = accessor.attr("count");
        source.count = Integer.parseInt(accessorCount);
        String accessorStride = accessor.attr("stride");
        if (null != accessorStride) {
            source.stride = Integer.parseInt(accessorStride);
        }
        String accessorSource = accessor.attr("source");
        source.accessorSource = accessorSource;

        ElementSet paramSet = accessor.find("param");
        int paramSize = paramSet.size();
        source.parameterNames = new String[paramSize];
        source.parameterTypes = new String[paramSize];
        for (int i = 0; i < paramSize; i++) {
            Element param = paramSet.get(i);
            source.parameterNames[i] = param.attr("name");
            source.parameterTypes[i] = param.attr("type");
        }

        Element objectArray = sourceElement.select(accessorSource);
        if (null == objectArray) {
            throw new ColladaParseException("Unable to find id " + accessorSource + " for float array in sourceElement id=" + sourceElement.id() + " name="
                                            + sourceElement.name());
        }
        String arraySizeString = objectArray.attr("count");
        int arraySize = Integer.parseInt(arraySizeString);
        String objectArrayDataString = objectArray.text().trim();

        // TODO: we should really parse each parameter type, but we'll assume they are homogeneneous for now
        if (("float".equalsIgnoreCase(source.parameterTypes[0]))
            || ("float4x4".equalsIgnoreCase(source.parameterTypes[0]))) {
            source.floatValues = new float[arraySize];
View Full Code Here

TOP

Related Classes of org.eaxy.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.