master #4

Merged
Zhang merged 11 commits from :master into master 2021-03-15 18:05:19 +08:00
30 changed files with 2418775 additions and 1 deletions

View File

@ -19,3 +19,5 @@
## 打卡
1. 尹莫波-demo文件夹
2. 林家烁-ljs文件夹

View File

@ -96,7 +96,7 @@ BIMLoader = function(json)
var edges = new THREE.EdgesGeometry(mesh.geometry);
var line = new THREE.LineSegments(edges, new THREE.LineBasicMaterial({color: 0xff0000}));
obj.add(mesh);
obj.add(mesh.clone());
obj.add(line);
}
}

316
20210129/hcx/TestCommand.cs Normal file
View File

@ -0,0 +1,316 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System.IO;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.Collections;
namespace WebGL
{
[Transaction(TransactionMode.Manual)]
public class TestCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
#region MyRegion
List<Reference> refes = null;
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
try
{
refes = uiDoc.Selection.PickObjects(ObjectType.Element, "选择Element").ToList();
}
catch
{
return Result.Cancelled;
}
List<MyElement> myElements = new List<MyElement>();
List<MyMaterial> myMaterials = new List<MyMaterial>();
List<MyMesh> myMeshes = new List<MyMesh>();
Transaction trans = new Transaction(doc, "1212");
trans.Start();
foreach (var refe in refes)
{
List<XYZ> points = new List<XYZ>();
Element element = doc.GetElement(refe);
Color color = new Color(0, 0, 0);
int transparent = 0;
var materialIds = element.GetMaterialIds(false).ToList();
foreach (var materialId in materialIds)
{
var material = doc.GetElement(materialId) as Material;
if (material != null)
{
transparent = material.Transparency;
color = material.Color;
}
myMaterials.Add(new MyMaterial { color = ToHexColor(color), transparent = transparent });
}
//顶点索引
List<int> indices = new List<int>();
var solids = GetSolidByElement(element, ViewDetailLevel.Fine);
foreach (var solid in solids)
{
var faces = solid.Faces;
//循环每个面
foreach (Face face in faces)
{
// 对每个面进行三角面片化
Mesh mesh = face.Triangulate();
if (mesh == null) continue;
for (int i = 0; i < mesh.NumTriangles; i++)
{
MeshTriangle triangular = mesh.get_Triangle(i);
for (int n = 0; n < 3; n++)
{
XYZ point = triangular.get_Vertex(n);
if (points.Count == 0)
{
points.Add(point);
indices.Add(points.Count - 1);
}
else
{
XYZ tempPoint = points.Where(a => a.DistanceTo(point) < 0.01).FirstOrDefault();
if (tempPoint != null)
{
int index = points.IndexOf(tempPoint);
indices.Add(index);
}
else
{
points.Add(point);
indices.Add(points.Count - 1);
}
}
}
}
}
}
//顶点坐标
List<double> listVertices = new List<double>();
foreach (var point in points)
{
listVertices.Add(point.X * 304.8);
listVertices.Add(point.Y * 304.8);
listVertices.Add(point.Z * 304.8);
}
//顶点法线
List<double> normals = new List<double>();
for (int i = 1; i <= indices.Count; i++)
{
if (i % 3 == 0)
{
XYZ point1 = points[indices[i - 3]];
XYZ point2 = points[indices[i - 2]];
XYZ point3 = points[indices[i - 1]];
//(P0 - P1) 叉乘 (P2 - P1
var normal_1 = (point2 - point1).CrossProduct(point3 - point1).Normalize();
var normal_2 = (point1 - point2).CrossProduct(point3 - point2).Normalize();
var normal_3 = (point1 - point3).CrossProduct(point1 - point3).Normalize();
double[] normal1 = new double[3];
normal1[0] = normal_1.X;
normal1[1] = normal_1.Y;
normal1[2] = normal_1.Z;
double[] normal2 = new double[3];
normal2[0] = normal_1.X;
normal2[1] = normal_1.Y;
normal2[2] = normal_1.Z;
double[] normal3 = new double[3];
normal3[0] = normal_1.X;
normal3[1] = normal_1.Y;
normal3[2] = normal_1.Z;
//x,y,z
normals.Add(normal1[0]);
normals.Add(normal1[1]);
normals.Add(normal1[2]);
normals.Add(normal2[0]);
normals.Add(normal2[1]);
normals.Add(normal2[2]);
normals.Add(normal3[0]);
normals.Add(normal3[1]);
normals.Add(normal3[2]);
}
}
List<double> transfroms = new List<double>();
transfroms.Add(1);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(1);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(1);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(0);
transfroms.Add(1);
ElementInfo info = new ElementInfo
{
name = element.Name
};
myMeshes.Add(new MyMesh()
{
indices = indices,
vertices = listVertices,
material = myMaterials.Count - 1,
normals = normals
});
myElements.Add(new MyElement()
{
id = element.Id.ToString(),
mesh = myMeshes.Count - 1,
transform = transfroms,
visible = 1.0f,
info = info
});
}
trans.Commit();
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "json文件 (*.json)|*.json";
dialog.DefaultExt = ".json";
dialog.Title = "导出配置文件";
if (dialog.ShowDialog() == DialogResult.OK)
{
var Model = new
{
instances = myElements,
meshes = myMeshes,
materials = myMaterials
};
File.WriteAllText(dialog.FileName, JsonConvert.SerializeObject(Model, Formatting.Indented));
}
#endregion
return Result.Succeeded;
}
private string ToHexColor(Color color)
{
string R = Convert.ToString(color.Red, 16);
if (R == "0")
R = "00";
string G = Convert.ToString(color.Green, 16);
if (G == "0")
G = "00";
string B = Convert.ToString(color.Blue, 16);
if (B == "0")
B = "00";
string HexColor = "#" + R + G + B;
return HexColor;
}
private IList<Solid> GetSolidByElement(Element element, ViewDetailLevel viewDetailLevel)
{
List<Solid> lstSolid = new List<Solid>();
try
{
Options options = new Options();
options.IncludeNonVisibleObjects = false;
options.DetailLevel = viewDetailLevel;
options.ComputeReferences = true;
GeometryElement geoElement = element.get_Geometry(options);
IEnumerator enumerator = geoElement.GetEnumerator();
{
while (enumerator.MoveNext())
{
GeometryObject geoObj = enumerator.Current as GeometryObject;
if (geoObj is GeometryInstance)
{
GeometryInstance geoinstance = geoObj as GeometryInstance;
GeometryElement geoObjtmp = geoinstance.GetInstanceGeometry();
//GeometryElement geoObjtmp = geoinstance.GetSymbolGeometry();
IEnumerator enumeratorobj = geoObjtmp.GetEnumerator();
{
while (enumeratorobj.MoveNext())
{
GeometryObject obj2 = enumeratorobj.Current as GeometryObject;
if (obj2 is Solid)
{
lstSolid.Add(obj2 as Solid);
}
}
}
}
else if (geoObj is Solid)
{
lstSolid.Add(geoObj as Solid);
}
}
}
}
catch
{
//throw;
}
return lstSolid;
}
}
public class MyElement
{
public string id { get; set; }
public List<double> transform { get; set; }
public float visible { get; set; }
public int mesh { get; set; }
public ElementInfo info { get; set; }
}
public class ElementInfo
{
public string name { get; set; }
}
public class MyMesh
{
public List<double> vertices { get; set; }
public List<double> normals { get; set; }
public List<int> indices { get; set; }
public int material { get; set; }
}
public class MyMaterial
{
public string color { get; set; }
public int transparent { get; set; }
}
}

2417400
20210129/hcx/bimData.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,109 @@
using Autodesk.Navisworks.Api.Interop.ComApi;
using LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson
{
public class CallbackGeomListener : InwSimplePrimitivesCB
{
//static FileStream aFile = new FileStream(@"C:\Users\Don\Desktop\项目1.txt", FileMode.OpenOrCreate);
//static StreamWriter sw = new StreamWriter(aFile);
public InwLTransform3f3 LCS2WCS;
//public ModelData ModelData { get; set; }
//public List<InwSimpleVertex> vertices { get; set; }
//public List<LineTest> lines { get; set; }
public List<double> vertexes { get; set; }
public List<double> normals { get; set; }
public List<string> vertexes_str { get; set; }
public List<string> normals_str { get; set; }
public CallbackGeomListener()
{
vertexes = new List<double>();
normals = new List<double>();
vertexes_str = new List<string>();
normals_str = new List<string>();
}
public void Line(InwSimpleVertex v1, InwSimpleVertex v2)
{
// do your work
}
public void Point(InwSimpleVertex v1)
{
// do your work
}
public void SnapPoint(InwSimpleVertex v1)
{
// do your work
}
public void Triangle(InwSimpleVertex v1, InwSimpleVertex v2, InwSimpleVertex v3)
{
//var v1Str = TranslationUtils.TranslationCoordLCS2WCS(v1, LCS2WCS);
//vertexes.AddRange(v1Str);
//var v2Str = TranslationUtils.TranslationCoordLCS2WCS(v2, LCS2WCS);
//vertexes.AddRange(v2Str);
//var v3Str = TranslationUtils.TranslationCoordLCS2WCS(v3, LCS2WCS);
//vertexes.AddRange(v3Str);
//var n1Str = TranslationUtils.TranslationNormalLCS2WCS(v1, LCS2WCS);
//normals.AddRange(n1Str);
//var n2Str = TranslationUtils.TranslationNormalLCS2WCS(v2, LCS2WCS);
//normals.AddRange(n2Str);
//var n3Str = TranslationUtils.TranslationNormalLCS2WCS(v3, LCS2WCS);
//normals.AddRange(n3Str);
//vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v1, LCS2WCS));
//vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v2, LCS2WCS));
//vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v3, LCS2WCS));
//normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v1, LCS2WCS));
//normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v2, LCS2WCS));
//normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v3, LCS2WCS));
var v1Str = TranslationUtils.TranslationCoordLCS2WCS(v1);
vertexes.AddRange(v1Str);
var v2Str = TranslationUtils.TranslationCoordLCS2WCS(v2);
vertexes.AddRange(v2Str);
var v3Str = TranslationUtils.TranslationCoordLCS2WCS(v3);
vertexes.AddRange(v3Str);
var n1Str = TranslationUtils.TranslationNormalLCS2WCS(v1);
normals.AddRange(n1Str);
var n2Str = TranslationUtils.TranslationNormalLCS2WCS(v2);
normals.AddRange(n2Str);
var n3Str = TranslationUtils.TranslationNormalLCS2WCS(v3);
normals.AddRange(n3Str);
vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v1));
vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v2));
vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v3));
normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v1));
normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v2));
normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v3));
}
~CallbackGeomListener()
{
//sw.Close();
}
}
}

View File

@ -0,0 +1,134 @@
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using Application = Autodesk.Navisworks.Api.Application;
using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;
using LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models;
using System.IO;
using System.Reflection;
using Autodesk.Navisworks.Api.ComApi;
using LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson;
using Autodesk.Navisworks.Api.Interop.ComApi;
namespace LjsGo.Navisworks.GraphicsAssignment
{
//基本插件
[Plugin("Basic", "ADSK", ToolTip = "Popups", DisplayName = "TestTest")]//名字,开发者号(四位字串),提示,用户界面显示名
[AddInPlugin(AddInLocation.AddIn)]//设定插件的位置
public class ExportGeometryToJsonCmd : AddInPlugin
{
private static string AssemblyPath = Path.GetDirectoryName(typeof(ExportGeometryToJsonCmd).Assembly.Location);
public override int Execute(params string[] parameters)
{
try
{
//当前文档
Document doc = Application.ActiveDocument;//application是运行了之后自动提供的
// get the current selection
ModelItemCollection oModelColl = Application.ActiveDocument.CurrentSelection.SelectedItems;
//convert to COM selection
InwOpState oState = ComApiBridge.State;
InwOpSelection oSel = ComApiBridge.ToInwOpSelection(oModelColl);
// create the callback object
var instances = new List<Instance>();
var meshs = new List<Mesh>();
var materials = new List<Material> { new Material { color = "#808080", transparent = 1.0 }};
ModelData modelData = new ModelData
{
instances = instances,
meshes = meshs,
materials = materials,
};
var instanceIndex = 0;
foreach (InwOaPath3 path in oSel.Paths())
{
Instance instance = new Instance
{
id = Guid.NewGuid().ToString(),
info = new { Name = "test" },
mesh = instanceIndex,
visible = 1,
};
instances.Add(instance);
CallbackGeomListener callbkListener = new CallbackGeomListener();
var vertices_str = new List<string>();
var normals_str = new List<string>();
var vertices = new List<double>();
var normals = new List<double>();
var indices = new List<int>();
foreach (InwOaFragment3 frag in path.Fragments())
{
InwLTransform3f3 localToWorld = (InwLTransform3f3)(object)frag.GetLocalToWorldMatrix();
callbkListener.LCS2WCS = localToWorld;
var transfrom = new List<double>();
foreach (double item in (Array)localToWorld.Matrix)
{
transfrom.Add(item);
}
instance.transform = transfrom.ToArray();
// generate the primitives
frag.GenerateSimplePrimitives(nwEVertexProperty.eNORMAL, callbkListener);
vertices_str.AddRange(callbkListener.vertexes_str);
normals_str.AddRange(callbkListener.normals_str);
vertices.AddRange(callbkListener.vertexes);
normals.AddRange(callbkListener.normals);
for (int q = 0; q < callbkListener.vertexes_str.Count && q < callbkListener.normals_str.Count; q++)
{
for (int i = 0; i < vertices_str.Count && i < normals_str.Count; i++)
{
if (vertices_str[i] == callbkListener.vertexes_str[q] && normals_str[i] == callbkListener.normals_str[q])
{
indices.Add(i);
break;
}
}
}
}
Mesh mesh = new Mesh()
{
vertices = vertices,
normals = normals,
indices = indices,
material = 0,
};
meshs.Add(mesh);
instanceIndex++;
}
var json = Kooboo.Json.JsonSerializer.ToJson(modelData);
var fileInfo = new FileInfo(doc.FileName);
var dir = fileInfo.Directory.FullName;
var savePath = Path.Combine(dir, "test.json");
File.WriteAllText(savePath, json);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return 0;
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class Instance
{
public string id { get; set; }
public double[] transform { get; set; }
public double visible { get; set; }
public int mesh { get; set; }
public object info { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class InstanceInfo
{
public InstanceInfo()
{
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ComBridge = Autodesk.Navisworks.Api.ComApi.ComApiBridge;
using COMApi = Autodesk.Navisworks.Api.Interop.ComApi;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class LineTest
{
public string Start { get; set; }
public string End { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class Material
{
public string color { get; set; }
public double transparent { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class Mesh
{
public List<double> vertices { get; set; }
public List<int> indices { get; set; }
public List<double> normals { get; set; }
public int material { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class ModelData
{
public List<Instance> instances { get; set; }
public List<Mesh> meshes { get; set; }
public List<Material> materials { get; set; }
}
}

View File

@ -0,0 +1,130 @@
using Autodesk.Navisworks.Api.Interop.ComApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson
{
public class TranslationUtils
{
public TranslationUtils()
{
}
public static List<double> TranslationNormalLCS2WCS(InwSimpleVertex v1, InwLTransform3f3 LCS2WCS)
{
Array array_v1 = (Array)(object)v1.normal;
//var v1Str = "[" + Convert.ToDouble(array_v1.GetValue(1)) + "," +
// Convert.ToDouble(array_v1.GetValue(2)) + "," +
// Convert.ToDouble(array_v1.GetValue(3)) + "]";
var result = new List<double>
{
Convert.ToDouble(array_v1.GetValue(1)),
Convert.ToDouble(array_v1.GetValue(2)),
Convert.ToDouble(array_v1.GetValue(3)),
};
return result;
}
public static List<double> TranslationCoordLCS2WCS(InwSimpleVertex v1, InwLTransform3f3 LCS2WCS)
{
Array array_v1 = (Array)(object)v1.coord;
double xTrans = LCS2WCS.GetTranslation().data1;
double yTrans = LCS2WCS.GetTranslation().data2;
double zTrans = LCS2WCS.GetTranslation().data3;
//var v1Str = "[" + (Convert.ToDouble(array_v1.GetValue(1)) + xTrans).ToString() + "," +
// (Convert.ToDouble(array_v1.GetValue(2)) + yTrans).ToString() + "," +
// (Convert.ToDouble(array_v1.GetValue(3)) + zTrans).ToString() + "]";
var result = new List<double>
{
Convert.ToDouble(array_v1.GetValue(1)) + xTrans,
Convert.ToDouble(array_v1.GetValue(2)) + yTrans,
Convert.ToDouble(array_v1.GetValue(3)) + zTrans
};
return result;
}
public static string TranslationNormalLCS2WCSStr(InwSimpleVertex v1, InwLTransform3f3 LCS2WCS)
{
Array array_v1 = (Array)(object)v1.normal;
var v1Str = "[" + Convert.ToDouble(array_v1.GetValue(1)) + "," +
Convert.ToDouble(array_v1.GetValue(2)) + "," +
Convert.ToDouble(array_v1.GetValue(3)) + "]";
return v1Str;
}
public static string TranslationCoordLCS2WCSStr(InwSimpleVertex v1, InwLTransform3f3 LCS2WCS)
{
Array array_v1 = (Array)(object)v1.coord;
double xTrans = LCS2WCS.GetTranslation().data1;
double yTrans = LCS2WCS.GetTranslation().data2;
double zTrans = LCS2WCS.GetTranslation().data3;
var v1Str = "[" + (Convert.ToDouble(array_v1.GetValue(1)) + xTrans).ToString() + "," +
(Convert.ToDouble(array_v1.GetValue(2)) + yTrans).ToString() + "," +
(Convert.ToDouble(array_v1.GetValue(3)) + zTrans).ToString() + "]";
return v1Str;
}
public static List<double> TranslationNormalLCS2WCS(InwSimpleVertex v1)
{
Array array_v1 = (Array)(object)v1.normal;
var result = new List<double>
{
Convert.ToDouble(array_v1.GetValue(1)),
Convert.ToDouble(array_v1.GetValue(2)),
Convert.ToDouble(array_v1.GetValue(3)),
};
return result;
}
public static List<double> TranslationCoordLCS2WCS(InwSimpleVertex v1)
{
Array array_v1 = (Array)(object)v1.coord;
var result = new List<double>
{
Convert.ToDouble(array_v1.GetValue(1)),
Convert.ToDouble(array_v1.GetValue(2)),
Convert.ToDouble(array_v1.GetValue(3))
};
return result;
}
public static string TranslationNormalLCS2WCSStr(InwSimpleVertex v1)
{
Array array_v1 = (Array)(object)v1.normal;
var v1Str = "[" + Convert.ToDouble(array_v1.GetValue(1)) + "," +
Convert.ToDouble(array_v1.GetValue(2)) + "," +
Convert.ToDouble(array_v1.GetValue(3)) + "]";
return v1Str;
}
public static string TranslationCoordLCS2WCSStr(InwSimpleVertex v1)
{
Array array_v1 = (Array)(object)v1.coord;
var v1Str = "[" + Convert.ToDouble(array_v1.GetValue(1)) + "," +
Convert.ToDouble(array_v1.GetValue(2)) + "," +
Convert.ToDouble(array_v1.GetValue(3)) + "]";
return v1Str;
}
}
}

View File

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<UseWpf>True</UseWpf>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Kooboo.Json" Version="1.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="Autodesk.Navisworks.Api">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Navisworks Manage 2019\Autodesk.Navisworks.Api.dll</HintPath>
</Reference>
<Reference Include="Autodesk.Navisworks.ComApi">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Navisworks Manage 2019\Autodesk.Navisworks.ComApi.dll</HintPath>
</Reference>
<Reference Include="Autodesk.Navisworks.Controls">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Navisworks Manage 2019\Autodesk.Navisworks.Controls.dll</HintPath>
</Reference>
<Reference Include="Autodesk.Navisworks.Interop.ComApi">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Navisworks Manage 2019\Autodesk.Navisworks.Interop.ComApi.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Windows" />
<Reference Include="System.Xaml" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
</Target>
</Project>

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LjsGo.Navisworks", "LjsGo.Navisworks\LjsGo.Navisworks.csproj", "{F8254CA1-F4FF-44B7-833B-C074B175CAC0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F8254CA1-F4FF-44B7-833B-C074B175CAC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8254CA1-F4FF-44B7-833B-C074B175CAC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8254CA1-F4FF-44B7-833B-C074B175CAC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8254CA1-F4FF-44B7-833B-C074B175CAC0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7C1D6A6E-3C17-443C-8803-96BD4228E8EE}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,109 @@
using Autodesk.Navisworks.Api.Interop.ComApi;
using LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson
{
public class CallbackGeomListener : InwSimplePrimitivesCB
{
//static FileStream aFile = new FileStream(@"C:\Users\Don\Desktop\项目1.txt", FileMode.OpenOrCreate);
//static StreamWriter sw = new StreamWriter(aFile);
public InwLTransform3f3 LCS2WCS;
//public ModelData ModelData { get; set; }
//public List<InwSimpleVertex> vertices { get; set; }
//public List<LineTest> lines { get; set; }
public List<double> vertexes { get; set; }
public List<double> normals { get; set; }
public List<string> vertexes_str { get; set; }
public List<string> normals_str { get; set; }
public CallbackGeomListener()
{
vertexes = new List<double>();
normals = new List<double>();
vertexes_str = new List<string>();
normals_str = new List<string>();
}
public void Line(InwSimpleVertex v1, InwSimpleVertex v2)
{
// do your work
}
public void Point(InwSimpleVertex v1)
{
// do your work
}
public void SnapPoint(InwSimpleVertex v1)
{
// do your work
}
public void Triangle(InwSimpleVertex v1, InwSimpleVertex v2, InwSimpleVertex v3)
{
//var v1Str = TranslationUtils.TranslationCoordLCS2WCS(v1, LCS2WCS);
//vertexes.AddRange(v1Str);
//var v2Str = TranslationUtils.TranslationCoordLCS2WCS(v2, LCS2WCS);
//vertexes.AddRange(v2Str);
//var v3Str = TranslationUtils.TranslationCoordLCS2WCS(v3, LCS2WCS);
//vertexes.AddRange(v3Str);
//var n1Str = TranslationUtils.TranslationNormalLCS2WCS(v1, LCS2WCS);
//normals.AddRange(n1Str);
//var n2Str = TranslationUtils.TranslationNormalLCS2WCS(v2, LCS2WCS);
//normals.AddRange(n2Str);
//var n3Str = TranslationUtils.TranslationNormalLCS2WCS(v3, LCS2WCS);
//normals.AddRange(n3Str);
//vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v1, LCS2WCS));
//vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v2, LCS2WCS));
//vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v3, LCS2WCS));
//normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v1, LCS2WCS));
//normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v2, LCS2WCS));
//normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v3, LCS2WCS));
var v1Str = TranslationUtils.TranslationCoordLCS2WCS(v1);
vertexes.AddRange(v1Str);
var v2Str = TranslationUtils.TranslationCoordLCS2WCS(v2);
vertexes.AddRange(v2Str);
var v3Str = TranslationUtils.TranslationCoordLCS2WCS(v3);
vertexes.AddRange(v3Str);
var n1Str = TranslationUtils.TranslationNormalLCS2WCS(v1);
normals.AddRange(n1Str);
var n2Str = TranslationUtils.TranslationNormalLCS2WCS(v2);
normals.AddRange(n2Str);
var n3Str = TranslationUtils.TranslationNormalLCS2WCS(v3);
normals.AddRange(n3Str);
vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v1));
vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v2));
vertexes_str.Add(TranslationUtils.TranslationCoordLCS2WCSStr(v3));
normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v1));
normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v2));
normals_str.Add(TranslationUtils.TranslationNormalLCS2WCSStr(v3));
}
~CallbackGeomListener()
{
//sw.Close();
}
}
}

View File

@ -0,0 +1,134 @@
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using Application = Autodesk.Navisworks.Api.Application;
using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;
using LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models;
using System.IO;
using System.Reflection;
using Autodesk.Navisworks.Api.ComApi;
using LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson;
using Autodesk.Navisworks.Api.Interop.ComApi;
namespace LjsGo.Navisworks.GraphicsAssignment
{
//基本插件
[Plugin("Basic", "ADSK", ToolTip = "Popups", DisplayName = "TestTest")]//名字,开发者号(四位字串),提示,用户界面显示名
[AddInPlugin(AddInLocation.AddIn)]//设定插件的位置
public class ExportGeometryToJsonCmd : AddInPlugin
{
private static string AssemblyPath = Path.GetDirectoryName(typeof(ExportGeometryToJsonCmd).Assembly.Location);
public override int Execute(params string[] parameters)
{
try
{
//当前文档
Document doc = Application.ActiveDocument;//application是运行了之后自动提供的
// get the current selection
ModelItemCollection oModelColl = Application.ActiveDocument.CurrentSelection.SelectedItems;
//convert to COM selection
InwOpState oState = ComApiBridge.State;
InwOpSelection oSel = ComApiBridge.ToInwOpSelection(oModelColl);
// create the callback object
var instances = new List<Instance>();
var meshs = new List<Mesh>();
var materials = new List<Material> { new Material { color = "#808080", transparent = 1.0 }};
ModelData modelData = new ModelData
{
instances = instances,
meshes = meshs,
materials = materials,
};
var instanceIndex = 0;
foreach (InwOaPath3 path in oSel.Paths())
{
Instance instance = new Instance
{
id = Guid.NewGuid().ToString(),
info = new { Name = "test" },
mesh = instanceIndex,
visible = 1,
};
instances.Add(instance);
CallbackGeomListener callbkListener = new CallbackGeomListener();
var vertices_str = new List<string>();
var normals_str = new List<string>();
var vertices = new List<double>();
var normals = new List<double>();
var indices = new List<int>();
foreach (InwOaFragment3 frag in path.Fragments())
{
InwLTransform3f3 localToWorld = (InwLTransform3f3)(object)frag.GetLocalToWorldMatrix();
callbkListener.LCS2WCS = localToWorld;
var transfrom = new List<double>();
foreach (double item in (Array)localToWorld.Matrix)
{
transfrom.Add(item);
}
instance.transform = transfrom.ToArray();
// generate the primitives
frag.GenerateSimplePrimitives(nwEVertexProperty.eNORMAL, callbkListener);
vertices_str.AddRange(callbkListener.vertexes_str);
normals_str.AddRange(callbkListener.normals_str);
vertices.AddRange(callbkListener.vertexes);
normals.AddRange(callbkListener.normals);
for (int q = 0; q < callbkListener.vertexes_str.Count && q < callbkListener.normals_str.Count; q++)
{
for (int i = 0; i < vertices_str.Count && i < normals_str.Count; i++)
{
if (vertices_str[i] == callbkListener.vertexes_str[q] && normals_str[i] == callbkListener.normals_str[q])
{
indices.Add(i);
break;
}
}
}
}
Mesh mesh = new Mesh()
{
vertices = vertices,
normals = normals,
indices = indices,
material = 0,
};
meshs.Add(mesh);
instanceIndex++;
}
var json = Kooboo.Json.JsonSerializer.ToJson(modelData);
var fileInfo = new FileInfo(doc.FileName);
var dir = fileInfo.Directory.FullName;
var savePath = Path.Combine(dir, "test.json");
File.WriteAllText(savePath, json);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return 0;
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class Instance
{
public string id { get; set; }
public double[] transform { get; set; }
public double visible { get; set; }
public int mesh { get; set; }
public object info { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class InstanceInfo
{
public InstanceInfo()
{
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ComBridge = Autodesk.Navisworks.Api.ComApi.ComApiBridge;
using COMApi = Autodesk.Navisworks.Api.Interop.ComApi;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class LineTest
{
public string Start { get; set; }
public string End { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class Material
{
public string color { get; set; }
public double transparent { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class Mesh
{
public List<double> vertices { get; set; }
public List<int> indices { get; set; }
public List<double> normals { get; set; }
public int material { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson.Models
{
public class ModelData
{
public List<Instance> instances { get; set; }
public List<Mesh> meshes { get; set; }
public List<Material> materials { get; set; }
}
}

View File

@ -0,0 +1,130 @@
using Autodesk.Navisworks.Api.Interop.ComApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LjsGo.Navisworks.GraphicsAssignment.ExportGeometryToJson
{
public class TranslationUtils
{
public TranslationUtils()
{
}
public static List<double> TranslationNormalLCS2WCS(InwSimpleVertex v1, InwLTransform3f3 LCS2WCS)
{
Array array_v1 = (Array)(object)v1.normal;
//var v1Str = "[" + Convert.ToDouble(array_v1.GetValue(1)) + "," +
// Convert.ToDouble(array_v1.GetValue(2)) + "," +
// Convert.ToDouble(array_v1.GetValue(3)) + "]";
var result = new List<double>
{
Convert.ToDouble(array_v1.GetValue(1)),
Convert.ToDouble(array_v1.GetValue(2)),
Convert.ToDouble(array_v1.GetValue(3)),
};
return result;
}
public static List<double> TranslationCoordLCS2WCS(InwSimpleVertex v1, InwLTransform3f3 LCS2WCS)
{
Array array_v1 = (Array)(object)v1.coord;
double xTrans = LCS2WCS.GetTranslation().data1;
double yTrans = LCS2WCS.GetTranslation().data2;
double zTrans = LCS2WCS.GetTranslation().data3;
//var v1Str = "[" + (Convert.ToDouble(array_v1.GetValue(1)) + xTrans).ToString() + "," +
// (Convert.ToDouble(array_v1.GetValue(2)) + yTrans).ToString() + "," +
// (Convert.ToDouble(array_v1.GetValue(3)) + zTrans).ToString() + "]";
var result = new List<double>
{
Convert.ToDouble(array_v1.GetValue(1)) + xTrans,
Convert.ToDouble(array_v1.GetValue(2)) + yTrans,
Convert.ToDouble(array_v1.GetValue(3)) + zTrans
};
return result;
}
public static string TranslationNormalLCS2WCSStr(InwSimpleVertex v1, InwLTransform3f3 LCS2WCS)
{
Array array_v1 = (Array)(object)v1.normal;
var v1Str = "[" + Convert.ToDouble(array_v1.GetValue(1)) + "," +
Convert.ToDouble(array_v1.GetValue(2)) + "," +
Convert.ToDouble(array_v1.GetValue(3)) + "]";
return v1Str;
}
public static string TranslationCoordLCS2WCSStr(InwSimpleVertex v1, InwLTransform3f3 LCS2WCS)
{
Array array_v1 = (Array)(object)v1.coord;
double xTrans = LCS2WCS.GetTranslation().data1;
double yTrans = LCS2WCS.GetTranslation().data2;
double zTrans = LCS2WCS.GetTranslation().data3;
var v1Str = "[" + (Convert.ToDouble(array_v1.GetValue(1)) + xTrans).ToString() + "," +
(Convert.ToDouble(array_v1.GetValue(2)) + yTrans).ToString() + "," +
(Convert.ToDouble(array_v1.GetValue(3)) + zTrans).ToString() + "]";
return v1Str;
}
public static List<double> TranslationNormalLCS2WCS(InwSimpleVertex v1)
{
Array array_v1 = (Array)(object)v1.normal;
var result = new List<double>
{
Convert.ToDouble(array_v1.GetValue(1)),
Convert.ToDouble(array_v1.GetValue(2)),
Convert.ToDouble(array_v1.GetValue(3)),
};
return result;
}
public static List<double> TranslationCoordLCS2WCS(InwSimpleVertex v1)
{
Array array_v1 = (Array)(object)v1.coord;
var result = new List<double>
{
Convert.ToDouble(array_v1.GetValue(1)),
Convert.ToDouble(array_v1.GetValue(2)),
Convert.ToDouble(array_v1.GetValue(3))
};
return result;
}
public static string TranslationNormalLCS2WCSStr(InwSimpleVertex v1)
{
Array array_v1 = (Array)(object)v1.normal;
var v1Str = "[" + Convert.ToDouble(array_v1.GetValue(1)) + "," +
Convert.ToDouble(array_v1.GetValue(2)) + "," +
Convert.ToDouble(array_v1.GetValue(3)) + "]";
return v1Str;
}
public static string TranslationCoordLCS2WCSStr(InwSimpleVertex v1)
{
Array array_v1 = (Array)(object)v1.coord;
var v1Str = "[" + Convert.ToDouble(array_v1.GetValue(1)) + "," +
Convert.ToDouble(array_v1.GetValue(2)) + "," +
Convert.ToDouble(array_v1.GetValue(3)) + "]";
return v1Str;
}
}
}

View File

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<UseWpf>True</UseWpf>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Kooboo.Json" Version="1.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="Autodesk.Navisworks.Api">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Navisworks Manage 2019\Autodesk.Navisworks.Api.dll</HintPath>
</Reference>
<Reference Include="Autodesk.Navisworks.ComApi">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Navisworks Manage 2019\Autodesk.Navisworks.ComApi.dll</HintPath>
</Reference>
<Reference Include="Autodesk.Navisworks.Controls">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Navisworks Manage 2019\Autodesk.Navisworks.Controls.dll</HintPath>
</Reference>
<Reference Include="Autodesk.Navisworks.Interop.ComApi">
<HintPath>..\..\..\..\..\..\Program Files\Autodesk\Navisworks Manage 2019\Autodesk.Navisworks.Interop.ComApi.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Windows" />
<Reference Include="System.Xaml" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
</Target>
</Project>

1
20210129/ljs/test.json Normal file

File diff suppressed because one or more lines are too long

BIN
20210129/ljs/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

22
20210302/README.md Normal file
View File

@ -0,0 +1,22 @@
# 图形学培训
课件:[图形学培训1.2&1.3-glTF数据结构和扩展](./doc/图形学培训1.2&1.3-glTF数据结构和扩展.pptx)
## 内容
- glTF模型数据介绍
- Draco压缩算法及扩展结构介绍
## 作业
不强制要求,希望大家有空都可以去做一做,将 **Navisworks****Revit** 的模型导出一个glTF的数据文件。
gltTF数据文件的验证器[glTF-Validator](https://github.khronos.org/glTF-Validator/)
相关资料:
![glTF OverView](./doc/gltfOverview-2.0.0b.png)
glTF的官方实现[UnityGLTF](https://github.com/KhronosGroup/UnityGLTF/)
glTF的非官方实现[SharpGLTF](https://github.com/vpenades/SharpGLTF)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 MiB