Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Texture Mapping #336

Open
Ozymandias1 opened this issue May 12, 2020 · 3 comments
Open

Support for Texture Mapping #336

Ozymandias1 opened this issue May 12, 2020 · 3 comments
Labels
feature A new feature or enhancement help wanted
Milestone

Comments

@Ozymandias1
Copy link

Ozymandias1 commented May 12, 2020

i try to make some geometry using IfcTriangulatedFaceSet with texture mapping.

i searching for example or sample but i can't find how to create geometry with texture mapping for ifc format.

and i wrote some code with ifc and xbim documents.

when i create ifc file use my code, geometry are shows up in Xbim Xplorer but can't see texture mapping.

am i use wrong approach?

or is there any way for create ifc geometry with texture mapping?

best regards.

using (var txn = model.BeginTransaction(string.Format("Create Ifc Polygon Object: {0}", data.name)))
{
    var coordinates = model.Instances.New<IfcCartesianPointList3D>();
    var tfs = model.Instances.New<IfcTriangulatedFaceSet>(fs =>
        {
            fs.Closed = false;
            fs.Coordinates = coordinates;
        }
    );
    var texMap = model.Instances.New<IfcIndexedTriangleTextureMap>();
    texMap.MappedTo = tfs; // connect to face set

    var imageTexture = model.Instances.New<IfcImageTexture>();
    imageTexture.URLReference = "./MySampleTexture.jpg";
    texMap.Maps.Add(imageTexture);

    // convert position vertex set to double[] list
    var points = new List<double[]>();
    for (int vdx = 0; vdx < data.vertices.Length; vdx++)
    {
        var v0 = data.vertices[vdx];
        points.Add(new double[] { v0.x, v0.z * -1.0, v0.y }); // invert zy
    }
    for (int vdx = 0; vdx < points.Count; vdx++)
    {
        var values = points[vdx].Select(v0 => new IfcLengthMeasure(v0));
        coordinates.CoordList.GetAt(vdx).AddRange(values);
    }
    // convert face index set to long[] list
    var indices = new List<long[]>();
    for (int idx = 0; idx < data.indices.Length; idx += 3)
    {
        // index are starting 1, not 0.
        var i0 = data.indices[idx + 0] + 1;
        var i1 = data.indices[idx + 1] + 1;
        var i2 = data.indices[idx + 2] + 1;
        indices.Add(new long[] { i0, i1, i2 });
    }
    for (int idx = 0; idx < indices.Count; idx++)
    {
        var values = indices[idx].Select(i0 => new IfcPositiveInteger(i0));
        tfs.CoordIndex.GetAt(idx).AddRange(values);
        texMap.TexCoordIndex.GetAt(idx).AddRange(values); // uv index are same as face index
    }

    // UV
    var texVtxList = model.Instances.New<IfcTextureVertexList>();
    texMap.TexCoords = texVtxList;
    var uvs = new List<double[]>();
    for(int vdx = 0; vdx < data.uvs.Length; vdx++)
    {
        var v0 = data.uvs[vdx];
        uvs.Add(new double[] { v0.x, v0.y });
    }
    for(int vdx = 0; vdx < uvs.Count; vdx++)
    {
        var values = uvs[vdx].Select(v0 => new IfcParameterValue(v0));
        texVtxList.TexCoordsList.GetAt(vdx).AddRange(values);
    }

    // create ifcshape, representation
    var shape = model.Instances.New<IfcShapeRepresentation>();
    var context = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
    shape.ContextOfItems = context;
    shape.RepresentationType = "Tessellation";
    shape.RepresentationIdentifier = "Body";
    shape.Items.Add(tfs);

    var rep = model.Instances.New<IfcProductDefinitionShape>();
    rep.Representations.Add(shape);
    
    var column = model.Instances.New<IfcColumn>();
    column.Name = data.name;
    column.Representation = rep;
    ifcParentGroup.RelatedElements.Add(column);    

    txn.Commit();
}

image

@martin1cerny
Copy link
Member

I'm sorry but our viewer doesn't handle textures. We only show colours. To be fair, I don't think you will find many IFC tools which would handle textures. If you know about any, let us know please.

@andyward andyward changed the title problem in create ifc column using IfcTriangulatedFaceSet Support for Texture Mapping May 12, 2020
@andyward
Copy link
Member

There was some experimental work by @Noranius to support texture mapping last year xBimTeam/XbimWindowsUI#127

I don't know how far he got. It might be a good start to look at IfcBlobTexture support

@Noranius
Copy link

Yes I tried to achieve some results there. However, I could not reach the final target. see xBimTeam/XbimWindowsUI#140. In general I've made changes to the essentials and the presentation. But the final result does not display the expected texture. Whereby, i could check that the texture, respectively the jpg, is loaded successfully.

@andyward andyward added feature A new feature or enhancement help wanted labels Oct 17, 2020
@andyward andyward added this to the Backlog milestone Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or enhancement help wanted
Projects
None yet
Development

No branches or pull requests

4 participants