Skip to content

Commit

Permalink
Merge pull request #2 from williamwong/master
Browse files Browse the repository at this point in the history
AEC Technology Hackathon 2016
  • Loading branch information
bhowes-tt authored Dec 14, 2016
2 parents 22abbf2 + f94e3e8 commit 2c609cb
Show file tree
Hide file tree
Showing 13 changed files with 530 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
22 changes: 22 additions & 0 deletions src/Spectacles.Net/Spectacles.Net.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectacles.Net", "Spectacles.Net\Spectacles.Net.csproj", "{BBC112A9-8B9F-4ECB-930A-28121A7ABD5C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BBC112A9-8B9F-4ECB-930A-28121A7ABD5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBC112A9-8B9F-4ECB-930A-28121A7ABD5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBC112A9-8B9F-4ECB-930A-28121A7ABD5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBC112A9-8B9F-4ECB-930A-28121A7ABD5C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
80 changes: 80 additions & 0 deletions src/Spectacles.Net/Spectacles.Net/BaseSpectaclesExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Spectacles.Net.Data;

namespace Spectacles.Net
{
/// <summary>
/// An abstract base exporter class that holds an instance of the
/// SpectaclesContainer class and provides hooks to attach data to
/// the properties of the Spectacles container. The class should be
/// extended by individual exporters, providing custom implementations
/// and logic that is unique to the individual application platforms.
/// </summary>
public abstract class BaseSpectaclesExporter : ISpectaclesExporter
{
private readonly SpectaclesContainer _container;

protected BaseSpectaclesExporter()
{
_container = new SpectaclesContainer
{
metadata = new Metadata(),
geometries = new List<SpectaclesGeometry>(),
materials = new List<SpectaclesMaterial>(),
obj = new SpectaclesObject()
};
}

/// <summary>
/// Provides Metadata object to add additional information
/// </summary>
/// <param name="metadata">A Metadata instance</param>
public abstract void OnAddMetadata(Metadata metadata);

/// <summary>
/// Provides SpectaclesGeometry list to add geometry to
/// </summary>
/// <param name="spectaclesGeometries">List of SpectaclesGeometry objects</param>
public abstract void OnAddGeometries(List<SpectaclesGeometry> spectaclesGeometries);

/// <summary>
/// Provides SpectaclesMaterial list to add materials to
/// </summary>
/// <param name="spectaclesMaterials">List of SpectaclesMaterial objects</param>
public abstract void OnAddMaterials(List<SpectaclesMaterial> spectaclesMaterials);


/// <summary>
/// Provides SpectaclesObject to add scene objects to
/// </summary>
/// <param name="spectaclesObject">A SpectaclesObject instance</param>
public abstract void OnAddSpectacleObject(SpectaclesObject spectaclesObject);

/// <summary>
/// Execute JSON serialization
/// </summary>
/// <param name="path">File to save JSON to</param>
/// <returns></returns>
public virtual string ExportToJson(string path)
{
// Execute custom implementations of adding to SpectaclesContainer
OnAddMetadata(_container.metadata);
OnAddGeometries(_container.geometries);
OnAddMaterials(_container.materials);
OnAddSpectacleObject(_container.obj);

// Serialize SpectaclesContainer to JSON
var spectaclesJson = JsonConvert.SerializeObject(_container);

// Write to file
using (var outputFile = new StreamWriter(path))
{
outputFile.Write(spectaclesJson);
}

return spectaclesJson;
}
}
}
16 changes: 16 additions & 0 deletions src/Spectacles.Net/Spectacles.Net/Data/Metadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Runtime.Serialization;

namespace Spectacles.Net.Data
{
public class Metadata
{
[DataMember]
public string type { get; set; } // "Object"

[DataMember]
public double version { get; set; } // 4.3

[DataMember]
public string generator { get; set; } // "Spectacles.RevitExporter Revit Spectacles exporter"
}
}
59 changes: 59 additions & 0 deletions src/Spectacles.Net/Spectacles.Net/Data/SpectaclesContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//The MIT License (MIT)

//Those portions created by va3c authors are provided with the following copyright:

//Copyright (c) 2014 va3c

//Those portions created by Thornton Tomasetti employees are provided with the following copyright:

//Copyright (c) 2015 Thornton Tomasetti

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

#region Namespaces

using System.Collections.Generic;
using System.Runtime.Serialization;

#endregion // Namespaces

namespace Spectacles.Net.Data
{
/// <summary>
/// three.js object class, successor of SpectaclesScene.
/// The structure and properties defined here were
/// reverse engineered ftom JSON files exported
/// by the three.js and Spectacles editors.
/// </summary>
[DataContract]
public class SpectaclesContainer
{
[DataMember]
public Metadata metadata { get; set; }

[DataMember( Name = "object" )]
public SpectaclesObject obj { get; set; }

[DataMember]
public List<SpectaclesGeometry> geometries;

[DataMember]
public List<SpectaclesMaterial> materials;
}
}
24 changes: 24 additions & 0 deletions src/Spectacles.Net/Spectacles.Net/Data/SpectaclesGeometry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Spectacles.Net.Data
{
[DataContract]
public class SpectaclesGeometry
{
[DataMember]
public string uuid { get; set; }

[DataMember]
public string type { get; set; } // "Geometry"

[DataMember]
public SpectaclesGeometryData data { get; set; }

// [DataMember]
// public double scale { get; set; }

[DataMember]
public List<SpectaclesMaterial> materials { get; set; }
}
}
58 changes: 58 additions & 0 deletions src/Spectacles.Net/Spectacles.Net/Data/SpectaclesGeometryData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Spectacles.Net.Data
{
[DataContract]
public class SpectaclesGeometryData
{
// populate data object properties
//jason.data.vertices = new object[mesh.Vertices.Count * 3];
//jason.data.normals = new object[0];
//jason.data.uvs = new object[0];
//jason.data.faces = new object[mesh.Faces.Count * 4];
//jason.data.scale = 1;
//jason.data.visible = true;
//jason.data.castShadow = true;
//jason.data.receiveShadow = false;
//jason.data.doubleSided = true;


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

// for the faces, we will use
// triangle with material
// 00 00 00 10 = 2
// 2, [vertex_index, vertex_index, vertex_index], [material_index] // e.g.:
//
//2, 0,1,2, 0

[DataMember]
public List<double> vertices { get; set; } // millimetres
// "morphTargets": []
[DataMember]
public List<double> normals { get; set; }

// "colors": []
[DataMember]
public List<double> uvs { get; set; }

[DataMember]
public List<int> faces { get; set; } // indices into Vertices + Materials

[DataMember]
public double scale { get; set; }

[DataMember]
public bool visible { get; set; }

[DataMember]
public bool castShadow { get; set; }

[DataMember]
public bool receiveShadow { get; set; }

[DataMember]
public bool doubleSided { get; set; }
}
}
42 changes: 42 additions & 0 deletions src/Spectacles.Net/Spectacles.Net/Data/SpectaclesMaterial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Runtime.Serialization;

namespace Spectacles.Net.Data
{
/// <summary>
/// Based on MeshPhongMaterial obtained by exporting a cube
/// </summary>
public class SpectaclesMaterial
{
[DataMember]
public string uuid { get; set; }

[DataMember]
public string name { get; set; }

[DataMember]
public string type { get; set; } // MeshPhongMaterial

[DataMember]
public string color { get; set; } // 16777215

// [DataMember]
// public int ambient { get; set; } //16777215
//
// [DataMember]
// public int emissive { get; set; } // 1

[DataMember]
public double opacity { get; set; } // 1

[DataMember]
public bool transparent { get; set; } // false

[DataMember]
public bool wireframe { get; set; } // false

// [DataMember]
// public int shading { get; set; } // 1
[DataMember]
public int side { get; set; }
}
}
Loading

0 comments on commit 2c609cb

Please sign in to comment.