Search in sources :

Example 1 with GeometryInfo

use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.

the class GeometryGenerator method returnCachedData.

private void returnCachedData(IfcModelInterface model, GeometryCache geometryCache, DatabaseSession databaseSession, int pid, int rid) throws BimserverDatabaseException {
    EClass productClass = model.getPackageMetaData().getEClass("IfcProduct");
    List<IdEObject> products = model.getAllWithSubTypes(productClass);
    for (IdEObject ifcProduct : products) {
        GeometryCacheEntry geometryCacheEntry = geometryCache.get(ifcProduct.getExpressId());
        if (geometryCacheEntry != null) {
            GeometryData geometryData = databaseSession.create(GeometryPackage.eINSTANCE.getGeometryData(), pid, rid);
            geometryData.setVertices(geometryCacheEntry.getVertices().array());
            geometryData.setNormals(geometryCacheEntry.getNormals().array());
            GeometryInfo geometryInfo = databaseSession.create(GeometryPackage.eINSTANCE.getGeometryInfo(), pid, rid);
            Vector3f min = databaseSession.create(GeometryPackage.eINSTANCE.getVector3f(), pid, rid);
            min.setX(geometryCacheEntry.getGeometryInfo().getMinBounds().getX());
            min.setY(geometryCacheEntry.getGeometryInfo().getMinBounds().getY());
            min.setZ(geometryCacheEntry.getGeometryInfo().getMinBounds().getZ());
            Vector3f max = databaseSession.create(GeometryPackage.eINSTANCE.getVector3f(), pid, rid);
            max.setX(geometryCacheEntry.getGeometryInfo().getMaxBounds().getX());
            max.setY(geometryCacheEntry.getGeometryInfo().getMaxBounds().getY());
            max.setZ(geometryCacheEntry.getGeometryInfo().getMaxBounds().getZ());
            geometryInfo.setMinBounds(min);
            geometryInfo.setMaxBounds(max);
            geometryInfo.setData(geometryData);
            ifcProduct.eSet(ifcProduct.eClass().getEStructuralFeature("geometry"), geometryInfo);
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IdEObject(org.bimserver.emf.IdEObject) Vector3f(org.bimserver.models.geometry.Vector3f) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) GeometryData(org.bimserver.models.geometry.GeometryData)

Example 2 with GeometryInfo

use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.

the class ClientIfcModel method processGeometryInputStream.

private void processGeometryInputStream(InputStream inputStream, Map<Long, Long> geometryInfoOidToOid) throws IOException, GeometryException, IfcModelInterfaceException {
    try (LittleEndianDataInputStream dataInputStream = new LittleEndianDataInputStream(inputStream)) {
        boolean done = false;
        while (!done) {
            byte type = dataInputStream.readByte();
            if (type == 0) {
                String protocol = dataInputStream.readUTF();
                if (!protocol.equals("BGS")) {
                    throw new GeometryException("Protocol != BGS (" + protocol + ")");
                }
                byte formatVersion = dataInputStream.readByte();
                if (formatVersion != 11) {
                    throw new GeometryException("Unsupported version " + formatVersion + " / 11");
                }
                int skip = 4 - (7 % 4);
                if (skip != 0 && skip != 4) {
                    dataInputStream.readFully(new byte[skip]);
                }
                for (int i = 0; i < 6; i++) {
                    dataInputStream.readDouble();
                }
            } else if (type == 5) {
                dataInputStream.readFully(new byte[7]);
                // roid
                dataInputStream.readLong();
                long geometryInfoOid = dataInputStream.readLong();
                GeometryInfo geometryInfo = (GeometryInfo) get(geometryInfoOid);
                if (geometryInfo == null) {
                    geometryInfo = create(GeometryInfo.class);
                }
                ((IdEObjectImpl) geometryInfo).setOid(geometryInfoOid);
                ((IdEObjectImpl) geometryInfo).setLoadingState(State.LOADING);
                add(geometryInfoOid, geometryInfo);
                Long ifcProductOid = geometryInfoOidToOid.get(geometryInfoOid);
                if (ifcProductOid == null) {
                    throw new GeometryException("Missing geometry info id: " + geometryInfoOid);
                }
                IdEObject ifcProduct = get(ifcProductOid);
                EStructuralFeature geometryFeature = getPackageMetaData().getEClass("IfcProduct").getEStructuralFeature("geometry");
                ifcProduct.eSet(geometryFeature, geometryInfo);
                org.bimserver.models.geometry.Vector3f minBounds = GeometryFactory.eINSTANCE.createVector3f();
                minBounds.setX(dataInputStream.readDouble());
                minBounds.setY(dataInputStream.readDouble());
                minBounds.setZ(dataInputStream.readDouble());
                org.bimserver.models.geometry.Vector3f maxBounds = GeometryFactory.eINSTANCE.createVector3f();
                maxBounds.setX(dataInputStream.readDouble());
                maxBounds.setY(dataInputStream.readDouble());
                maxBounds.setZ(dataInputStream.readDouble());
                geometryInfo.setMinBounds(minBounds);
                geometryInfo.setMaxBounds(maxBounds);
                byte[] transformation = new byte[16 * 8];
                dataInputStream.readFully(transformation);
                geometryInfo.setTransformation(transformation);
                long geometryDataOid = dataInputStream.readLong();
                GeometryData geometryData = (GeometryData) get(geometryDataOid);
                if (geometryData == null) {
                    geometryData = GeometryFactory.eINSTANCE.createGeometryData();
                    add(geometryDataOid, geometryData);
                }
                geometryInfo.setData(geometryData);
                ((IdEObjectImpl) geometryData).setLoadingState(State.LOADED);
            } else if (type == 3) {
                throw new GeometryException("Parts not supported");
            } else if (type == 1) {
                dataInputStream.readFully(new byte[7]);
                long geometryDataOid = dataInputStream.readLong();
                GeometryData geometryData = (GeometryData) get(geometryDataOid);
                if (geometryData == null) {
                    geometryData = GeometryFactory.eINSTANCE.createGeometryData();
                    add(geometryDataOid, geometryData);
                }
                ((IdEObjectImpl) geometryData).setOid(geometryDataOid);
                ((IdEObjectImpl) geometryData).setLoadingState(State.LOADING);
                int nrIndices = dataInputStream.readInt();
                byte[] indices = new byte[nrIndices * 4];
                dataInputStream.readFully(indices);
                geometryData.setIndices(indices);
                int colorType = dataInputStream.readInt();
                if (colorType == 1) {
                    dataInputStream.readFloat();
                    dataInputStream.readFloat();
                    dataInputStream.readFloat();
                    dataInputStream.readFloat();
                }
                int nrVertices = dataInputStream.readInt();
                byte[] vertices = new byte[nrVertices * 4];
                dataInputStream.readFully(vertices);
                geometryData.setVertices(vertices);
                int nrNormals = dataInputStream.readInt();
                byte[] normals = new byte[nrNormals * 4];
                dataInputStream.readFully(normals);
                geometryData.setNormals(normals);
                int nrMaterials = dataInputStream.readInt();
                byte[] materials = new byte[nrMaterials * 4];
                dataInputStream.readFully(materials);
                geometryData.setMaterials(materials);
                ((IdEObjectImpl) geometryData).setLoadingState(State.LOADED);
            } else if (type == 6) {
                done = true;
            } else {
                throw new GeometryException("Unimplemented type: " + type);
            }
        }
    } catch (EOFException e) {
    // 
    } catch (ObjectAlreadyExistsException e) {
        e.printStackTrace();
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) GeometryData(org.bimserver.models.geometry.GeometryData) LittleEndianDataInputStream(com.google.common.io.LittleEndianDataInputStream) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) EOFException(java.io.EOFException) ObjectAlreadyExistsException(org.bimserver.plugins.ObjectAlreadyExistsException)

Example 3 with GeometryInfo

use of org.bimserver.models.geometry.GeometryInfo 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 4 with GeometryInfo

use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.

the class GeometryGenerator method returnCachedData.

private void returnCachedData(IfcModelInterface model, GeometryCache geometryCache, DatabaseSession databaseSession, int pid, int rid, boolean store) throws BimserverDatabaseException, ObjectAlreadyExistsException, IfcModelInterfaceException {
    EClass productClass = model.getPackageMetaData().getEClass("IfcProduct");
    List<IdEObject> products = model.getAllWithSubTypes(productClass);
    for (IdEObject ifcProduct : products) {
        GeometryCacheEntry geometryCacheEntry = geometryCache.get(ifcProduct.getExpressId());
        if (geometryCacheEntry != null) {
            GeometryData geometryData = databaseSession.create(GeometryPackage.eINSTANCE.getGeometryData(), pid, rid);
            geometryData.setVertices(createBuffer(model, databaseSession, geometryCacheEntry.getVertices(), store, pid, rid));
            geometryData.setNormals(createBuffer(model, databaseSession, geometryCacheEntry.getNormals(), store, pid, rid));
            GeometryInfo geometryInfo = databaseSession.create(GeometryPackage.eINSTANCE.getGeometryInfo(), pid, rid);
            Vector3f min = databaseSession.create(GeometryPackage.eINSTANCE.getVector3f(), pid, rid);
            min.setX(geometryCacheEntry.getGeometryInfo().getBounds().getMin().getX());
            min.setY(geometryCacheEntry.getGeometryInfo().getBounds().getMin().getY());
            min.setZ(geometryCacheEntry.getGeometryInfo().getBounds().getMin().getZ());
            Vector3f max = databaseSession.create(GeometryPackage.eINSTANCE.getVector3f(), pid, rid);
            max.setX(geometryCacheEntry.getGeometryInfo().getBounds().getMax().getX());
            max.setY(geometryCacheEntry.getGeometryInfo().getBounds().getMax().getY());
            max.setZ(geometryCacheEntry.getGeometryInfo().getBounds().getMax().getZ());
            Bounds bounds = GeometryFactory.eINSTANCE.createBounds();
            bounds.setMin(min);
            bounds.setMax(max);
            geometryInfo.setBounds(bounds);
            geometryInfo.setData(geometryData);
            ifcProduct.eSet(ifcProduct.eClass().getEStructuralFeature("geometry"), geometryInfo);
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IdEObject(org.bimserver.emf.IdEObject) Vector3f(org.bimserver.models.geometry.Vector3f) Bounds(org.bimserver.models.geometry.Bounds) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) GeometryData(org.bimserver.models.geometry.GeometryData)

Example 5 with GeometryInfo

use of org.bimserver.models.geometry.GeometryInfo in project BIMserver by opensourceBIM.

the class ClientIfcModel method loadGeometry.

public void loadGeometry() throws QueryException, ServerException, UserException, PublicInterfaceNotFoundException, IOException, GeometryException, IfcModelInterfaceException {
    if (includeGeometry) {
        if (modelState == ModelState.FULLY_LOADED) {
            return;
        }
        Query query = new Query("test", getPackageMetaData());
        ObjectNode settings = new ObjectMapper().createObjectNode();
        query.setGeometrySettings(settings);
        query.getGeometrySettings().put("useSmallInts", false);
        query.getGeometrySettings().put("splitGeometry", false);
        query.getGeometrySettings().put("quantizeColors", true);
        QueryPart queryPart = query.createQueryPart();
        EClass ifcProductClass = getPackageMetaData().getEClass("IfcProduct");
        EStructuralFeature geometryFeature = ifcProductClass.getEStructuralFeature("geometry");
        List<IdEObject> allWithSubTypes = new ArrayList<>(super.getAllWithSubTypes(ifcProductClass));
        for (IdEObject ifcProduct : allWithSubTypes) {
            GeometryInfo geometry = (GeometryInfo) ifcProduct.eGet(geometryFeature);
            if (geometry != null) {
                if (!geometryTried.contains(geometry.getOid())) {
                    queryPart.addOid(geometry.getOid());
                    geometryTried.add(geometry.getOid());
                }
            }
        }
        if (queryPart.getOids() == null) {
            return;
        }
        LOGGER.info("Loading geometry for " + queryPart.getOids().size() + " objects");
        EClass geometryInfoClass = getPackageMetaData().getEClassIncludingDependencies("GeometryInfo");
        Include include = queryPart.createInclude();
        include.addType(geometryInfoClass, false);
        include.addField("data");
        Include geometryData = include.createInclude();
        geometryData.addType(getPackageMetaData().getEClassIncludingDependencies("GeometryData"), false);
        geometryData.addFieldDirect("indices");
        geometryData.addFieldDirect("normals");
        geometryData.addFieldDirect("vertices");
        geometryData.addFieldDirect("colorsQuantized");
        long serializerOid = bimServerClient.getBinaryGeometryMessagingStreamingSerializerOid();
        long topicId = bimServerClient.query(query, roid, serializerOid);
        // TODO use websocket notifications
        bimServerClient.waitForDonePreparing(topicId);
        try (InputStream inputStream = bimServerClient.getDownloadData(topicId)) {
            clientDebugInfo.incrementGeometryGetDownloadData();
            try {
                processGeometryInputStream(inputStream);
            } catch (Throwable e) {
                e.printStackTrace();
            } finally {
                bimServerClient.getServiceInterface().cleanupLongAction(topicId);
            }
        }
    }
}
Also used : Query(org.bimserver.database.queries.om.Query) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IdEObject(org.bimserver.emf.IdEObject) QueryPart(org.bimserver.database.queries.om.QueryPart) InputStream(java.io.InputStream) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ArrayList(java.util.ArrayList) Include(org.bimserver.database.queries.om.Include) EClass(org.eclipse.emf.ecore.EClass) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

GeometryInfo (org.bimserver.models.geometry.GeometryInfo)15 GeometryData (org.bimserver.models.geometry.GeometryData)8 IdEObject (org.bimserver.emf.IdEObject)6 IfcProduct (org.bimserver.models.ifc2x3tc1.IfcProduct)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 SProject (org.bimserver.interfaces.objects.SProject)4 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)4 EClass (org.eclipse.emf.ecore.EClass)4 ByteBuffer (java.nio.ByteBuffer)3 BimServerClient (org.bimserver.client.BimServerClient)3 ClientIfcModel (org.bimserver.client.ClientIfcModel)3 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)3 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)3 Vector3f (org.bimserver.models.geometry.Vector3f)3 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)3 Test (org.junit.Test)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 DoubleBuffer (java.nio.DoubleBuffer)2 FloatBuffer (java.nio.FloatBuffer)2 IntBuffer (java.nio.IntBuffer)2