Search in sources :

Example 1 with IfcProduct

use of org.bimserver.models.ifc2x3tc1.IfcProduct in project BIMserver by opensourceBIM.

the class TestGeometry method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Get the low level interface
        LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
        // Create a new project
        SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        // Checkin file
        long start = System.nanoTime();
        bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, Paths.get("D:\\Dropbox\\Shared\\IFC files\\ArenA 2014\\3D IFC\\arena.ifc"));
        long end = System.nanoTime();
        System.out.println(((end - start) / 1000000) + " ms");
        // Refresh project
        project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
        int nrTriangles = 0;
        // Load model without lazy loading (complete model at once)
        IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, true, true);
        Assert.assertNotNull(model.getModelMetaData().getMinBounds());
        Assert.assertNotNull(model.getModelMetaData().getMaxBounds());
        for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
            GeometryInfo geometryInfo = ifcProduct.getGeometry();
            if (geometryInfo != null) {
                Vector3f minBounds = geometryInfo.getMinBounds();
                Vector3f maxBounds = geometryInfo.getMinBounds();
                Assert.assertNotNull(minBounds);
                Assert.assertNotNull(maxBounds);
                nrTriangles += geometryInfo.getPrimitiveCount();
            }
        }
        Assert.assertEquals(45260, nrTriangles);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Vector3f(org.bimserver.models.geometry.Vector3f) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) LowLevelInterface(org.bimserver.shared.interfaces.LowLevelInterface) Test(org.junit.Test)

Example 2 with IfcProduct

use of org.bimserver.models.ifc2x3tc1.IfcProduct in project BIMserver by opensourceBIM.

the class IfcUtils method listElementQuantities.

public static List<String> listElementQuantities(IfcProduct ifcProduct) {
    List<String> list = new ArrayList<>();
    for (IfcRelDefines ifcRelDefines : ifcProduct.getIsDefinedBy()) {
        if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
            IfcRelDefinesByProperties ifcRelDefinesByProperties = (IfcRelDefinesByProperties) ifcRelDefines;
            IfcPropertySetDefinition propertySetDefinition = ifcRelDefinesByProperties.getRelatingPropertyDefinition();
            if (propertySetDefinition instanceof IfcElementQuantity) {
                IfcElementQuantity ifcElementQuantity = (IfcElementQuantity) propertySetDefinition;
                list.add(ifcElementQuantity.getName());
            }
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) IfcElementQuantity(org.bimserver.models.ifc2x3tc1.IfcElementQuantity) IfcRelDefinesByProperties(org.bimserver.models.ifc2x3tc1.IfcRelDefinesByProperties) IfcPropertySetDefinition(org.bimserver.models.ifc2x3tc1.IfcPropertySetDefinition) IfcRelDefines(org.bimserver.models.ifc2x3tc1.IfcRelDefines)

Example 3 with IfcProduct

use of org.bimserver.models.ifc2x3tc1.IfcProduct in project BIMserver by opensourceBIM.

the class GuidHighlighter method highlightGuids.

private void highlightGuids(IfcModelInterface model, Set<String> highlightedGuids) {
    Set<IdEObject> newObjects = new HashSet<IdEObject>();
    IfcColourRgb gray = Ifc2x3tc1Factory.eINSTANCE.createIfcColourRgb();
    newObjects.add(gray);
    gray.setRed(0.5f);
    gray.setGreen(0.5f);
    gray.setBlue(0.5f);
    Set<IdEObject> toDelete = new HashSet<IdEObject>();
    for (IdEObject object : model.getValues()) {
        if (object instanceof IfcPresentationLayerAssignment) {
            toDelete.add(object);
        }
    }
    IfcPresentationLayerAssignment notSelectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
    notSelectedLayer.setName("Not Selected");
    notSelectedLayer.setIdentifier("Not Selected");
    newObjects.add(notSelectedLayer);
    IfcPresentationLayerAssignment selectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
    selectedLayer.setName("Selected");
    selectedLayer.setIdentifier("Selected");
    newObjects.add(selectedLayer);
    for (IdEObject idEObject : model.getValues()) {
        if (idEObject instanceof IfcProduct) {
            IfcProduct product = (IfcProduct) idEObject;
            String guid = product.getGlobalId();
            boolean hide = true;
            if (guid != null) {
                if (highlightedGuids.contains(guid)) {
                    hide = false;
                }
            }
            if (hide) {
                System.out.println("Hiding " + guid);
                IfcProductRepresentation representation = product.getRepresentation();
                if (representation != null) {
                    for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
                        notSelectedLayer.getAssignedItems().add(ifcRepresentation);
                        for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
                            notSelectedLayer.getAssignedItems().add(ifcRepresentationItem);
                            for (IfcStyledItem ifcStyledItem : ifcRepresentationItem.getStyledByItem()) {
                                for (IfcPresentationStyleAssignment ifcPresentationStyleAssignment : ifcStyledItem.getStyles()) {
                                    for (IfcPresentationStyleSelect ifcPresentationStyleSelect : ifcPresentationStyleAssignment.getStyles()) {
                                        if (ifcPresentationStyleSelect instanceof IfcSurfaceStyle) {
                                            IfcSurfaceStyle ifcSurfaceStyle = (IfcSurfaceStyle) ifcPresentationStyleSelect;
                                            for (IfcSurfaceStyleElementSelect ifcSurfaceStyleElementSelect : ifcSurfaceStyle.getStyles()) {
                                                if (ifcSurfaceStyleElementSelect instanceof IfcSurfaceStyleRendering) {
                                                    IfcSurfaceStyleRendering ifcSurfaceStyleRendering = (IfcSurfaceStyleRendering) ifcSurfaceStyleElementSelect;
                                                    ifcSurfaceStyleRendering.setTransparency(0.98f);
                                                    ifcSurfaceStyleRendering.setDiffuseColour(gray);
                                                    ifcSurfaceStyleRendering.setReflectionColour(gray);
                                                    ifcSurfaceStyleRendering.setSpecularColour(gray);
                                                    ifcSurfaceStyleRendering.setSurfaceColour(gray);
                                                    ifcSurfaceStyleRendering.setTransmissionColour(gray);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                System.out.println("Not hiding " + guid);
                IfcProductRepresentation representation = product.getRepresentation();
                if (representation != null) {
                    for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
                        selectedLayer.getAssignedItems().add(ifcRepresentation);
                        for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
                            selectedLayer.getAssignedItems().add(ifcRepresentationItem);
                        }
                    }
                }
            }
        }
    }
    for (IdEObject toDeleteObject : toDelete) {
        model.remove(toDeleteObject);
    }
    for (IdEObject newObject : newObjects) {
        try {
            model.add(model.getHighestOid() + 1, newObject);
        } catch (IfcModelInterfaceException e) {
            e.printStackTrace();
        }
    }
}
Also used : IfcSurfaceStyle(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyle) IdEObject(org.bimserver.emf.IdEObject) IfcRepresentationItem(org.bimserver.models.ifc2x3tc1.IfcRepresentationItem) IfcPresentationLayerAssignment(org.bimserver.models.ifc2x3tc1.IfcPresentationLayerAssignment) IfcColourRgb(org.bimserver.models.ifc2x3tc1.IfcColourRgb) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) IfcStyledItem(org.bimserver.models.ifc2x3tc1.IfcStyledItem) IfcSurfaceStyleElementSelect(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleElementSelect) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) IfcPresentationStyleAssignment(org.bimserver.models.ifc2x3tc1.IfcPresentationStyleAssignment) IfcPresentationStyleSelect(org.bimserver.models.ifc2x3tc1.IfcPresentationStyleSelect) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation) HashSet(java.util.HashSet) IfcSurfaceStyleRendering(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleRendering)

Example 4 with IfcProduct

use of org.bimserver.models.ifc2x3tc1.IfcProduct in project GltfSerializers by opensourceBIM.

the class BinaryGltfSerializer2 method generateSceneAndBody.

private void generateSceneAndBody() throws SerializerException {
    int totalBodyByteLength = 0;
    int totalIndicesByteLength = 0;
    int totalVerticesByteLength = 0;
    int totalNormalsByteLength = 0;
    int totalColorsByteLength = 0;
    int maxIndexValues = 16389;
    for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
        GeometryInfo geometryInfo = ifcProduct.getGeometry();
        if (!ifcProduct.eClass().getName().equals("IfcOpeningElement") && geometryInfo != null && geometryInfo.getData().getVertices().length > 0) {
            GeometryData data = geometryInfo.getData();
            int nrIndicesBytes = data.getIndices().length;
            totalIndicesByteLength += nrIndicesBytes / 2;
            if (nrIndicesBytes > 4 * maxIndexValues) {
                int nrIndices = nrIndicesBytes / 4;
                totalVerticesByteLength += nrIndices * 3 * 4;
                totalNormalsByteLength += nrIndices * 3 * 4;
                if (data.getMaterials() != null) {
                    totalColorsByteLength += nrIndices * 4 * 4;
                }
            } else {
                totalVerticesByteLength += data.getVertices().length;
                totalNormalsByteLength += data.getNormals().length;
                if (data.getMaterials() != null) {
                    totalColorsByteLength += data.getMaterials().length;
                }
            }
        }
    }
    totalBodyByteLength = totalIndicesByteLength + totalVerticesByteLength + totalNormalsByteLength + totalColorsByteLength;
    body = ByteBuffer.allocate(totalBodyByteLength + materialColorFragmentShaderBytes.length + materialColorVertexShaderBytes.length + vertexColorFragmentShaderBytes.length + vertexColorVertexShaderBytes.length);
    body.order(ByteOrder.LITTLE_ENDIAN);
    ByteBuffer newIndicesBuffer = ByteBuffer.allocate(totalIndicesByteLength);
    newIndicesBuffer.order(ByteOrder.LITTLE_ENDIAN);
    ByteBuffer newVerticesBuffer = ByteBuffer.allocate(totalVerticesByteLength);
    newVerticesBuffer.order(ByteOrder.LITTLE_ENDIAN);
    ByteBuffer newNormalsBuffer = ByteBuffer.allocate(totalNormalsByteLength);
    newNormalsBuffer.order(ByteOrder.LITTLE_ENDIAN);
    ByteBuffer newColorsBuffer = ByteBuffer.allocate(totalColorsByteLength);
    newColorsBuffer.order(ByteOrder.LITTLE_ENDIAN);
    int indicesBufferView = createBufferView(totalIndicesByteLength, 0, ELEMENT_ARRAY_BUFFER, -1);
    int verticesBufferView = createBufferView(totalVerticesByteLength, totalIndicesByteLength, ARRAY_BUFFER, 12);
    int normalsBufferView = createBufferView(totalNormalsByteLength, totalIndicesByteLength + totalVerticesByteLength, ARRAY_BUFFER, 12);
    int colorsBufferView = -1;
    scenesNode.add(createDefaultScene());
    gltfNode.put("scene", 0);
    createModelNode();
    for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
        GeometryInfo geometryInfo = ifcProduct.getGeometry();
        if (!ifcProduct.eClass().getName().equals("IfcOpeningElement") && geometryInfo != null) {
            ByteBuffer matrixByteBuffer = ByteBuffer.wrap(ifcProduct.getGeometry().getTransformation());
            matrixByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
            DoubleBuffer doubleBuffer = matrixByteBuffer.asDoubleBuffer();
            float[] matrix = new float[16];
            for (int i = 0; i < doubleBuffer.capacity(); i++) {
                matrix[i] = (float) doubleBuffer.get();
            }
            updateExtends(geometryInfo, matrix);
        }
    }
    float[] offsets = getOffsets();
    // This will "normalize" the model by moving it's axis-aligned bounding box center to the 0-point. This will always be the wrong position, but at least the building will be close to the 0-point
    modelTranslation.add(-offsets[0]);
    modelTranslation.add(-offsets[1]);
    modelTranslation.add(-offsets[2]);
    for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
        GeometryInfo geometryInfo = ifcProduct.getGeometry();
        if (!ifcProduct.eClass().getName().equals("IfcOpeningElement") && geometryInfo != null && geometryInfo.getData().getVertices().length > 0) {
            int startPositionIndices = newIndicesBuffer.position();
            int startPositionVertices = newVerticesBuffer.position();
            int startPositionNormals = newNormalsBuffer.position();
            int startPositionColors = newColorsBuffer.position();
            GeometryData data = geometryInfo.getData();
            ByteBuffer indicesBuffer = ByteBuffer.wrap(data.getIndices());
            indicesBuffer.order(ByteOrder.LITTLE_ENDIAN);
            IntBuffer indicesIntBuffer = indicesBuffer.asIntBuffer();
            ByteBuffer verticesBuffer = ByteBuffer.wrap(data.getVertices());
            verticesBuffer.order(ByteOrder.LITTLE_ENDIAN);
            FloatBuffer verticesFloatBuffer = verticesBuffer.asFloatBuffer();
            ByteBuffer normalsBuffer = ByteBuffer.wrap(data.getNormals());
            normalsBuffer.order(ByteOrder.LITTLE_ENDIAN);
            FloatBuffer normalsFloatBuffer = normalsBuffer.asFloatBuffer();
            FloatBuffer materialsFloatBuffer = null;
            if (data.getMaterials() != null) {
                ByteBuffer materialsBuffer = ByteBuffer.wrap(data.getMaterials());
                materialsBuffer.order(ByteOrder.LITTLE_ENDIAN);
                materialsFloatBuffer = materialsBuffer.asFloatBuffer();
            }
            if (data.getIndices().length > 4 * maxIndexValues) {
                int totalNrIndices = indicesIntBuffer.capacity();
                int nrParts = (totalNrIndices + maxIndexValues - 1) / maxIndexValues;
                ArrayNode primitivesNode = OBJECT_MAPPER.createArrayNode();
                for (int part = 0; part < nrParts; part++) {
                    startPositionIndices = newIndicesBuffer.position();
                    startPositionVertices = newVerticesBuffer.position();
                    startPositionNormals = newNormalsBuffer.position();
                    startPositionColors = newColorsBuffer.position();
                    short indexCounter = 0;
                    int upto = Math.min((part + 1) * maxIndexValues, totalNrIndices);
                    for (int i = part * maxIndexValues; i < upto; i++) {
                        newIndicesBuffer.putShort(indexCounter++);
                    }
                    int[] min = new int[] { 0 };
                    int[] max = new int[] { upto };
                    int nrVertices = upto - part * maxIndexValues;
                    for (int i = part * maxIndexValues; i < upto; i += 3) {
                        int oldIndex1 = indicesIntBuffer.get(i);
                        int oldIndex2 = indicesIntBuffer.get(i + 1);
                        int oldIndex3 = indicesIntBuffer.get(i + 2);
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex1 * 3));
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex1 * 3 + 1));
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex1 * 3 + 2));
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex2 * 3));
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex2 * 3 + 1));
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex2 * 3 + 2));
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex3 * 3));
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex3 * 3 + 1));
                        newVerticesBuffer.putFloat(verticesFloatBuffer.get(oldIndex3 * 3 + 2));
                    }
                    for (int i = part * maxIndexValues; i < upto; i += 3) {
                        int oldIndex1 = indicesIntBuffer.get(i);
                        int oldIndex2 = indicesIntBuffer.get(i + 1);
                        int oldIndex3 = indicesIntBuffer.get(i + 2);
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex1 * 3));
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex1 * 3 + 1));
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex1 * 3 + 2));
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex2 * 3));
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex2 * 3 + 1));
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex2 * 3 + 2));
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex3 * 3));
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex3 * 3 + 1));
                        newNormalsBuffer.putFloat(normalsFloatBuffer.get(oldIndex3 * 3 + 2));
                    }
                    if (materialsFloatBuffer != null) {
                        for (int i = part * maxIndexValues; i < upto; i += 3) {
                            int oldIndex1 = indicesIntBuffer.get(i);
                            int oldIndex2 = indicesIntBuffer.get(i + 1);
                            int oldIndex3 = indicesIntBuffer.get(i + 2);
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex1 * 4));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex1 * 4 + 1));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex1 * 4 + 2));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex1 * 4 + 3));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex2 * 4));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex2 * 4 + 1));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex2 * 4 + 2));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex2 * 4 + 3));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex3 * 4));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex3 * 4 + 1));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex3 * 4 + 2));
                            newColorsBuffer.putFloat(materialsFloatBuffer.get(oldIndex3 * 4 + 3));
                        }
                    }
                    ObjectNode primitiveNode = OBJECT_MAPPER.createObjectNode();
                    int indicesAccessor = addIndicesAccessor(ifcProduct, indicesBufferView, startPositionIndices, nrVertices / 3, min, max);
                    int verticesAccessor = addVerticesAccessor(ifcProduct, verticesBufferView, startPositionVertices, nrVertices);
                    int normalsAccessor = addNormalsAccessor(ifcProduct, normalsBufferView, startPositionNormals, nrVertices);
                    int colorAccessor = -1;
                    if (data.getMaterials() != null) {
                        if (colorsBufferView == -1) {
                            colorsBufferView = createBufferView(totalColorsByteLength, totalIndicesByteLength + totalVerticesByteLength + totalNormalsByteLength, ARRAY_BUFFER, 16);
                        }
                        colorAccessor = addColorsAccessor(ifcProduct, colorsBufferView, startPositionColors, 16);
                    }
                    primitivesNode.add(primitiveNode);
                    primitiveNode.put("indices", indicesAccessor);
                    primitiveNode.put("mode", TRIANGLES);
                    ObjectNode attributesNode = OBJECT_MAPPER.createObjectNode();
                    primitiveNode.set("attributes", attributesNode);
                    attributesNode.put("NORMAL", normalsAccessor);
                    attributesNode.put("POSITION", verticesAccessor);
                    if (colorAccessor != -1) {
                        // attributesNode.put("COLOR_0", colorAccessor);
                        primitiveNode.put("material", vertexColorIndex);
                    } else {
                        primitiveNode.put("material", createOrGetMaterial(ifcProduct.eClass().getName(), IfcColors.getDefaultColor(ifcProduct.eClass().getName())));
                    }
                }
                int meshId = addMesh(ifcProduct, primitivesNode);
                int nodeId = addNode(meshId, ifcProduct);
                translationChildrenNode.add(nodeId);
            } else {
                int maxVal = 0;
                for (int i = 0; i < indicesIntBuffer.capacity(); i++) {
                    int index = indicesIntBuffer.get(i);
                    if (index > Short.MAX_VALUE) {
                        throw new SerializerException("Index too large to store as short " + index);
                    }
                    newIndicesBuffer.putShort((short) (index));
                    if (index > maxVal) {
                        maxVal = index;
                    }
                }
                int[] min = new int[] { 0 };
                int[] max = new int[] { maxVal };
                newVerticesBuffer.put(data.getVertices());
                newNormalsBuffer.put(data.getNormals());
                if (data.getMaterials() != null) {
                    newColorsBuffer.put(data.getMaterials());
                }
                int totalNrIndices = indicesIntBuffer.capacity();
                ArrayNode primitivesNode = OBJECT_MAPPER.createArrayNode();
                ObjectNode primitiveNode = OBJECT_MAPPER.createObjectNode();
                int indicesAccessor = addIndicesAccessor(ifcProduct, indicesBufferView, startPositionIndices, totalNrIndices, min, max);
                int verticesAccessor = addVerticesAccessor(ifcProduct, verticesBufferView, startPositionVertices, data.getVertices().length / 12);
                int normalsAccessor = addNormalsAccessor(ifcProduct, normalsBufferView, startPositionNormals, data.getNormals().length / 12);
                int colorAccessor = -1;
                if (data.getMaterials() != null) {
                    if (colorsBufferView == -1) {
                        colorsBufferView = createBufferView(totalColorsByteLength, totalIndicesByteLength + totalVerticesByteLength + totalNormalsByteLength, ARRAY_BUFFER, 16);
                    }
                    colorAccessor = addColorsAccessor(ifcProduct, colorsBufferView, startPositionColors, data.getVertices().length / 12);
                }
                primitivesNode.add(primitiveNode);
                primitiveNode.put("indices", indicesAccessor);
                primitiveNode.put("mode", TRIANGLES);
                ObjectNode attributesNode = OBJECT_MAPPER.createObjectNode();
                primitiveNode.set("attributes", attributesNode);
                attributesNode.put("NORMAL", normalsAccessor);
                attributesNode.put("POSITION", verticesAccessor);
                if (colorAccessor != -1) {
                    attributesNode.put("COLOR_0", colorAccessor);
                    primitiveNode.put("material", vertexColorIndex);
                } else {
                    primitiveNode.put("material", createOrGetMaterial(ifcProduct.eClass().getName(), IfcColors.getDefaultColor(ifcProduct.eClass().getName())));
                }
                int meshId = addMesh(ifcProduct, primitivesNode);
                int nodeId = addNode(meshId, ifcProduct);
                translationChildrenNode.add(nodeId);
            }
        }
    }
    if (newIndicesBuffer.position() != newIndicesBuffer.capacity()) {
        throw new SerializerException("Not all space used");
    }
    if (newVerticesBuffer.position() != newVerticesBuffer.capacity()) {
        throw new SerializerException("Not all space used");
    }
    if (newNormalsBuffer.position() != newNormalsBuffer.capacity()) {
        throw new SerializerException("Not all space used");
    }
    if (newColorsBuffer.position() != newColorsBuffer.capacity()) {
        throw new SerializerException("Not all space used");
    }
    newIndicesBuffer.position(0);
    newVerticesBuffer.position(0);
    newNormalsBuffer.position(0);
    newColorsBuffer.position(0);
    body.put(newIndicesBuffer);
    body.put(newVerticesBuffer);
    body.put(newNormalsBuffer);
    body.put(newColorsBuffer);
    int vertexColorFragmentShaderBufferViewName = createBufferView(vertexColorFragmentShaderBytes.length, body.position(), -1, -1);
    body.put(vertexColorFragmentShaderBytes);
    int vertexColorVertexShaderBufferViewName = createBufferView(vertexColorVertexShaderBytes.length, body.position(), -1, -1);
    body.put(vertexColorVertexShaderBytes);
    int materialColorFragmentShaderBufferViewName = createBufferView(materialColorFragmentShaderBytes.length, body.position(), -1, -1);
    body.put(materialColorFragmentShaderBytes);
    int materialColorVertexShaderBufferViewName = createBufferView(materialColorVertexShaderBytes.length, body.position(), -1, -1);
    body.put(materialColorVertexShaderBytes);
    // gltfNode.set("animations", createAnimations());
    gltfNode.set("asset", createAsset());
    // gltfNode.set("programs", createPrograms());
    gltfNode.put("scene", 0);
    // gltfNode.set("skins", createSkins());
    // gltfNode.set("techniques", createTechniques());
    // createVertexColorShaders(vertexColorFragmentShaderBufferViewName, vertexColorVertexShaderBufferViewName);
    // createMaterialColorShaders(materialColorFragmentShaderBufferViewName, materialColorVertexShaderBufferViewName);
    addBuffer(body.capacity());
// ArrayNode extensions = OBJECT_MAPPER.createArrayNode();
// extensions.add("KHR_binary_glTF");
// gltfNode.set("extensionsUsed", extensions);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GeometryData(org.bimserver.models.geometry.GeometryData) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) SerializerException(org.bimserver.plugins.serializers.SerializerException) IntBuffer(java.nio.IntBuffer) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 5 with IfcProduct

use of org.bimserver.models.ifc2x3tc1.IfcProduct in project BIMserver by opensourceBIM.

the class GetAreaDatabaseAction method execute.

@Override
public Double execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    IfcProduct ifcProduct = getDatabaseSession().get(oid, new OldQuery(bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema()), revision.getProject().getId(), revision.getId(), revision.getOid()));
    return ifcProduct.getGeometry().getArea();
}
Also used : Revision(org.bimserver.models.store.Revision) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) OldQuery(org.bimserver.database.OldQuery)

Aggregations

IfcProduct (org.bimserver.models.ifc2x3tc1.IfcProduct)8 GeometryInfo (org.bimserver.models.geometry.GeometryInfo)4 HashSet (java.util.HashSet)3 GeometryData (org.bimserver.models.geometry.GeometryData)3 IfcProductRepresentation (org.bimserver.models.ifc2x3tc1.IfcProductRepresentation)3 IfcPropertySetDefinition (org.bimserver.models.ifc2x3tc1.IfcPropertySetDefinition)3 IfcRelDefines (org.bimserver.models.ifc2x3tc1.IfcRelDefines)3 IfcRelDefinesByProperties (org.bimserver.models.ifc2x3tc1.IfcRelDefinesByProperties)3 IfcRepresentation (org.bimserver.models.ifc2x3tc1.IfcRepresentation)3 IfcRepresentationItem (org.bimserver.models.ifc2x3tc1.IfcRepresentationItem)3 SerializerException (org.bimserver.plugins.serializers.SerializerException)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ByteBuffer (java.nio.ByteBuffer)2 DoubleBuffer (java.nio.DoubleBuffer)2 FloatBuffer (java.nio.FloatBuffer)2 IntBuffer (java.nio.IntBuffer)2 OldQuery (org.bimserver.database.OldQuery)2 IfcElementQuantity (org.bimserver.models.ifc2x3tc1.IfcElementQuantity)2 IfcStyledItem (org.bimserver.models.ifc2x3tc1.IfcStyledItem)2