export view
This commit is contained in:
parent
22c65adb03
commit
6451f0d13e
@ -49,15 +49,18 @@ namespace PDF3D.Addin
|
||||
iDTFBuilder.InsertElement(item);
|
||||
}
|
||||
|
||||
//var views = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).OfClass(typeof(View3D)).Cast<View3D>().ToList();
|
||||
//foreach (var item in views)
|
||||
//{
|
||||
// iDTFBuilder.InsertView(item);
|
||||
//}
|
||||
var views = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).OfClass(typeof(View3D)).Cast<View3D>().ToList();
|
||||
foreach (var item in views)
|
||||
{
|
||||
if (item.Origin != null)
|
||||
{
|
||||
iDTFBuilder.InsertView(item);
|
||||
}
|
||||
}
|
||||
|
||||
iDTFBuilder.Export(idtf);
|
||||
|
||||
GeneratePDF(idtf,fileDialog.FileName);
|
||||
GeneratePDF(idtf, fileDialog.FileName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@ -87,7 +90,7 @@ namespace PDF3D.Addin
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void GeneratePDF(string idtf,string pdf)
|
||||
public void GeneratePDF(string idtf, string pdf)
|
||||
{
|
||||
System.Diagnostics.Process exep = new System.Diagnostics.Process();
|
||||
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
|
||||
|
@ -16,13 +16,14 @@ namespace PDF3D.Addin
|
||||
private Dictionary<string, int> _shaderIndex = new Dictionary<string, int>();
|
||||
|
||||
private Parent nullParent = new Parent() { Name = "<NULL>", Transform = new Transform4x4() };
|
||||
|
||||
private ViewResource ViewResource = new ViewResource() { Name = "ALL" };
|
||||
public IDTFBuilder(Autodesk.Revit.DB.Document document)
|
||||
{
|
||||
this.document = document;
|
||||
this._scene = new IDTFScene();
|
||||
}
|
||||
private void AddDefault()
|
||||
|
||||
private void AddDefaultMaterial()
|
||||
{
|
||||
var mat = new MaterialResource()
|
||||
{
|
||||
@ -30,9 +31,17 @@ namespace PDF3D.Addin
|
||||
MaterialDiffuse = System.Drawing.Color.FromArgb(255, 125, 125, 125),
|
||||
};
|
||||
this._scene.MaterialResources.Add(mat.Name, mat);
|
||||
this._scene.ShaderResources.Add(mat.Name, new ShaderResource() { ShaderMaterialName = mat.Name, Name = mat.Name });
|
||||
this._scene.ShaderResources.Add(mat.Name,
|
||||
new ShaderResource() { ShaderMaterialName = mat.Name, Name = mat.Name });
|
||||
_shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count);
|
||||
}
|
||||
private void AddDefaultViewResource()
|
||||
{
|
||||
if (!this._scene.ViewResources.Any())
|
||||
{
|
||||
this._scene.ViewResources.Add(ViewResource.Name, ViewResource);
|
||||
}
|
||||
}
|
||||
|
||||
public bool InsertGroup(string name, string patrent = "")
|
||||
{
|
||||
@ -42,19 +51,26 @@ namespace PDF3D.Addin
|
||||
}
|
||||
else
|
||||
{
|
||||
var group = new Group() { Name = name, Parents = new List<Parent>() { _scene.Groups.Any(x => x.Name == patrent) ? new Parent(patrent) : nullParent } };
|
||||
var group = new Group()
|
||||
{
|
||||
Name = name,
|
||||
Parents = new List<Parent>()
|
||||
{ _scene.Groups.Any(x => x.Name == patrent) ? new Parent(patrent) : nullParent }
|
||||
};
|
||||
this._scene.Groups.Add(group);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool InsertMaterial(Material material)
|
||||
{
|
||||
if (material == null)
|
||||
{
|
||||
if (!this._scene.MaterialResources.ContainsKey("default"))
|
||||
{
|
||||
AddDefault();
|
||||
AddDefaultMaterial();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else if (!this._scene.MaterialResources.ContainsKey(material.Name))
|
||||
@ -62,16 +78,20 @@ namespace PDF3D.Addin
|
||||
var mat = new MaterialResource()
|
||||
{
|
||||
Name = material.Name,
|
||||
MaterialDiffuse = System.Drawing.Color.FromArgb(255, material.Color.Red, material.Color.Green, material.Color.Blue),
|
||||
MaterialDiffuse = System.Drawing.Color.FromArgb(255, material.Color.Red, material.Color.Green,
|
||||
material.Color.Blue),
|
||||
MaterialOpacity = (100 - material.Transparency) / 100f
|
||||
};
|
||||
this._scene.MaterialResources.Add(mat.Name, mat);
|
||||
this._scene.ShaderResources.Add(mat.Name, new ShaderResource() { ShaderMaterialName = mat.Name, Name = mat.Name });
|
||||
this._scene.ShaderResources.Add(mat.Name,
|
||||
new ShaderResource() { ShaderMaterialName = mat.Name, Name = mat.Name });
|
||||
_shaderIndex.Add(mat.Name, this._scene.ShaderResources.Count);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool InsertElement(Element element)
|
||||
{
|
||||
Parent parent;
|
||||
@ -107,9 +127,33 @@ namespace PDF3D.Addin
|
||||
_scene.Models.Add(model);
|
||||
_scene.ModelResources.Add(name, modelRes);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void InsertView(View3D item)
|
||||
{
|
||||
AddDefaultViewResource();
|
||||
IDTF.Net.View view = new IDTF.Net.View() { Name = item.Name, Resource = ViewResource };
|
||||
view.ViewData.ViewAttributeScreenUnit = ViewAttributeScreenUnit.PERCENT;
|
||||
XYZ direction = item.ViewDirection.CrossProduct(item.UpDirection);
|
||||
view.Parents = new List<Parent>()
|
||||
{
|
||||
new Parent()
|
||||
{
|
||||
Name = "<NULL>",
|
||||
Transform = new Transform4x4()
|
||||
{
|
||||
c0r0 = item.ViewDirection.X, c0r1 = item.ViewDirection.Y, c0r2 = item.ViewDirection.Z, c0r3 = 0,
|
||||
c1r0 = item.UpDirection.X, c1r1 = item.UpDirection.Y, c1r2 = item.UpDirection.Z, c1r3 = 0,
|
||||
c2r0 = direction.X, c2r1 = direction.Y, c2r2 =direction.Z, c2r3 = 0,
|
||||
c3r0 = item.Origin.X * 304.8, c3r1 = item.Origin.Y * 304.8, c3r2 = item.Origin.Z * 304.8, c3r3 = 1,
|
||||
}
|
||||
}
|
||||
};
|
||||
this._scene.Views.Add(view);
|
||||
}
|
||||
|
||||
private MeshData ConvertGeometryObject(GeometryObject go)
|
||||
{
|
||||
if (go is GeometryElement ge)
|
||||
@ -123,6 +167,7 @@ namespace PDF3D.Addin
|
||||
CombineMeshdata(meshData, data);
|
||||
}
|
||||
}
|
||||
|
||||
return meshData;
|
||||
}
|
||||
|
||||
@ -130,20 +175,27 @@ namespace PDF3D.Addin
|
||||
{
|
||||
return ConvertGeometryObject(gi.GetInstanceGeometry());
|
||||
}
|
||||
|
||||
if (go is Face face)
|
||||
{
|
||||
var faceMesh = face.Triangulate(0.4);
|
||||
MeshData meshData = new MeshData();
|
||||
meshData.ModelPositionList.AddRange(faceMesh.Vertices.Select(p => new Point3((float)p.X * 304.8f, (float)p.Y * 304.8f, (float)p.Z * 304.8f)));
|
||||
meshData.ModelPositionList.AddRange(faceMesh.Vertices.Select(p =>
|
||||
new Point3((float)p.X * 304.8f, (float)p.Y * 304.8f, (float)p.Z * 304.8f)));
|
||||
for (int i = 0; i < faceMesh.NumTriangles; i++)
|
||||
{
|
||||
var tri = faceMesh.get_Triangle(i);
|
||||
meshData.MeshFacePositionList.Add(new Int3((int)tri.get_Index(0), (int)tri.get_Index(1), (int)tri.get_Index(2)));
|
||||
meshData.MeshFacePositionList.Add(new Int3((int)tri.get_Index(0), (int)tri.get_Index(1),
|
||||
(int)tri.get_Index(2)));
|
||||
}
|
||||
|
||||
var material = face?.MaterialElementId.IntegerValue > 0
|
||||
? (document.GetElement(face?.MaterialElementId) as Autodesk.Revit.DB.Material) : null;
|
||||
? (document.GetElement(face?.MaterialElementId) as Autodesk.Revit.DB.Material)
|
||||
: null;
|
||||
this.InsertMaterial(material);
|
||||
var shaderDesc = material == null ? new ShadingDescription(_shaderIndex["default"]) : new ShadingDescription(_shaderIndex[material.Name]);
|
||||
var shaderDesc = material == null
|
||||
? new ShadingDescription(_shaderIndex["default"])
|
||||
: new ShadingDescription(_shaderIndex[material.Name]);
|
||||
|
||||
meshData.ShadingDescriptionList.Add(shaderDesc);
|
||||
for (int i = 0; i < meshData.MeshFacePositionList.Count; i++)
|
||||
@ -153,20 +205,27 @@ namespace PDF3D.Addin
|
||||
|
||||
return meshData;
|
||||
}
|
||||
|
||||
if (go is Mesh mesh)
|
||||
{
|
||||
MeshData meshData = new MeshData();
|
||||
meshData.ModelPositionList.AddRange(mesh.Vertices.Select(p => new Point3((float)p.X * 304.8f, (float)p.Y * 304.8f, (float)p.Z * 304.8f)));
|
||||
meshData.ModelPositionList.AddRange(mesh.Vertices.Select(p =>
|
||||
new Point3((float)p.X * 304.8f, (float)p.Y * 304.8f, (float)p.Z * 304.8f)));
|
||||
for (int i = 0; i < mesh.NumTriangles; i++)
|
||||
{
|
||||
var tri = mesh.get_Triangle(i);
|
||||
meshData.MeshFacePositionList.Add(new Int3((int)tri.get_Index(0), (int)tri.get_Index(1), (int)tri.get_Index(2)));
|
||||
meshData.MeshFacePositionList.Add(new Int3((int)tri.get_Index(0), (int)tri.get_Index(1),
|
||||
(int)tri.get_Index(2)));
|
||||
}
|
||||
|
||||
var material = mesh?.MaterialElementId.IntegerValue > 0
|
||||
? (document.GetElement(mesh?.MaterialElementId) as Autodesk.Revit.DB.Material) : null;
|
||||
? (document.GetElement(mesh?.MaterialElementId) as Autodesk.Revit.DB.Material)
|
||||
: null;
|
||||
this.InsertMaterial(material);
|
||||
|
||||
var shaderDesc = material == null ? new ShadingDescription(_shaderIndex["default"]) : new ShadingDescription(_shaderIndex[material.Name]);
|
||||
var shaderDesc = material == null
|
||||
? new ShadingDescription(_shaderIndex["default"])
|
||||
: new ShadingDescription(_shaderIndex[material.Name]);
|
||||
|
||||
meshData.ShadingDescriptionList.Add(shaderDesc);
|
||||
for (int i = 0; i < meshData.MeshFacePositionList.Count; i++)
|
||||
@ -176,6 +235,7 @@ namespace PDF3D.Addin
|
||||
|
||||
return meshData;
|
||||
}
|
||||
|
||||
if (go is Solid solid)
|
||||
{
|
||||
var meshData = new MeshData();
|
||||
@ -202,7 +262,8 @@ namespace PDF3D.Addin
|
||||
{
|
||||
var oldCount = data1.ModelPositionList.Count;
|
||||
data1.ModelPositionList.AddRange(data2.ModelPositionList);
|
||||
data1.MeshFacePositionList.AddRange(data2.MeshFacePositionList.Select(x => new Int3(x.IntArray[0] + oldCount, x.IntArray[1] + oldCount, x.IntArray[2] + oldCount)));
|
||||
data1.MeshFacePositionList.AddRange(data2.MeshFacePositionList.Select(x =>
|
||||
new Int3(x.IntArray[0] + oldCount, x.IntArray[1] + oldCount, x.IntArray[2] + oldCount)));
|
||||
for (int i = 0; i < data2.MeshFaceDiffuseColorList.Count; i++)
|
||||
{
|
||||
int index = data2.MeshFaceDiffuseColorList[i].IntArray.ElementAt(0);
|
||||
@ -215,16 +276,20 @@ namespace PDF3D.Addin
|
||||
else
|
||||
{
|
||||
data1.ModelDiffuseColorList.Add(color);
|
||||
data1.MeshFaceDiffuseColorList.Add(new Int3(data1.ModelDiffuseColorList.Count - 1, data1.ModelDiffuseColorList.Count - 1, data1.ModelDiffuseColorList.Count - 1));
|
||||
data1.MeshFaceDiffuseColorList.Add(new Int3(data1.ModelDiffuseColorList.Count - 1,
|
||||
data1.ModelDiffuseColorList.Count - 1, data1.ModelDiffuseColorList.Count - 1));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < data2.MeshFaceShadingList.Count; i++)
|
||||
{
|
||||
var index = data2.MeshFaceShadingList[i];
|
||||
var shader = data2.ShadingDescriptionList[index];
|
||||
if (data1.ShadingDescriptionList.Any(x => x.ShaderID == shader.ShaderID))
|
||||
{
|
||||
int shaderIndex = data1.ShadingDescriptionList.IndexOf(data1.ShadingDescriptionList.FirstOrDefault(x => x.ShaderID == shader.ShaderID));
|
||||
int shaderIndex =
|
||||
data1.ShadingDescriptionList.IndexOf(
|
||||
data1.ShadingDescriptionList.FirstOrDefault(x => x.ShaderID == shader.ShaderID));
|
||||
data1.MeshFaceShadingList.Add(shaderIndex);
|
||||
}
|
||||
else
|
||||
@ -233,7 +298,6 @@ namespace PDF3D.Addin
|
||||
data1.MeshFaceShadingList.Add(data1.ShadingDescriptionList.Count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Export(string path)
|
||||
@ -258,6 +322,7 @@ namespace PDF3D.Addin
|
||||
int c = points.IndexOf(item.Mesh.ModelPositionList[face.IntArray[2]]);
|
||||
item.Mesh.MeshFacePositionList[i] = new Int3(a, b, c);
|
||||
}
|
||||
|
||||
item.Mesh.ModelPositionList = points;
|
||||
}
|
||||
//List<Point3> points = new List<Point3>();
|
||||
@ -284,13 +349,5 @@ namespace PDF3D.Addin
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
internal void InsertView(View3D item)
|
||||
{
|
||||
IDTF.Net.View view = new IDTF.Net.View() { Name = item.Name };
|
||||
ViewData viewData = new ViewData();
|
||||
view.ViewData = viewData;
|
||||
this._scene.Views.Add(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user