Skip to content

Commit

Permalink
Initial source files commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfaynshteyn committed Apr 10, 2019
1 parent 57bee1c commit 7aff79e
Show file tree
Hide file tree
Showing 17 changed files with 2,219 additions and 0 deletions.
67 changes: 67 additions & 0 deletions yulio_gltf_export.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#-----------------------------------------------------------------------------------
# MIT License
#
# Copyright (c) 2019 Yulio Technologies Inc.
#
# 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.
#-----------------------------------------------------------------------------------

Sketchup.require 'sketchup'
Sketchup.require 'extensions'

# 1.1.0 Support 8-bit ubyte indices
# Fixed exception handler
# Fixed an issue for when the json text contained utf8 multibyte characters
# 1.1.1 Fixed inversed textures
# Fixed metallicFactor default value - textured materials had default metallicity of 1 (metal) rather than 0 (diaellectric)
# 1.1.2 Add Sketchup.require
# 1.2.0 Add file-save dialog box when exporting the model, default to the same directory and name as the existing model.
# 1.2.1 Do not export hidden entities
# Export metallicFactor and roughnessFactor from dictionary attributes
# Allow scripted exports to specify filename
# Orientate model to face viewer
# Export textures from group/components
# 1.2.2 Fixed issue with nil material exported in un-grouped geometry
# 1.2.3 Do not export if the entity is on a hidden layer
# Fixed issue with min/max values of accessors
# 1.2.4 sRGB to linear color space conversion
# 1.2.5 Export sampler to correct issues with textures
# 1.3.0 Remove support for original Microsoft .glb files, as they have now fixed their issues
# Allow setting material metallic, roughness, emissive, and doubleSided properties through material naming convention
# Add BLEND property if the material contains a texture, as it might contain alpha transparency and the Sketchup API doesn't tell us.
# Fixed an issue where the material from an outer group or component being used to paint nested faces was not used in the final model.
# Set glTF copyright field from model.description
# 1.3.1 Drop the use of 8-bit indexes as this is not supported by many GPUs/Engines and may be dropped from future glTF specification.

module Yulio
module GltfExporter
unless file_loaded?(__FILE__)
# because LanguageHandler.new works at this directory level, create a constant for it here
TRANSLATE = LanguageHandler.new('yulio_gltf_export.strings')

ex = SketchupExtension.new(TRANSLATE["title"], 'yulio_gltf_export/gltf_export')
ex.description = TRANSLATE["description"]
ex.version = '1.0.0'
ex.copyright = '©2019'
ex.creator = 'Yulio Technolgies Inc.'
Sketchup.register_extension(ex, true)
file_loaded(__FILE__)
end
end
end
19 changes: 19 additions & 0 deletions yulio_gltf_export/Resources/en-US/yulio_gltf_export.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"title"="glTF Export";
"description"="Yulio glTF export";
"exportSummary"="glTF Export Summary";
"menuMain"="Yulio glTF";
"menuGltf"="Export Embedded glTF 2.0 (.gltf)";
"menuGlb"="Export Binary glTF 2.0 (.glb)";
"menuGlbMicrosoft"="Export Binary glTF for Microsoft Paint 3D (.glb)";
"untitled"="Untitled";
"images"="Images";
"textures"="Textures";
"materials"="Materials";
"nodes"="Nodes";
"meshes"="Meshes";
"accessors"="Accessors";
"bufferViews"="Buffer Views";
"path"="Saved to Path";
"triangles"="Triangles";
"unsupportedImage"="is an unsupported image type according to the glTF specification";
"badUVW","Models containing perspective-mapped textures (UVW) are not supported";
19 changes: 19 additions & 0 deletions yulio_gltf_export/Resources/fr/yulio_gltf_export.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"title"="Export glTF";
"description"="Yulio glTF export";
"exportSummary"="glTF Export Summary";
"menuMain"="Yulio glTF";
"menuGltf"="Export glTF 2.0 integrated (.gltf)";
"menuGlb"="Exporter le fichier binaire glTF 2.0 (.glb)";
"menuGlbMicrosoft"="Exporter le fichier binaire glTF Microsoft Paint 3D (.glb)";
"untitled"="Sans titre";
"images"="Images";
"textures"="Textures";
"materials"="Matériaux";
"nodes"="Nodes";
"meshes"="Meshes";
"accessors"="Accessors";
"bufferViews"="Vues Buffer";
"path"="Enregistré sur le chemin";
"triangles"="Triangles";
"unsupportedImage"="Est un type d'image non pris en charge selon la spécification glTF";
"badUVW","Les modèles contenant des textures mappées en perspective (UVQ) ne sont pas pris en charge";
19 changes: 19 additions & 0 deletions yulio_gltf_export/Resources/zh-CN/yulio_gltf_export.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"title"="glTF导出";
"description"="Yulio glTF导出";
"exportSummary"="glTF导出摘要";
"menuMain"="Yulio glTF";
"menuGltf"="导出嵌入式glTF 2.0(.gltf)";
"menuGlb"="导出二进制glTF 2.0(.glb)";
"menuGlbMicrosoft"="导出二进制glTF Microsoft Paint 3D (.glb)";
"untitled"="无标题";
"images"="图片";
"textures"="纹理";
"materials"="材料";
"nodes"="节点";
"meshes"="网格";
"accessors"="访问器";
"bufferViews"="存储的视图";
"path"="保存到资料夹";
"triangles"="三角形";
"unsupportedImage"="是不受支持的图像类型, 根据glTF规范";
"badUVW","不支持包含透视图纹理(UVW)的模型";
19 changes: 19 additions & 0 deletions yulio_gltf_export/Resources/zh-TW/yulio_gltf_export.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"title"="glTF導出";
"description"="Yulio glTF導出";
"exportSummary"="glTF導出摘要";
"menuMain"="Yulio glTF";
"menuGltf"="導出嵌入式glTF 2.0(.gltf)";
"menuGlb"="導出二進制glTF 2.0(.glb)";
"menuGlbMicrosoft"="導出二進制glTF Microsoft Paint 3D (.glb)";
"untitled"="無題";
"images"="圖片";
"textures"="紋理";
"materials"="材料";
"nodes"="節點";
"meshes"="網格";
"accessors"="訪問器";
"bufferViews"="存儲的視圖";
"path"="保存到資料夾";
"triangles"="三角形";
"unsupportedImage"="是不受支持的圖像類型, 根據glTF規範";
"badUVW","不支持包含透視圖紋理(UVW)的模型";
62 changes: 62 additions & 0 deletions yulio_gltf_export/gltf_accessors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#-----------------------------------------------------------------------------------
# MIT License
#
# Copyright (c) 2019 Yulio Technologies Inc.
#
# 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.
#-----------------------------------------------------------------------------------

module Yulio
module GltfExporter
class GltfAccessors

def initialize
@accessors = []
end

# Add an accessor to the accessor list
def add_accessor(bufferView, byteOffset, componentType,count, type, min,max)
accessor =
{
"bufferView" => bufferView,
"componentType" => componentType,
"count" => count,
"type" => type
}
if(byteOffset != 0)
accessor["byteOffset"] = byteOffset
end
if(min != nil && max != nil)
accessor["min"] = min
accessor["max"] = max
end
index = @accessors.length
#puts 'Creating Accessor ' + index.to_s + ' for buffer view ' + bufferView.to_s + ' at offset ' + byteOffset.to_s
@accessors.push(accessor)
return index
end

# retrieve the accessor list
def get_accessors
return @accessors
end

end
end
end
73 changes: 73 additions & 0 deletions yulio_gltf_export/gltf_buffer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#-----------------------------------------------------------------------------------
# MIT License
#
# Copyright (c) 2019 Yulio Technologies Inc.
#
# 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.
#-----------------------------------------------------------------------------------

require 'base64'
module Yulio
module GltfExporter
class GltfBuffer

def initialize
@buffer = ''
end

def add_buffer(bytes, alignment)

#if(alignment < 4)
# alignment = 4
#end

while @buffer.length % alignment != 0
@buffer = @buffer << 0
end

offset = @buffer.length
#puts 'Adding ' + bytes.length.to_s + ' bytes to buffer at offset ' + offset.to_s

@buffer << bytes
return offset
end

def get_buffers
buffers = []
buffer =
{
"byteLength" => @buffer.length
}
buffers.push(buffer)
return buffers, @buffer
end

def encode_buffers()
buffers = []
buf =
{
"uri" => "data:application/octet-stream;base64," + Base64.strict_encode64(@buffer),
"byteLength" => @buffer.length
}
buffers.push(buf)
return buffers
end
end
end
end
60 changes: 60 additions & 0 deletions yulio_gltf_export/gltf_buffer_views.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#-----------------------------------------------------------------------------------
# MIT License
#
# Copyright (c) 2019 Yulio Technologies Inc.
#
# 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.
#-----------------------------------------------------------------------------------

module Yulio
module GltfExporter
class GltfBufferViews

def initialize
@buffer_views = []
end

def add_buffer_view(buffer,byteOffset, byteLength, target, byteStride)

buffer_view = {}
buffer_view["buffer"] = buffer
if byteOffset != 0
buffer_view["byteOffset"] = byteOffset
end
buffer_view["byteLength"] = byteLength
if target != nil
buffer_view["target"] = target
end
if byteStride != nil
buffer_view["byteStride"] = byteStride
end
index = @buffer_views.length
@buffer_views.push(buffer_view)

#puts 'Creating buffer view ' + index.to_s + ' for offset ' + byteOffset.to_s + ' and length ' + byteLength.to_s + ' bytes'
return index
end

def get_buffer_views
return @buffer_views
end

end
end
end

0 comments on commit 7aff79e

Please sign in to comment.