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

Getting element visual style #63

Open
CBenghi opened this issue May 31, 2017 · 0 comments
Open

Getting element visual style #63

CBenghi opened this issue May 31, 2017 · 0 comments

Comments

@CBenghi
Copy link
Member

CBenghi commented May 31, 2017

I'm opening this issue on behalf of @Ajes1337, who asked the question in the webUI, but using WindowsUI primitives.

===

@Ajes1337 Says:

I have been struggling for days, how to get Vertices, Triangles and Material out of an IFC file with Xbim (in XbimWindowsUI)..
I have the Vertices and Triangles.. but are pulling my hair out now, just to figure out how I get a material color or a valid Material.

Anyone know a 'simple' way to get the material?

Here is my code that get Vertices and Triangles:

since I cant seem to use this inbuild 'insert code' here is pastbin: https://pastebin.com/VfmG4rfN

private static byte[] ReadIfcFileAjesStyle(string ifcFilename) {
	List<Vector3[]> vecs = new List<Vector3[]>();
	List<int[]> trises = new List<int[]>();
	List<string> types = new List<string>();
	using (var model2 = IfcStore.Open(ifcFilename)) {
		if (model2.GeometryStore.IsEmpty) {
			Console.WriteLine("model.GeometryStore.IsEmpty");
			var context = new Xbim3DModelContext(model2);
			context.CreateContext();//skal køre for at virke..
		}
		XbimModelPositioningCollection modelPositions = new XbimModelPositioningCollection();
		short userDefinedId = 0;
		model2.UserDefinedId = userDefinedId;
		modelPositions.AddModel(model2.ReferencingModel);
		if (model2.IsFederation) {
			foreach (IReferencedModel refModel in model2.ReferencedModels) {
				refModel.Model.UserDefinedId = ++userDefinedId;
				IfcStore v = refModel.Model as IfcStore;
				if (v != null)
					modelPositions.AddModel(v.ReferencingModel);
			}
		}
		XbimRect3D modelBounds = modelPositions.GetEnvelopeInMeters();
		XbimPoint3D p = modelBounds.Centroid();
		XbimVector3D modelTranslation = new XbimVector3D(-p.X, -p.Y, -p.Z);
		double oneMeter = model2.ModelFactors.OneMetre;
		XbimMatrix3D translation = XbimMatrix3D.CreateTranslation(modelTranslation * oneMeter);
		XbimMatrix3D scaling = XbimMatrix3D.CreateScale(1 / oneMeter);
		XbimMatrix3D transform = translation * scaling;
		WpfMaterial mat = new WpfMaterial();
		Color SelectionColor = Colors.Blue;
		mat.CreateMaterial(new XbimColour("Selection", SelectionColor.ScR, SelectionColor.ScG, SelectionColor.ScB, SelectionColor.ScA));
		Console.WriteLine("model.Instances amount: " + model2.Instances.Count);
		bool runOnce = false;
		foreach (IPersistEntity entityThe in model2.Instances) {
			WpfMeshGeometry3D m = WpfMeshGeometry3D.GetGeometry(entityThe, transform, mat);
			string nameOfType = entityThe.GetType().ToString();
			List<Vector3> vecsHere = new List<Vector3>();
			foreach (Point3D point in m.Mesh.Positions) {
				vecsHere.Add(new Vector3(point));
			}
			vecs.Add(vecsHere.ToArray());
			trises.Add(m.Mesh.TriangleIndices.ToArray());
			types.Add(nameOfType);
		}
	}
	byte[] data = SerializerMeshPack.SerializeMeshPack(vecs, trises, types);
	return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant