2

I’m writting to you this email because i’ve got some trouble to create a script in unity 3d (version 5.3.4f1). First i tried with assimpNet 3.0 (because i’veread that it works better) but when i try to get the tree structure of my ifc file, it doesn’t really work… the script give another tree structure (for exemple i get fiew nodes and then one node with 7 mesh but in the ifc file i have 2 nodes, the first one with 6 meshes and the second one with 1mesh) and then my meshes ind are not good so it doesn’t work…i can get the good meshes with other PostProcessSteps, but i’ve just one game object because of optimizeGraph.

So i tried with the assimpNet 3.3.1 (with the source code, i did the dll able to work with unity). But now i get another problem, when i tried to import my file with :

Assimp.Scene model2 = import.ImportFile("sample02.ifc", PostProcessPreset.TargetRealTimeMaximumQuality);

I get this error :

AssimpException: Error importing file: The string "E-006,#14,$)" cannot be converted into a value.

Assimp.AssimpContext.ImportFile (System.String file, PostProcessSteps postProcessFlags) ImportIFC.Start () (at Assets/Tests/ImportIFC/ImportIFC.cs:51)

So the script find the file but can not read it…

I give you my source code and if you have any question, i’ll be really happy to answer to you : My class to get the information :

using UnityEngine;

using System.Collections; using Assimp;

public class MainNodeIFC {

public string name;

public UnityEngine.Mesh[] meshes;
public MainNodeIFC[] children;

}

My main code :

public class ImportIFC : MonoBehaviour

{

// Use this for initialization
void Start()
{


    //using assimpNet 3.3.1
    AssimpContext import = new AssimpContext();

    //using assimpNet 3.0
    //AssimpImporter import = new AssimpImporter();

    import.SetConfig(new NormalSmoothingAngleConfig(66.0f));

    //using assimpNet 3.3.1
    Assimp.Scene model2 = import.ImportFile("sample02.ifc", PostProcessPreset.TargetRealTimeMaximumQuality);
    print("rootNode name: " + model2.RootNode.Name);


    //using assimpNet 3.0
    //can get good import of meshes but erase the tree structure
    /*Assimp.Scene model1 = import.ImportFile(fileName,
        //PostProcessSteps.FindInstances | // No effect + slow?
            PostProcessSteps.FindInvalidData |
            PostProcessSteps.FlipUVs |
            PostProcessSteps.FlipWindingOrder |
        //PostProcessSteps.MakeLeftHanded | // Appears to just mess things up
            PostProcessSteps.JoinIdenticalVertices |
            PostProcessSteps.ImproveCacheLocality |
            PostProcessSteps.OptimizeMeshes |
        PostProcessSteps.OptimizeGraph | // Will eliminate helper nodes
            PostProcessSteps.RemoveRedundantMaterials |
            PostProcessSteps.Triangulate 
            );*/
    //using assimpNet 3.0
    //can get the good tree structure but not the good meshes
    //Assimp.Scene model2=import.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality);
    //Assimp.Scene model2 = import.ImportFile(fileName, PostProcessPreset.TargetRealTimeQuality);



   /* MainNodeIFC MainNode1 = new MainNodeIFC();
    GameObject go1 = new GameObject();
    go1.name = model1.RootNode.Name;
    ImportNode(model1.RootNode, MainNode1, model1, go1);*/

    MainNodeIFC MainNode2 = new MainNodeIFC();
    GameObject go2 = new GameObject();
    go2.name = model2.RootNode.Name;
    ImportNode(model2.RootNode, MainNode2, model2, go2);




}



// Update is called once per frame
void Update()
{


}








void ImportNode(Node refNode, MainNodeIFC newNode, Assimp.Scene model, GameObject go)
{


    if (refNode.HasChildren)
    {


        //create new array of node children
        newNode.children = new MainNodeIFC[refNode.ChildCount];
        print(" node: " + refNode.Name + " nombre d'enfant: " + refNode.ChildCount);
        print("type du node: " + refNode.GetType().ToString());

        for (int i = 0; i < refNode.ChildCount; i++)
        {

            //create the child node
            newNode.children[i] = new MainNodeIFC();
            //create the game object for the node
            GameObject childGo = new GameObject();
            MeshFilter mf = childGo.AddComponent(typeof(MeshFilter)) as MeshFilter;
            MeshRenderer mr = childGo.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
            childGo.transform.parent = go.transform;
            childGo.name = refNode.Children[i].Name;

            //Set transform 
            Assimp.Vector3D position, scaling;
            Assimp.Quaternion rotation;
            refNode.Transform.Decompose(out scaling, out rotation, out position);
            childGo.transform.localPosition = new Vector3(position.X, position.Z, position.Y);
            childGo.transform.localRotation = new UnityEngine.Quaternion(rotation.X, rotation.Z, rotation.Y, rotation.W);
            childGo.transform.localScale = new Vector3( scaling.X, scaling.Z, scaling.Y );


            //recursive methode to get all the children node

            ImportNode(refNode.Children[i], newNode.children[i], model, childGo);

        }

    }

        if (refNode.HasMeshes)
        {
            //create array of meshes of this
            newNode.meshes = new UnityEngine.Mesh[refNode.MeshCount];

            print("final node : "+refNode.Name+"a comme enfant: " + refNode.MeshCount);
            print("type du node: " + refNode.GetType().ToString());

            //create the game object for the mesh
            /* */


            for (int i = 0; i < refNode.MeshCount; i++)
            {
                GameObject childGo = new GameObject();
                MeshFilter mf = childGo.AddComponent(typeof(MeshFilter)) as MeshFilter;
                MeshRenderer mr = childGo.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
                childGo.transform.parent = go.transform;
                childGo.name = i.ToString();
                print("nb faces: " + model.Meshes[refNode.MeshIndices[i]].FaceCount);
                //set tranform
                Assimp.Vector3D position, scaling;
                Assimp.Quaternion rotation;
                refNode.Transform.Decompose(out scaling, out rotation, out position);
                childGo.transform.localPosition = new Vector3(position.X, position.Z,-position.Y);
                childGo.transform.localRotation = new UnityEngine.Quaternion(rotation.X, rotation.Z, rotation.Y, rotation.W);
                childGo.transform.localScale = new Vector3( scaling.X, scaling.Z, scaling.Y );

                List<Vector3> verticeTmp = new List<Vector3>();



                //get vertices from model
                Vector3 VectTmp = new Vector3();
                for (int j = 0; j < model.Meshes[refNode.MeshIndices[i]].VertexCount; j++)
                {

                    VectTmp = new Vector3(model.Meshes[refNode.MeshIndices[i]].Vertices[j].X,
                        model.Meshes[refNode.MeshIndices[i]].Vertices[j].Z,
                        model.Meshes[refNode.MeshIndices[i]].Vertices[j].Y);//warning axe Y et Z inverse

                    verticeTmp.Add(VectTmp);
                }


                //set normal : actually doesn’t work

                /* var norm = model.Meshes[refNode.MeshIndices[i]].HasNormals ? model.Meshes[refNode.MeshIndices[i]].Normals[i] : new Vector3D();
                 var texC = model.Meshes[refNode.MeshIndices[i]].HasTextureCoords(0) ? model.Meshes[refNode.MeshIndices[i]].GetTextureCoords(0)[i] : new Vector3D();
                 var tan = model.Meshes[refNode.MeshIndices[i]].HasTangentBasis ? model.Meshes[refNode.MeshIndices[i]].Tangents[i] : new Vector3D();
                 newNode.meshes[i].normals[0].x = norm.X;
                 newNode.meshes[i].normals[0].y = norm.Y;
                 newNode.meshes[i].normals[0].z = norm.Z;*/



                //set vertices and triangle
                newNode.meshes[i] = new UnityEngine.Mesh();

                newNode.meshes[i].SetVertices(verticeTmp);
                newNode.meshes[i].triangles = model.Meshes[i].GetIndices();

                //draw the mesh
                mf.mesh = newNode.meshes[i];
            }
        }

}

}

sorry for my english, i’m a frensh student working also.

Thanks for your attention !

MarcMARTIN
  • 21
  • 4
  • Currently having the same problem, do you by any chance came any closer in solving the problem? – Mathijs Rutgers Apr 14 '16 at 08:45
  • No, finaly i think this wrapper not really work with ifc file...so i'm trying to do my own library but IFC file are really complicated... let me know if you find something – MarcMARTIN Apr 15 '16 at 09:48

0 Answers0