12 |
13 |
14 | #pragma pack(push, 8)
15 |
16 | #ifdef __cplusplus
17 | extern "C" {
18 | #endif // __cplusplus
19 |
20 | /**
21 | @struct SUPoint2D
22 | @brief Represents a point in 2-dimensional space.
23 | */
24 | struct SUPoint2D {
25 | double x; ///< X coordinate
26 | double y; ///< Y coordinate
27 | };
28 |
29 | /**
30 | @struct SUVector2D
31 | @brief Represents a vector in 2-dimensional space.
32 | */
33 | struct SUVector2D {
34 | double x; ///< X magnitude
35 | double y; ///< Y magnitude
36 | };
37 |
38 | /**
39 | @struct SUPoint3D
40 | @brief Represents a point in 3-dimensional space.
41 | */
42 | struct SUPoint3D {
43 | double x; ///< X coordinate
44 | double y; ///< Y coordinate
45 | double z; ///< Z coordinate
46 | };
47 |
48 | /**
49 | @struct SUVector3D
50 | @brief Represents a vector in 3-dimensional space.
51 | */
52 | struct SUVector3D {
53 | double x; ///< X magnitude
54 | double y; ///< Y magnitude
55 | double z; ///< Z magnitude
56 | };
57 |
58 | /**
59 | @struct SUPlane3D
60 | @brief Represents a 3D plane by the parameters a, b, c, d.
61 | For any point on the plane, ax + by + cz + d = 0.
62 | The coeficients are normalized so that a*a + b*b + c*c = 1.
63 | */
64 | struct SUPlane3D {
65 | double a; ///< The "a" factor in the plane equation.
66 | double b; ///< The "b" factor in the plane equation.
67 | double c; ///< The "c" factor in the plane equation.
68 | double d; ///< The "d" factor in the plane equation.
69 | };
70 |
71 | /**
72 | @struct SUBoundingBox3D
73 | @brief Represents a 3D axis-aligned bounding box represented by the extreme
74 | diagonal corner points with minimum and maximum x,y,z coordinates.
75 | */
76 | struct SUBoundingBox3D {
77 | struct SUPoint3D min_point; ///< A 3D point where x, y and z are minimum
78 | ///< values in the bounding box
79 | struct SUPoint3D max_point; ///< A 3D point where x, y and z are maximum
80 | ///< values in the bounding box
81 | };
82 |
83 | /**
84 | @struct SUAxisAlignedRect2D
85 | @brief Represents a 2D rectangle that is aligned with the X and Y axis of the
86 | coordinate system.
87 | */
88 | struct SUAxisAlignedRect2D {
89 | struct SUPoint2D upper_left; ///< Upper left corner of the bounding box.
90 | struct SUPoint2D lower_right; ///< Lower right corner of the bounding box.
91 | };
92 |
93 | /**
94 | @struct SURay3D
95 | @brief Represents a 3D ray defined by a point and normal vector.
96 | @since SketchUp 2018, API 6.0
97 | */
98 | struct SURay3D {
99 | struct SUPoint3D point; ///< Origin of the ray.
100 | struct SUVector3D normal; ///< Direction of the ray.
101 | };
102 |
103 | /**
104 | @struct SUTransformation
105 | @brief Represents a 3D (4x4) geometric transformation matrix.
106 |
107 | Matrix values are in column-major order.
108 | The transformation is stored as:
109 |
110 | @code{.txt}
111 | - -
112 | | R T |
113 | M = | 0 w |
114 | - -
115 | @endcode
116 |
117 | where:
118 |
119 | - M is a 4x4 matrix
120 |
- R is a 3x3 sub-matrix. It is the rotation part
121 |
- T is a 3x1 sub-matrix. It is the translation part
122 |
- w is a scalar. It is 1/scale.
123 |
124 | */
125 | struct SUTransformation {
126 | double values[16]; ///< Matrix values in column-major order.
127 | };
128 |
129 | /**
130 | @struct SUTransformation2D
131 | @brief Represents a 2D (2x3) affine transformation matrix. The matrix
132 | is stored in column-major format:
133 |
134 | m11 m21 tx
135 | m12 m22 ty
136 |
137 | */
138 | struct SUTransformation2D {
139 | double m11; ///< the m11 component
140 | double m12; ///< the m12 component
141 | double m21; ///< the m21 component
142 | double m22; ///< the m22 component
143 | double tx; ///< the tx component
144 | double ty; ///< the ty component
145 | };
146 |
147 | #ifdef __cplusplus
148 | } // end extern "C"
149 | #endif // __cplusplus
150 |
151 | #pragma pack(pop)
152 |
153 | #endif // SKETCHUP_GEOMETRY_H_
154 |
--------------------------------------------------------------------------------
/API/SketchUpAPI/application/ruby_api.h:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Trimble Inc. All Rights Reserved.
2 |
3 | /**
4 | * @file
5 | * @brief Interfaces for exchanging data between SketchUp's Ruby API and C API.
6 | *
7 | * @note This is for use only within the SketchUp application.
8 | */
9 | #ifndef SKETCHUP_APPLICATION_RUBY_API_H_
10 | #define SKETCHUP_APPLICATION_RUBY_API_H_
11 |
12 | #include
13 | #include
14 | #pragma pack(push, 8)
15 |
16 | #ifdef __cplusplus
17 | extern "C" {
18 | #endif
19 |
20 | /**
21 | @brief This macro is defining a type matching Ruby's own `VALUE` type and
22 | can be used interchangeably.
23 | */
24 | #ifdef __APPLE__
25 | #define RUBY_VALUE unsigned long
26 | #elif _WIN32
27 | #define RUBY_VALUE unsigned long long
28 | #else
29 | #warning "Unsupported platform"
30 | #define RUBY_VALUE unsigned long
31 | #endif
32 |
33 | /**
34 | @brief Converts a C API entity to a Ruby API entity.
35 |
36 | @since SketchUp 2020.2, API 8.2
37 |
38 | @param[in] entity The C API entity reference.
39 | @param[out] ruby_entity The retrieved Ruby API entity reference.
40 | @see SUModelRef
41 | @return
42 | - \ref SU_ERROR_NONE on success
43 | - \ref SU_ERROR_INVALID_INPUT if \p entity is an invalid object
44 | - \ref SU_ERROR_INVALID_ARGUMENT if \p entity is not owned by a model
45 | - \ref SU_ERROR_NULL_POINTER_OUTPUT if \p ruby_entity is `NULL`
46 | - \ref SU_ERROR_NO_DATA if this isn't called from within SketchUp
47 | */
48 | SU_RESULT SUEntityToRuby(SUEntityRef entity, RUBY_VALUE* ruby_entity);
49 |
50 | /**
51 | @brief Converts a Ruby API entity to a C API entity.
52 |
53 | @since SketchUp 2020.2, API 8.2
54 |
55 | @param[in] ruby_entity The Ruby API entity reference.
56 | @param[out] entity The retrieved C API entity reference.
57 | @see SUModelRef
58 | @return
59 | - \ref SU_ERROR_NONE on success
60 | - \ref SU_ERROR_INVALID_ARGUMENT if \p ruby_entity refers to a deleted entity
61 | - \ref SU_ERROR_INVALID_ARGUMENT if \p ruby_entity is not an entity type
62 | - \ref SU_ERROR_NULL_POINTER_OUTPUT if \p entity is `NULL`
63 | - \ref SU_ERROR_OVERWRITE_VALID if \p entity is already a valid reference
64 | - \ref SU_ERROR_NO_DATA if this isn't called from within SketchUp
65 | */
66 | SU_RESULT SUEntityFromRuby(RUBY_VALUE ruby_entity, SUEntityRef* entity);
67 |
68 | /**
69 | @brief Converts a C API entity to a Ruby API imagerep.
70 |
71 | @note Ruby takes ownership of the object it should not be released by
72 | SUImageRepRelease. It will be released when Ruby garbage collects the
73 | Ruby references to it.
74 |
75 | @since SketchUp 2020.2, API 8.2
76 |
77 | @param[in] imagerep The C API imagerep reference.
78 | @param[out] ruby_imagerep The retrieved Ruby API imagerep reference.
79 | @see SUModelRef
80 | @return
81 | - \ref SU_ERROR_NONE on success
82 | - \ref SU_ERROR_INVALID_INPUT if \p imagerep is an invalid object
83 | - \ref SU_ERROR_NULL_POINTER_OUTPUT if \p ruby_imagerep is `NULL`
84 | - \ref SU_ERROR_NO_DATA if this isn't called from within SketchUp
85 | */
86 | SU_RESULT SUImageRepToRuby(SUImageRepRef imagerep, RUBY_VALUE* ruby_imagerep);
87 |
88 | /**
89 | @brief Converts a Ruby API imagerep to a C API imagerep.
90 |
91 | @note Ruby retains the ownership of the object it should not be released by
92 | SUImageRepRelease.
93 |
94 | @warning The returned C API reference points to an object that is owned by the
95 | Ruby runtime and it may be garbage collected. To avoid this, ensure
96 | that the Ruby API reference has a longer lifetime than the C API
97 | reference.
98 |
99 | @since SketchUp 2020.2, API 8.2
100 |
101 | @param[in] ruby_imagerep The Ruby API imagerep reference.
102 | @param[out] imagerep The retrieved C API imagerep reference.
103 | @see SUModelRef
104 | @return
105 | - \ref SU_ERROR_NONE on success
106 | - \ref SU_ERROR_INVALID_ARGUMENT if \p ruby_imagerep is not an imagerep type
107 | - \ref SU_ERROR_NULL_POINTER_OUTPUT if \p imagerep is `NULL`
108 | - \ref SU_ERROR_OVERWRITE_VALID if \p imagerep is already a valid reference
109 | - \ref SU_ERROR_NO_DATA if this isn't called from within SketchUp
110 | */
111 | SU_RESULT SUImageRepFromRuby(RUBY_VALUE ruby_imagerep, SUImageRepRef* imagerep);
112 |
113 | #ifdef __cplusplus
114 | }
115 | #endif
116 | #pragma pack(pop)
117 |
118 | #endif // SKETCHUP_APPLICATION_RUBY_API_H_
119 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 | .vs
10 |
11 | # Build results
12 | [Dd]ebug/
13 | [Dd]ebugPublic/
14 | [Rr]elease/
15 | [Rr]eleases/
16 | x64/
17 | x86/
18 | build/
19 | bld/
20 | [Bb]in/
21 | [Oo]bj/
22 |
23 | # Roslyn cache directories
24 | *.ide/
25 |
26 | # MSTest test Results
27 | [Tt]est[Rr]esult*/
28 | [Bb]uild[Ll]og.*
29 |
30 | #NUNIT
31 | *.VisualState.xml
32 | TestResult.xml
33 |
34 | # Build Results of an ATL Project
35 | [Dd]ebugPS/
36 | [Rr]eleasePS/
37 | dlldata.c
38 |
39 | *_i.c
40 | *_p.c
41 | *_i.h
42 | *.ilk
43 | *.meta
44 | *.obj
45 | *.pch
46 | *.pdb
47 | *.pgc
48 | *.pgd
49 | *.rsp
50 | *.sbr
51 | *.tlb
52 | *.tli
53 | *.tlh
54 | *.tmp
55 | *.tmp_proj
56 | *.log
57 | *.vspscc
58 | *.vssscc
59 | .builds
60 | *.pidb
61 | *.svclog
62 | *.scc
63 |
64 | # Chutzpah Test files
65 | _Chutzpah*
66 |
67 | # Visual C++ cache files
68 | ipch/
69 | *.aps
70 | *.ncb
71 | *.opensdf
72 | *.sdf
73 | *.cachefile
74 |
75 | # Visual Studio profiler
76 | *.psess
77 | *.vsp
78 | *.vspx
79 |
80 | # TFS 2012 Local Workspace
81 | $tf/
82 |
83 | # Guidance Automation Toolkit
84 | *.gpState
85 |
86 | # ReSharper is a .NET coding add-in
87 | _ReSharper*/
88 | *.[Rr]e[Ss]harper
89 | *.DotSettings.user
90 |
91 | # JustCode is a .NET coding addin-in
92 | .JustCode
93 |
94 | # TeamCity is a build add-in
95 | _TeamCity*
96 |
97 | # DotCover is a Code Coverage Tool
98 | *.dotCover
99 |
100 | # NCrunch
101 | _NCrunch_*
102 | .*crunch*.local.xml
103 |
104 | # MightyMoose
105 | *.mm.*
106 | AutoTest.Net/
107 |
108 | # Web workbench (sass)
109 | .sass-cache/
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.[Pp]ublish.xml
129 | *.azurePubxml
130 | # TODO: Comment the next line if you want to checkin your web deploy settings
131 | # but database connection strings (with potential passwords) will be unencrypted
132 | *.pubxml
133 | *.publishproj
134 |
135 | # NuGet Packages
136 | *.nupkg
137 | # The packages folder can be ignored because of Package Restore
138 | **/packages/*
139 | # except build/, which is used as an MSBuild target.
140 | !**/packages/build/
141 | # If using the old MSBuild-Integrated Package Restore, uncomment this:
142 | #!**/packages/repositories.config
143 |
144 | # Windows Azure Build Output
145 | csx/
146 | *.build.csdef
147 |
148 | # Windows Store app package directory
149 | AppPackages/
150 |
151 | # Others
152 | sql/
153 | *.Cache
154 | ClientBin/
155 | [Ss]tyle[Cc]op.*
156 | ~$*
157 | *~
158 | *.dbmdl
159 | *.dbproj.schemaview
160 | *.pfx
161 | *.publishsettings
162 | node_modules/
163 |
164 | # RIA/Silverlight projects
165 | Generated_Code/
166 |
167 | # Backup & report files from converting an old project file
168 | # to a newer Visual Studio version. Backup files are not needed,
169 | # because we have git ;-)
170 | _UpgradeReport_Files/
171 | Backup*/
172 | UpgradeLog*.XML
173 | UpgradeLog*.htm
174 |
175 | # SQL Server files
176 | *.mdf
177 | *.ldf
178 |
179 | # Business Intelligence projects
180 | *.rdl.data
181 | *.bim.layout
182 | *.bim_*.settings
183 |
184 | # Microsoft Fakes
185 | FakesAssemblies/
186 |
187 | # =========================
188 | # Operating System Files
189 | # =========================
190 |
191 | # OSX
192 | # =========================
193 |
194 | .DS_Store
195 | .AppleDouble
196 | .LSOverride
197 |
198 | # Thumbnails
199 | ._*
200 |
201 | # Files that might appear on external disk
202 | .Spotlight-V100
203 | .Trashes
204 |
205 | # Directories potentially created on remote AFP share
206 | .AppleDB
207 | .AppleDesktop
208 | Network Trash Folder
209 | Temporary Items
210 | .apdisk
211 |
212 | # Windows
213 | # =========================
214 |
215 | # Windows image file caches
216 | Thumbs.db
217 | ehthumbs.db
218 |
219 | # Folder config file
220 | Desktop.ini
221 |
222 | # Recycle Bin used on file shares
223 | $RECYCLE.BIN/
224 |
225 | # Windows Installer files
226 | *.cab
227 | *.msi
228 | *.msm
229 | *.msp
230 |
231 | # Windows shortcuts
232 | *.lnk
233 |
--------------------------------------------------------------------------------
/SketchUpNET/Mesh.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | SketchUpNET - a C++ Wrapper for the Trimble(R) SketchUp(R) C API
4 | Copyright(C) 2015, Autor: Maximilian Thumfart
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 |
20 | */
21 |
22 | #pragma once
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include "loop.h"
39 | #include "vertex.h"
40 | #include "vector.h"
41 | #include "utilities.h"
42 | #include "MeshFace.h"
43 |
44 |
45 | using namespace System;
46 | using namespace System::Collections;
47 | using namespace System::Collections::Generic;
48 |
49 | namespace SketchUpNET
50 | {
51 | public ref class Mesh
52 | {
53 | public:
54 |
55 | List^ Vertices;
56 | List^ Normals;
57 | List^ Faces;
58 |
59 | System::String^ Layer;
60 |
61 | Mesh(List^ vs, List^ ns, List^ faces, System::String^ layer)
62 | {
63 | this->Vertices = vs;
64 | this->Normals = ns;
65 | this->Faces = faces;
66 | this->Layer = layer;
67 | };
68 |
69 | Mesh() {};
70 | internal:
71 |
72 |
73 |
74 | static Mesh^ FromSU(SUFaceRef face)
75 | {
76 | List^ vertices = gcnew List();
77 | List^ vectors = gcnew List();
78 | List^ faces = gcnew List();
79 |
80 | // Layer
81 | SULayerRef layer = SU_INVALID;
82 | SUDrawingElementGetLayer(SUFaceToDrawingElement(face), &layer);
83 |
84 | System::String^ layername = gcnew System::String("");
85 | if (!SUIsInvalid(layer))
86 | {
87 | layername = Utilities::GetLayerName(layer);
88 | }
89 |
90 | SUMeshHelperRef helper = SU_INVALID;
91 | SUMeshHelperCreate(&helper, face);
92 |
93 | size_t vCount = 0;
94 | SUMeshHelperGetNumVertices(helper, &vCount);
95 | if (vCount > 0)
96 | {
97 | std::vector vs(vCount);
98 | SUMeshHelperGetVertices(helper,vCount, &vs[0], &vCount);
99 |
100 | for (size_t j = 0; j < vCount; j++)
101 | {
102 | vertices->Add(Vertex::FromSU(vs[j]));
103 | }
104 | }
105 |
106 |
107 |
108 | size_t fCount = 0;
109 | size_t ret = 0;
110 | SUMeshHelperGetNumTriangles(helper, &fCount);
111 | if (fCount > 0)
112 | {
113 |
114 | std::vector fs(3 * fCount);
115 | SUMeshHelperGetVertexIndices(helper, 3*fCount, &fs[0], &ret);
116 |
117 | for (size_t j = 0; j < 3*fCount; j=j+3)
118 | {
119 | faces->Add(gcnew MeshFace(fs[j], fs[j+1], fs[j + 2]));
120 | }
121 | }
122 |
123 |
124 | size_t nCount = 0;
125 | SUMeshHelperGetNumTriangles(helper, &nCount);
126 | if (nCount > 0)
127 | {
128 | std::vector norms(nCount);
129 | SUMeshHelperGetNormals(helper, nCount, &norms[0], &nCount);
130 |
131 | for (size_t j = 0; j < nCount; j++)
132 | {
133 | vectors->Add(Vector::FromSU(norms[j]));
134 | }
135 | }
136 |
137 | SUMeshHelperRelease(&helper);
138 |
139 | Mesh^ m = gcnew Mesh(vertices,vectors, faces, layername);
140 |
141 | return m;
142 | }
143 |
144 |
145 | };
146 |
147 |
148 | }
--------------------------------------------------------------------------------
/SketchUpNET/Material.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | SketchUpNET - a C++ Wrapper for the Trimble(R) SketchUp(R) C API
4 | Copyright(C) 2015, Autor: Maximilian Thumfart
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 |
20 | */
21 | #pragma once
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include