opensourceBIM / BIMserver

The open source BIMserver platform
GNU Affero General Public License v3.0
1.56k stars 610 forks source link

Surface colors are not evaluated correctly. #495

Closed Jo64 closed 7 years ago

Jo64 commented 7 years ago

BIMserver 1.4 ifcfurnishingelement

Hi, the object colors (IfcFurnishingElement) are not displayed correctly because they are not transferred. The GeometryLoader loads all geometric data, but the color array is empty. var colors = data.readFloatArray (nrColors); The color is now used from the BIMSURFER.Constants.materials list. Are the colors of IfcStyledItem not supported? Thanks Jo

rubendel commented 7 years ago

BIMserver 1.5 definately uses IfcStyledItem for coloring objects, but I am also pretty sure 1.4 did. There might be some corner cases so I'd be interested in trying your model in 1.5 if you are in the ability to share the file. Otherwise maybe you can try in 1.5?

Jo64 commented 7 years ago

Ok. Here is the ifc file. The file contains only 4 walls and the desk. MUC-cvb40-ARC-001.zip

rubendel commented 7 years ago

chair

So in 1.5 the colors seem to be right, but part of the chair is missing in the visualization. I'll have a look at that.

Jo64 commented 7 years ago

deskchair

Hi Ruben, I've found the reason why the chair isn't rendered. The chair consists of 2 geometry parts. The data stream from the geometryloader 'this.readObject = function (data, geometryType)' has correct values. But if you have a geometry with more than one parts the first part is never rendered. Can't see why. Can you check this? Solution: I've added the geometry data from the first part into the second geometry part and the chair is displayed correctly. Look at the quick and dirty changes in the geometryloader.js.

GeometryLoader.js ...

else if (geometryType == 3) { var coreIds = []; var geometryDataOid = data.readLong(); var nrParts = data.readInt(); //var objectBounds = data.readFloatArray(6);

var previousGeometry = null;

for (var i = 0; i < nrParts; i++) {
    var coreId = data.readLong();
    coreIds.push(coreId);
    var nrIndices = data.readInt();
    o.stats.nrPrimitives += nrIndices / 3;
    var indices = data.readShortArray(nrIndices);
    data.align4();
    var nrVertices = data.readInt();
    o.stats.nrVertices += nrVertices;
    var vertices = data.readFloatArray(nrVertices);
    var nrNormals = data.readInt();
    o.stats.nrNormals += nrNormals;
    var normals = data.readFloatArray(nrNormals);
    var nrColors = data.readInt();
    o.stats.nrColors += nrColors;

    var colors = null;
    if (nrColors > 0) {
        colors = data.readFloatArray(nrColors);
    }

    var geometry = {
        type: "geometry",
        primitive: o.type
    };

    geometry.coreId = coreId;

    if (o.type == "lines") {
        geometry.indices = o.convertToLines(indices);
    } else {
        geometry.indices = indices;
    }
    geometry.positions = vertices;
    geometry.normals = normals;

    if (colors != null && colors.length > 0) {
        geometry.colors = colors;
    }

    // ******************************************************************
    // quick and dirty changes - start
    // add the first geometry data to the second geometry
    if (i == 1)
    {
        var newVertices = new Float32Array(geometry.positions.length + previousGeometry.positions.length);
        var newIndices = new Int16Array(geometry.indices.length + previousGeometry.indices.length);
        var newNormals = new Float32Array(geometry.normals.length + previousGeometry.normals.length);

        for (var k = 0; k < geometry.positions.length; k++)
            newVertices[k] = geometry.positions[k];
        for (var k = 0 ; k < previousGeometry.positions.length; k++)
            newVertices[k + geometry.positions.length] = previousGeometry.positions[k];

        for (var k = 0; k < geometry.normals.length; k++)
            newNormals[k] = geometry.normals[k];
        for (var k = 0; k < previousGeometry.normals.length; k++)
            newNormals[k + geometry.normals.length] = previousGeometry.normals[k];

        for (var k = 0; k < geometry.indices.length; k++)
            newIndices[k] = geometry.indices[k];
        for (var k = 0; k < previousGeometry.indices.length; k++)
            newIndices[k + geometry.indices.length] = previousGeometry.indices[k] + geometry.indices.length; // index correction!!!

        geometry.positions = newVertices;
        geometry.indices = newIndices;
        geometry.normals = newNormals;

        if (previousGeometry.colors != null && previousGeometry.colors.length > 0)
        {
            if (colors != null && colors.length > 0) {
                var newColors = new Float32Array(geometry.colors.length + previousGeometry.colors.length);

                for (var k = 0; k < geometry.colors.length; k++)
                    newColors[k] = geometry.colors[k];
                for (var k = 0; k < previousGeometry.colors.length; k++)
                    newColors[k + geometry.colors.length] = previousGeometry.colors[k];

                geometry.colors = newColors;
            }
            else
            {
                geometry.colors = previousGeometry.colors;
            }
        }
    }
    // quick and dirty changes - end
    // ******************************************************************

    //o.library.add("node", geometry);                    
    o.library.addNode(geometry);

    previousGeometry = geometry;
}

}

Jo64 commented 7 years ago

Sorry, not closed. Please check the exact cause.

rubendel commented 7 years ago

Thanks for your feedback! I have committed a smaller fix, linked to this issue.