Skip to content

Commit

Permalink
first scene implementation for #19
Browse files Browse the repository at this point in the history
moethu committed Aug 29, 2020

Verified

This commit was signed with the committer’s verified signature.
samuelattwood Samuel Attwood
1 parent 2740216 commit cead674
Showing 10 changed files with 166 additions and 16 deletions.
9 changes: 6 additions & 3 deletions SketchUpNET/Curve.cpp
Original file line number Diff line number Diff line change
@@ -47,11 +47,13 @@ namespace SketchUpNET

List<Edge^>^ Edges = gcnew List<Edge^>();
bool isArc;
Int32 ID;

Curve(List<Edge^>^ edges, bool isarc)
Curve(Int32 id, List<Edge^>^ edges, bool isarc)
{
this->Edges = edges;
this->isArc = isarc;
this->ID = id;
};

Curve(){};
@@ -61,7 +63,8 @@ namespace SketchUpNET
static Curve^ FromSU(SUCurveRef curve)
{
List<Edge^>^ edgelist = gcnew List<Edge^>();

int32_t id = -1;
SUEntityGetID(SUCurveToEntity(curve), &id);
size_t edgecount = 0;
SUCurveGetNumEdges(curve, &edgecount);
if (edgecount > 0)
@@ -81,7 +84,7 @@ namespace SketchUpNET
if (type == SUCurveType::SUCurveType_Arc) isArc = true;


Curve^ v = gcnew Curve(edgelist, isArc);
Curve^ v = gcnew Curve(id, edgelist, isArc);

return v;
};
12 changes: 8 additions & 4 deletions SketchUpNET/Edge.cpp
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
#include <SketchUpAPI/unicodestring.h>
#include <SketchUpAPI/model/model.h>
#include <SketchUpAPI/model/entities.h>
#include <SketchUpAPI/model/entity.h>
#include <SketchUpAPI/model/face.h>
#include <SketchUpAPI/model/edge.h>
#include <SketchUpAPI/model/vertex.h>
@@ -50,12 +51,14 @@ namespace SketchUpNET
Vertex^ Start;
Vertex^ End;
System::String^ Layer;
Int32 ID;

Edge(Vertex ^ start, Vertex ^ end, System::String^ layer)
Edge(Int32 id, Vertex ^ start, Vertex ^ end, System::String^ layer)
{
this->Start = start;
this->End = end;
this->Layer = layer;
this->ID = id;
};

Edge(){};
@@ -70,7 +73,8 @@ namespace SketchUpNET
SUPoint3D end;
SUVertexGetPosition(startVertex, &start);
SUVertexGetPosition(endVertex, &end);

int32_t id = -1;
SUEntityGetID(SUEdgeToEntity(edge), &id);
// Layer
SULayerRef layer = SU_INVALID;
SUDrawingElementGetLayer(SUEdgeToDrawingElement(edge), &layer);
@@ -81,7 +85,7 @@ namespace SketchUpNET
layername = SketchUpNET::Utilities::GetLayerName(layer);
}

Edge^ v = gcnew Edge(Vertex::FromSU(start), Vertex::FromSU(end), layername);
Edge^ v = gcnew Edge(id, Vertex::FromSU(start), Vertex::FromSU(end), layername);

return v;
};
@@ -118,7 +122,7 @@ namespace SketchUpNET
{
std::vector<SUEdgeRef> edgevector(edgeCount);
SUEntitiesGetEdges(entities, false, edgeCount, &edgevector[0], &edgeCount);


for (size_t i = 0; i < edgeCount; i++) {
Edge^ edge = Edge::FromSU(edgevector[i]);
9 changes: 6 additions & 3 deletions SketchUpNET/Group.cpp
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ namespace SketchUpNET
/// <summary>
/// Surfaces
/// </summary>
Int32 ID;
List<Surface^>^ Surfaces;
List<Edge^>^ Edges;
List<Curve^>^ Curves;
@@ -63,7 +64,7 @@ namespace SketchUpNET
Transform^ Transformation;
System::String^ Layer;

Group(System::String^ name, List<Surface^>^ surfaces, List<Curve^>^ curves, List<Edge^>^ edges, List<Instance^>^ insts, List<Group^>^ group, Transform^ transformation, System::String^ layername)
Group(Int32 id, System::String^ name, List<Surface^>^ surfaces, List<Curve^>^ curves, List<Edge^>^ edges, List<Instance^>^ insts, List<Group^>^ group, Transform^ transformation, System::String^ layername)
{
this->Name = name;
this->Surfaces = surfaces;
@@ -73,6 +74,7 @@ namespace SketchUpNET
this->Groups = group;
this->Transformation = transformation;
this->Layer = layername;
this->ID = id;
};

Group(){};
@@ -108,8 +110,9 @@ namespace SketchUpNET
{
layername = SketchUpNET::Utilities::GetLayerName(layer);
}

Group^ v = gcnew Group(SketchUpNET::Utilities::GetString(name), surfaces, curves, edges, inst, grps, Transform::FromSU(transform), layername);
int32_t id = -1;
SUEntityGetID(SUGroupToEntity(group), &id);
Group^ v = gcnew Group(id, SketchUpNET::Utilities::GetString(name), surfaces, curves, edges, inst, grps, Transform::FromSU(transform), layername);

return v;
};
10 changes: 7 additions & 3 deletions SketchUpNET/Instance.cpp
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
#include <SketchUpAPI/unicodestring.h>
#include <SketchUpAPI/model/model.h>
#include <SketchUpAPI/model/entities.h>
#include <SketchUpAPI/model/entity.h>
#include <SketchUpAPI/model/face.h>
#include <SketchUpAPI/model/edge.h>
#include <SketchUpAPI/model/layer.h>
@@ -55,14 +56,16 @@ namespace SketchUpNET
System::String^ Guid;
System::Object^ Parent;
System::String^ Layer;
Int32 ID;

Instance(System::String^ name, System::String^ guid, String^ parent, Transform^ transformation, System::String^ layername)
Instance(Int32 id, System::String^ name, System::String^ guid, String^ parent, Transform^ transformation, System::String^ layername)
{
this->Name = name;
this->Transformation = transformation;
this->ParentID = parent;
this->Guid = guid;
this->Layer = layername;
this->ID = id;
};


@@ -105,8 +108,9 @@ namespace SketchUpNET
SUTransformation transform = SU_INVALID;
SUComponentInstanceGetTransform(comp, &transform);


Instance^ v = gcnew Instance(SketchUpNET::Utilities::GetString(name), SketchUpNET::Utilities::GetString(instanceguid), parent, Transform::FromSU(transform), layername);
int32_t id = -1;
SUEntityGetID(SUComponentInstanceToEntity(comp), &id);
Instance^ v = gcnew Instance(id, SketchUpNET::Utilities::GetString(name), SketchUpNET::Utilities::GetString(instanceguid), parent, Transform::FromSU(transform), layername);

return v;
};
82 changes: 82 additions & 0 deletions SketchUpNET/Scene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
SketchUpNET - a C++ Wrapper for the Trimble(R) SketchUp(R) C API
Copyright(C) 2015, Autor: Maximilian Thumfart
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.
*/

#include <SketchUpAPI/slapi.h>
#include <SketchUpAPI/geometry.h>
#include <SketchUpAPI/initialize.h>
#include <SketchUpAPI/unicodestring.h>
#include <SketchUpAPI/model/model.h>
#include <SketchUpAPI/model/entities.h>
#include <SketchUpAPI/model/scene.h>
#include <SketchUpAPI/model/entity.h>
#include <msclr/marshal.h>
#include "utilities.h"
#include "Layer.h"

#pragma once

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;

namespace SketchUpNET
{
public ref class Scene
{
public:

System::String^ Name;
List<Int32>^ hiddenInstanceIds;

Scene(System::String^ name, List<Int32>^ hiddenInstanceIds)
{
this->Name = name;
this->hiddenInstanceIds = hiddenInstanceIds;
};

Scene() {};
internal:
static Scene^ FromSU(SUSceneRef scene)
{
SUStringRef name = SU_INVALID;
SUStringCreate(&name);
SUSceneGetName(scene, &name);

size_t eCount = 0;
SUSceneGetNumHiddenEntities(scene, &eCount);
List<Int32>^ instancelist = gcnew List<Int32>();

if (eCount > 0) {
std::vector<SUEntityRef> ents(eCount);
SUSceneGetHiddenEntities(scene, eCount, &ents[0], &eCount);

for (size_t i = 0; i < eCount; i++) {
int32_t id = -1;
SUEntityGetID(ents[i], &id);
instancelist->Add(id);
}
}

return gcnew Scene(SketchUpNET::Utilities::GetString(name), instancelist);
};
};

}
21 changes: 21 additions & 0 deletions SketchUpNET/Scene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
SketchUpNET - a C++ Wrapper for the Trimble(R) SketchUp(R) C API
Copyright(C) 2015, Autor: Maximilian Thumfart
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.
*/
#include "Scene.cpp"
22 changes: 22 additions & 0 deletions SketchUpNET/SketchUpNET.cpp
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
#include "Group.h"
#include "Instance.h"
#include "Component.h"
#include "Scene.h"

#pragma once

@@ -107,6 +108,11 @@ namespace SketchUpNET
/// </summary>
System::Collections::Generic::List<Edge^>^ Edges;

/// <summary>
/// Containing Scenes
/// </summary>
System::Collections::Generic::List<Scene^>^ Scenes;

/// <summary>
/// Loads a SketchUp Model from filepath without loading Meshes.
/// Use this if you don't need meshed geometries.
@@ -192,6 +198,22 @@ namespace SketchUpNET
}


// Get all Scenes
size_t sCount = 0;
SUModelGetNumScenes(model, &sCount);
Scenes = gcnew System::Collections::Generic::List<Scene^>();

if (sCount > 0) {
std::vector<SUSceneRef> scenes(sCount);
SUModelGetScenes(model, sCount, &scenes[0], &sCount);

for (size_t i = 0; i < sCount; i++) {
Scene^ s = Scene::FromSU(scenes[i]);
Scenes->Add(s);
}
}


// Get all Components
size_t compCount = 0;
SUModelGetNumComponentDefinitions(model, &compCount);
2 changes: 2 additions & 0 deletions SketchUpNET/SketchUpNET.vcxproj
Original file line number Diff line number Diff line change
@@ -159,6 +159,7 @@
<ClCompile Include="Material.cpp" />
<ClCompile Include="Mesh.cpp" />
<ClCompile Include="MeshFace.cpp" />
<ClCompile Include="Scene.cpp" />
<ClCompile Include="SketchUpNET.cpp" />
<ClCompile Include="Surface.cpp" />
<ClCompile Include="Texture.cpp" />
@@ -180,6 +181,7 @@
<ClInclude Include="Mesh.h" />
<ClInclude Include="MeshFace.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Scene.h" />
<ClInclude Include="Surface.h" />
<ClInclude Include="Texture.h" />
<ClInclude Include="Transform.h" />
6 changes: 6 additions & 0 deletions SketchUpNET/SketchUpNET.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -69,6 +69,9 @@
<ClCompile Include="Texture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Scene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Vertex.h">
@@ -125,6 +128,9 @@
<ClInclude Include="Texture.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Scene.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="SketchUpNET.rc">
9 changes: 6 additions & 3 deletions SketchUpNET/Surface.cpp
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ namespace SketchUpNET
public ref class Surface
{
public:
Int32 ID;
Loop^ OuterEdges;
List<Loop^>^ InnerEdges;
List<Vertex^>^ Vertices;
@@ -62,7 +63,7 @@ namespace SketchUpNET

System::String^ Layer;

Surface(Loop^ outer, List<Loop^>^ inner, Vector^ normal, double area, List<Vertex^>^ vertices, Mesh^ m, System::String^ layername, Material^ backmat, Material^ frontmat)
Surface(Int32 id, Loop^ outer, List<Loop^>^ inner, Vector^ normal, double area, List<Vertex^>^ vertices, Mesh^ m, System::String^ layername, Material^ backmat, Material^ frontmat)
{
this->OuterEdges = outer;
this->InnerEdges = inner;
@@ -73,6 +74,7 @@ namespace SketchUpNET
this->Area = area;
this->Vertices = vertices;
this->Layer = layername;
this->ID = id;
};

Surface(){};
@@ -155,7 +157,8 @@ namespace SketchUpNET
static Surface^ FromSU(SUFaceRef face, bool includeMeshes, System::Collections::Generic::Dictionary<String^, Material^>^ materials)
{
List<Loop^>^ inner = gcnew List<Loop^>();

int32_t id = -1;
SUEntityGetID(SUFaceToEntity(face), &id);
SULoopRef outer = SU_INVALID;
SUFaceGetOuterLoop(face, &outer);

@@ -228,7 +231,7 @@ namespace SketchUpNET
Material^ backMat = (materials->ContainsKey(mbackName)) ? materials[mbackName] : Material::FromSU(mback);
Material^ frontMat = (materials->ContainsKey(minnerName)) ? materials[minnerName] : Material::FromSU(minner);

Surface^ v = gcnew Surface(Loop::FromSU(outer), inner, normal, area, vertices,m, layername, backMat, frontMat);
Surface^ v = gcnew Surface(id, Loop::FromSU(outer), inner, normal, area, vertices,m, layername, backMat, frontMat);

return v;
}

0 comments on commit cead674

Please sign in to comment.