Skip to content

Commit

Permalink
scale to metres and add element properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Tammik committed May 18, 2014
1 parent c633ba2 commit b9dc721
Show file tree
Hide file tree
Showing 6 changed files with 2,185 additions and 1,474 deletions.
52 changes: 52 additions & 0 deletions RvtVa3c/Util.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Autodesk.Revit.DB;
using System;
using System.Collections.Generic;

namespace RvtVa3c
{
Expand Down Expand Up @@ -77,5 +78,56 @@ public static string ElementDescription(
typeName, categoryName, familyName,
symbolName, e.Id.IntegerValue, e.Name );
}

/// <summary>
/// Return a dictionary of all the given
/// element parameter names and values.
/// </summary>
public static Dictionary<string, string>
GetElementProperties(
Element e,
bool includeType )
{
IList<Parameter> parameters
= e.GetOrderedParameters();

Dictionary<string, string> a
= new Dictionary<string, string>(
parameters.Count );

string key;

foreach( Parameter p in parameters )
{
key = p.Definition.Name;

if( !a.ContainsKey( key ) )
{
a.Add( key, p.AsValueString() );
}
}

if( includeType )
{
ElementId idType = e.GetTypeId();

if( null != idType )
{
Document doc = e.Document;
Element typ = doc.GetElement( idType );
parameters = typ.GetOrderedParameters();
foreach( Parameter p in parameters )
{
key = "Type " + p.Definition.Name;

if( !a.ContainsKey( key ) )
{
a.Add( key, p.AsValueString() );
}
}
}
}
return a;
}
}
}
24 changes: 17 additions & 7 deletions RvtVa3c/Va3cExportContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Va3cExportContext : IExportContext
{
string _output_folder_path = "C:/a/vs/va3c/RvtVa3c/models/";

/// <summary>
/// Scale the model down from millimetres to metres.
/// </summary>
double _scale = 0.001;

/// <summary>
/// If true, switch Y and Z coordinate
/// and flip X to negative.
Expand Down Expand Up @@ -336,7 +341,7 @@ Va3cScene.Va3cMaterial m
CurrentGeometryPerMaterial.type = "Geometry";
CurrentGeometryPerMaterial.data = new Va3cScene.Va3cGeometryData();
CurrentGeometryPerMaterial.data.faces = new List<int>();
CurrentGeometryPerMaterial.data.vertices = new List<long>();
CurrentGeometryPerMaterial.data.vertices = new List<double>();
CurrentGeometryPerMaterial.data.normals = new List<double>();
CurrentGeometryPerMaterial.data.uvs = new List<double>();
CurrentGeometryPerMaterial.data.visible = true;
Expand Down Expand Up @@ -688,17 +693,17 @@ public RenderNodeAction OnElementBegin(
}

public void OnElementEnd(
ElementId elementId )
ElementId id )
{
// Note: this method is invoked even for
// elements that were skipped.

Element e = _doc.GetElement( elementId );
Element e = _doc.GetElement( id );
string uid = e.UniqueId;

Debug.WriteLine( string.Format(
"OnElementEnd: id {0} category {1} name {2}",
elementId.IntegerValue, e.Category.Name, e.Name ) );
id.IntegerValue, e.Category.Name, e.Name ) );

if( _objects.ContainsKey( uid ) )
{
Expand All @@ -719,15 +724,20 @@ public void OnElementEnd(

foreach( KeyValuePair<PointInt, int> p in _vertices[material] )
{
geo.data.vertices.Add( p.Key.X );
geo.data.vertices.Add( p.Key.Y );
geo.data.vertices.Add( p.Key.Z );
geo.data.vertices.Add( _scale * p.Key.X );
geo.data.vertices.Add( _scale * p.Key.Y );
geo.data.vertices.Add( _scale * p.Key.Z );
}
obj.geometry = geo.uuid;
_geometries.Add( geo.uuid, geo );
_currentElement.children.Add( obj );
}

Dictionary<string, string> d
= Util.GetElementProperties( e, true );

_currentElement.userData = d;

_objects.Add( _currentElement.uuid, _currentElement );

_elementStack.Pop();
Expand Down
3 changes: 2 additions & 1 deletion RvtVa3c/Va3cScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Va3cGeometryData
//jason.data.receiveShadow = false;
//jason.data.doubleSided = true;

[DataMember] public List<long> vertices { get; set; } // millimetres
[DataMember] public List<double> vertices { get; set; } // millimetres
// "morphTargets": []
[DataMember] public List<double> normals { get; set; }
// "colors": []
Expand Down Expand Up @@ -122,6 +122,7 @@ public class Va3cObject
//[DataMember] public bool castShadow { get; set; }
//[DataMember] public bool receiveShadow { get; set; }
//[DataMember] public bool doubleSided { get; set; }
[DataMember] public Dictionary<string, string> userData { get; set; }
}

// https://github.com/mrdoob/three.js/wiki/JSON-Model-format-3
Expand Down
Loading

0 comments on commit b9dc721

Please sign in to comment.