<commit_before>OV.ImporterIfc = class extends OV.ImporterBase
{
    constructor ()
    {
        super ();
		this.ifc = null;
    }
	
    CanImportExtension (extension)
    {
        return extension === 'ifc';
    }
    
    GetKnownFileFormats ()
    {
        return {
    		'ifc' : OV.FileFormat.Binary
        };
    }
    
    GetUpDirection ()
    {
        return OV.Direction.Y;
    }

	ClearContent ()
	{
        this.materialNameToIndex = null;
	}

    ResetContent ()
    {
        this.materialNameToIndex = {};
    }

    ImportContent (fileContent, onFinish)
    {
		if (this.ifc === null) {
			let obj = this;
			OV.LoadExternalLibrary ('web-ifc-api.js', {
				success : function () {
					obj.ifc = new IfcAPI ();
                    obj.ifc.Init ().then (function () {
                        obj.ImportIfcContent (fileContent);
                        onFinish ();
                    });
				},
				error : function () {
					onFinish ();
				}
			});
		} else {
			this.ImportIfcContent (fileContent);
			onFinish ();
		}
    }

	ImportIfcContent (fileContent)
	{
        const fileBuffer = new Uint8Array (fileContent);
		const modelID = this.ifc.OpenModel (fileBuffer, {
            COORDINATE_TO_ORIGIN : true
        });
        const ifcMeshes = this.ifc.LoadAllGeometry (modelID);
        for (let meshIndex = 0; meshIndex < ifcMeshes.size (); meshIndex++) {
            const ifcMesh = ifcMeshes.get (meshIndex);
            this.ImportIfcMesh (modelID, ifcMesh);
        }
        this.ifc.CloseModel (modelID);
	}

    ImportIfcMesh (modelID, ifcMesh)
    {
        let mesh = new OV.Mesh ();
        mesh.SetName ('Mesh ' + ifcMesh.expressID.toString ());

        let vertexOffset = 0;
        const ifcGeometries = ifcMesh.geometries;
        for (let geometryIndex = 0; geometryIndex < ifcGeometries.size (); geometryIndex++) {
            const ifcGeometry = ifcGeometries.get (geometryIndex);
            const ifcGeometryData = this.ifc.GetGeometry (modelID, ifcGeometry.geometryExpressID);
            const ifcVertices = this.ifc.GetVertexArray (ifcGeometryData.GetVertexData (), ifcGeometryData.GetVertexDataSize ());
            const ifcIndices = this.ifc.GetIndexArray (ifcGeometryData.GetIndexData (), ifcGeometryData.GetIndexDataSize ());
            const materialIndex = this.GetMaterialIndexByColor (ifcGeometry.color);
            const matrix = new OV.Matrix (ifcGeometry.flatTransformation);
            const transformation = new OV.Transformation (matrix);

            for (let i = 0; i < ifcVertices.length; i += 6) {
                const x = ifcVertices[i];
                const y = ifcVertices[i + 1];
                const z = ifcVertices[i + 2];
                const coord = new OV.Coord3D (x, y, z);
                const transformed = transformation.TransformCoord3D (coord);
                mesh.AddVertex (transformed);
            }
            // TODO: normals
            for (let i = 0; i < ifcIndices.length; i += 3) {
                const v0 = ifcIndices[i];
                const v1 = ifcIndices[i + 1];
                const v2 = ifcIndices[i + 2];
                const triangle = new OV.Triangle (
                    vertexOffset + v0,
                    vertexOffset + v1,
                    vertexOffset + v2
                );
                triangle.SetMaterial (materialIndex);
                mesh.AddTriangle (triangle);
            }
            vertexOffset += ifcVertices.length / 6;
        }

        this.model.AddMesh (mesh);
    }

    GetMaterialIndexByColor (ifcColor)
    {
        const color = new OV.Color (
            parseInt (ifcColor.x * 255.0, 10),
            parseInt (ifcColor.y * 255.0, 10),
            parseInt (ifcColor.z * 255.0, 10)
        );
    
        const materialName = 'Color ' +
            OV.IntegerToHexString (color.r) +
            OV.IntegerToHexString (color.g) +
            OV.IntegerToHexString (color.b) +
            OV.IntegerToHexString (parseInt (ifcColor.w * 255.0, 10));
        
        let materialIndex = this.materialNameToIndex[materialName];
        if (materialIndex === undefined) {
			let material = new OV.Material ();
            material.name = materialName;
			material.diffuse = color;
            material.opacity = ifcColor.w;
            OV.UpdateMaterialTransparency (material);
            materialIndex = this.model.AddMaterial (material);
            this.materialNameToIndex[materialName] = materialIndex;
        }
        return materialIndex;
    }
};<commit_msg>Property import tryout.<commit_after>OV.ImporterIfc = class extends OV.ImporterBase
{
    constructor ()
    {
        super ();
		this.ifc = null;
    }
	
    CanImportExtension (extension)
    {
        return extension === 'ifc';
    }
    
    GetKnownFileFormats ()
    {
        return {
    		'ifc' : OV.FileFormat.Binary
        };
    }
    
    GetUpDirection ()
    {
        return OV.Direction.Y;
    }

	ClearContent ()
	{
        this.materialNameToIndex = null;
        this.expressIDToMesh = null;
	}

    ResetContent ()
    {
        this.materialNameToIndex = {};
        this.expressIDToMesh = {};
    }

    ImportContent (fileContent, onFinish)
    {
		if (this.ifc === null) {
			let obj = this;
			OV.LoadExternalLibrary ('web-ifc-api.js', {
				success : function () {
					obj.ifc = new IfcAPI ();
                    obj.ifc.Init ().then (function () {
                        obj.ImportIfcContent (fileContent);
                        onFinish ();
                    });
				},
				error : function () {
					onFinish ();
				}
			});
		} else {
			this.ImportIfcContent (fileContent);
			onFinish ();
		}
    }

	ImportIfcContent (fileContent)
	{
        const fileBuffer = new Uint8Array (fileContent);
		const modelID = this.ifc.OpenModel (fileBuffer, {
            COORDINATE_TO_ORIGIN : true
        });
        const ifcMeshes = this.ifc.LoadAllGeometry (modelID);
        for (let meshIndex = 0; meshIndex < ifcMeshes.size (); meshIndex++) {
            const ifcMesh = ifcMeshes.get (meshIndex);
            this.ImportIfcMesh (modelID, ifcMesh);
        }
        this.ImportProperties (modelID);
        this.ifc.CloseModel (modelID);
	}

    ImportIfcMesh (modelID, ifcMesh)
    {
        let mesh = new OV.Mesh ();
        mesh.SetName ('Mesh ' + ifcMesh.expressID.toString ());

        let vertexOffset = 0;
        const ifcGeometries = ifcMesh.geometries;
        for (let geometryIndex = 0; geometryIndex < ifcGeometries.size (); geometryIndex++) {
            const ifcGeometry = ifcGeometries.get (geometryIndex);
            const ifcGeometryData = this.ifc.GetGeometry (modelID, ifcGeometry.geometryExpressID);
            const ifcVertices = this.ifc.GetVertexArray (ifcGeometryData.GetVertexData (), ifcGeometryData.GetVertexDataSize ());
            const ifcIndices = this.ifc.GetIndexArray (ifcGeometryData.GetIndexData (), ifcGeometryData.GetIndexDataSize ());
            const materialIndex = this.GetMaterialIndexByColor (ifcGeometry.color);
            const matrix = new OV.Matrix (ifcGeometry.flatTransformation);
            const transformation = new OV.Transformation (matrix);

            for (let i = 0; i < ifcVertices.length; i += 6) {
                const x = ifcVertices[i];
                const y = ifcVertices[i + 1];
                const z = ifcVertices[i + 2];
                const coord = new OV.Coord3D (x, y, z);
                const transformed = transformation.TransformCoord3D (coord);
                mesh.AddVertex (transformed);
            }
            // TODO: normals
            for (let i = 0; i < ifcIndices.length; i += 3) {
                const v0 = ifcIndices[i];
                const v1 = ifcIndices[i + 1];
                const v2 = ifcIndices[i + 2];
                const triangle = new OV.Triangle (
                    vertexOffset + v0,
                    vertexOffset + v1,
                    vertexOffset + v2
                );
                triangle.SetMaterial (materialIndex);
                mesh.AddTriangle (triangle);
            }
            vertexOffset += ifcVertices.length / 6;
        }

        this.expressIDToMesh[ifcMesh.expressID] = mesh;
        this.model.AddMesh (mesh);
    }

    ImportProperties (modelID)
    {
        let obj = this;
        const lines = this.ifc.GetLineIDsWithType (modelID, IFCRELDEFINESBYPROPERTIES);
        for (let i = 0; i < lines.size (); i++) {
            const relID = lines.get (i);
            const rel = this.ifc.GetLine (modelID, relID);
            rel.RelatedObjects.forEach (function (objectRelID) {
                let foundMesh = obj.expressIDToMesh[objectRelID.value];
                if (foundMesh === undefined) {
                    return;
                }
                if (Array.isArray (rel.RelatingPropertyDefinition)) {
                    return;
                }
                let propSetDef = rel.RelatingPropertyDefinition;
                let propSet = obj.ifc.GetLine (modelID, propSetDef.value, true);
                // TODO: same property can exist in different sets
                if (!propSet.Name.value.endsWith ('Common')) {
                    return;
                }
                propSet.HasProperties.forEach (function (property) {
                    let meshProperty = null;
                    if (property.NominalValue.label === 'IFCLABEL' || property.NominalValue.label === 'IFCIDENTIFIER') {
                        meshProperty = new OV.Property (OV.PropertyType.Text, property.Name.value, property.NominalValue.value);
                    } else if (property.NominalValue.label === 'IFCBOOLEAN') {
                        // TODO: bool property type
                        meshProperty = new OV.Property (OV.PropertyType.Text, property.Name.value, property.NominalValue.value === 'T' ? 'Yes' : 'No');
                    }
                    if (meshProperty !== null) {
                        foundMesh.AddProperty (meshProperty);
                    }
                });
            });
        }
    }

    GetMaterialIndexByColor (ifcColor)
    {
        const color = new OV.Color (
            parseInt (ifcColor.x * 255.0, 10),
            parseInt (ifcColor.y * 255.0, 10),
            parseInt (ifcColor.z * 255.0, 10)
        );
    
        const materialName = 'Color ' +
            OV.IntegerToHexString (color.r) +
            OV.IntegerToHexString (color.g) +
            OV.IntegerToHexString (color.b) +
            OV.IntegerToHexString (parseInt (ifcColor.w * 255.0, 10));
        
        let materialIndex = this.materialNameToIndex[materialName];
        if (materialIndex === undefined) {
			let material = new OV.Material ();
            material.name = materialName;
			material.diffuse = color;
            material.opacity = ifcColor.w;
            OV.UpdateMaterialTransparency (material);
            materialIndex = this.model.AddMaterial (material);
            this.materialNameToIndex[materialName] = materialIndex;
        }
        return materialIndex;
    }
};
{'fraction_non_alphanumeric': 0.10628106642566651, 'fraction_numerical': 0.008224130140081337, 'mean_word_length': 1.7343711391153942, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '100468', 'n_tokens_mistral': 3392, 'n_tokens_neox': 3114, 'n_words': 653}