Skip to content

Commit

Permalink
Merging all the changes and fixes into the master branch (#2)
Browse files Browse the repository at this point in the history
2.0.0 Added support for the camera export
		Changed the mesh accumulation, export and relevant buffer view generation mechanism to be performed on a per mesh per material basis. This cuts down the export times by a factor of 2x and drastically improves the speed and memory consumption when exported files are imported via Assimp.
		Added optional support for multiple buffer generation in exported files (if needed)
		Currently mesh vertices are exported without welding for performance reasons (additional ~30% speed improvement) at the expense of bigger exported file sizes (this could be changed to hash based welding; see the code in MeshData class)
		Overall re-factoring to clean up and remove redundant code
		Various small performance optimizations and hardening
		Added some missing internationalization resource strings
2.1.0 Added ImageMagick app to convert images to .png
		Passed FOV to gltf from SU
2.2.0 Fixed RGBA blending not being supported when a texture was specified for a material
		A fix to suppress duplicate geometry in CET exported scenes
  • Loading branch information
lfaynshteyn committed Aug 27, 2019
1 parent 707d720 commit bc120a5
Show file tree
Hide file tree
Showing 40 changed files with 2,298 additions and 516 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
13 changes: 12 additions & 1 deletion yulio_gltf_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
# 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.
# 2.0.0 Added support for the camera export
# Changed the mesh accumulation, export and relevant buffer view generation mechanism to be performed on a per mesh per material basis. This cuts down the export times by a factor of 2x and drastically improves the speed and memory consumption when exported files are imported via Assimp.
# Added optional support for multiple buffer generation in exported files (if needed)
# Currently mesh vertices are exported without welding for performance reasons (additional ~30% speed improvement) at the expense of bigger exported file sizes (this could be changed to hash based welding; see the code in MeshData class)
# Overall re-factoring to clean up and remove redundant code
# Various small performance optimizations and hardening
# Added some missing internationalization resource strings
# 2.1.0 Added ImageMagick app to convert images to .png
# Passed FOV to gltf from SU
# 2.2.0 Fixed RGBA blending not being supported when a texture was specified for a material
# A fix to suppress duplicate geometry in CET exported scenes

module Yulio
module GltfExporter
Expand All @@ -57,7 +68,7 @@ module GltfExporter

ex = SketchupExtension.new(TRANSLATE["title"], 'yulio_gltf_export/gltf_export')
ex.description = TRANSLATE["description"]
ex.version = '1.0.0'
ex.version = '2.2.0'
ex.copyright = '©2019'
ex.creator = 'Yulio Technolgies Inc.'
Sketchup.register_extension(ex, true)
Expand Down
Binary file added yulio_gltf_export/Grey_Texture.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions yulio_gltf_export/Resources/en-US/yulio_gltf_export.strings
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
"materials"="Materials";
"nodes"="Nodes";
"meshes"="Meshes";
"cameras"="Cameras";
"accessors"="Accessors";
"bufferViews"="Buffer Views";
"buffers"="Buffers";
"path"="Saved to Path";
"triangles"="Triangles";
"vertices"="Vertices";
"unsupportedImage"="is an unsupported image type according to the glTF specification";
"badUVW","Models containing perspective-mapped textures (UVW) are not supported";
3 changes: 3 additions & 0 deletions yulio_gltf_export/Resources/fr/yulio_gltf_export.strings
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
"materials"="Matériaux";
"nodes"="Nodes";
"meshes"="Meshes";
"cameras"="Cameras";
"accessors"="Accessors";
"bufferViews"="Vues Buffer";
"buffers"="Buffers";
"path"="Enregistré sur le chemin";
"triangles"="Triangles";
"vertices"="Vertices";
"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";
9 changes: 3 additions & 6 deletions yulio_gltf_export/gltf_accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def initialize
@accessors = []
end

attr_reader :accessors

# Add an accessor to the accessor list
def add_accessor(bufferView, byteOffset, componentType,count, type, min,max)
def add_accessor(bufferView, byteOffset, componentType, count, type, min, max)
accessor =
{
"bufferView" => bufferView,
Expand All @@ -52,11 +54,6 @@ def add_accessor(bufferView, byteOffset, componentType,count, type, min,max)
return index
end

# retrieve the accessor list
def get_accessors
return @accessors
end

end
end
end
73 changes: 0 additions & 73 deletions yulio_gltf_export/gltf_buffer.rb

This file was deleted.

10 changes: 5 additions & 5 deletions yulio_gltf_export/gltf_buffer_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ def initialize
@buffer_views = []
end

def add_buffer_view(buffer,byteOffset, byteLength, target, byteStride)
attr_reader :buffer_views

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

# Create a new buffer_view
buffer_view = {}
buffer_view["buffer"] = buffer
if byteOffset != 0
Expand All @@ -44,16 +47,13 @@ def add_buffer_view(buffer,byteOffset, byteLength, target, byteStride)
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
Expand Down
93 changes: 93 additions & 0 deletions yulio_gltf_export/gltf_buffers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#-----------------------------------------------------------------------------------
# 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 GltfBuffers
def initialize()
#@buffers = {} # Can use hash indexed buffers in you want to initialize & use them out of order, but no real need for that
@buffers = []
end

def add_or_append_buffer(index, bytes, alignment)

# if (@buffers[index] == nil)
# puts 'Creating a new buffer with index ' + index.to_s
# buffer = ''
# @buffers[index] = buffer
# else
# puts 'Using the existing buffer with index ' + index.to_s
# buffer = @buffers[index]
# end

if (index < @buffers.length)
#puts 'Using the existing buffer with index ' + index.to_s
buffer = @buffers[index]
else
#puts 'Creating a new buffer with index ' + @buffers.length.to_s
buffer = ''
@buffers.push(buffer)
end

while buffer.length % alignment != 0
#puts 'Padding the buffer'
buffer = buffer << 0
end

offset = buffer.length

#puts 'Adding ' + bytes.length.to_s + ' bytes to buffer at offset ' + offset.to_s + ' with alignment of ' + alignment.to_s

buffer << bytes
return offset
end

def get_buffers
buffers = []
@buffers.each do |item|
buf =
{
"byteLength" => item.length
}
buffers.push(buf)
end
return buffers, @buffers
end

def encode_buffers()
buffers = []
@buffers.each do |item|
buf =
{
"uri" => "data:application/octet-stream;base64," + Base64.strict_encode64(item),
"byteLength" => item.length
}
buffers.push(buf)
end
return buffers
end
end
end
end
112 changes: 112 additions & 0 deletions yulio_gltf_export/gltf_cameras.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#-----------------------------------------------------------------------------------
# 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 "yulio_gltf_export/gltf_id"

module Yulio
module GltfExporter
class GltfCameras
def initialize(nodes)
@nodes = nodes
@cameras = []
@id_gen = GltfId.new
end

attr_reader :cameras

def add_camera_type(name,fov)
camera={
"perspective"=>
{
"yfov"=>fov,
"zfar"=>25.399999618530278,
"znear"=>0.02539999969303608,
"aspectRatio"=>1.5
},
"type"=>"perspective",
"name"=>name
}
index=@cameras.length
@cameras.push(camera)
return index

end

def create_camera_matrix(camera)
originM=Geom::Point3d.new(camera.eye.x.to_m,camera.eye.y.to_m,camera.eye.z.to_m)
matrix=Geom::Transformation.axes(originM,camera.xaxis,camera.yaxis,camera.zaxis.reverse)
#temp=[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
#tran=Geom::Transformation.new(temp)
#matrix=tran*matrix
return matrix.to_a
end

def add_camera_nodes
pages = Sketchup.active_model.pages
if (pages.length == 0)
return
end

group_node_id = create_camera_group

pages.each do |page|
name = page.label
camera = page.camera
matrix = create_camera_matrix(camera)
camera_id = add_camera_type(name + "_camera",camera.fov.degrees)
node_id = @nodes.add_node(name, matrix, true)
@nodes.add_camera(node_id, camera_id)
@nodes.add_child(group_node_id, node_id)
end
end

def create_camera_group
matrix = [
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0
]

node_id = @nodes.add_node("Camera Group", matrix, true)
@nodes.add_child(0, node_id)

return node_id
end

end
end

end

0 comments on commit bc120a5

Please sign in to comment.