Skip to content

Commit

Permalink
Load only necessary files.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelTallet committed Jan 14, 2020
1 parent f82914a commit e8269aa
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 99 deletions.
2 changes: 1 addition & 1 deletion source/universal_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# Universal Importer plugin namespace.
module UniversalImporter

VERSION = '1.1.0'.freeze
VERSION = '1.1.1'.freeze

# Load translation if it's available for current locale.
TRANSLATE = LanguageHandler.new('uir.strings')
Expand Down
6 changes: 4 additions & 2 deletions source/universal_importer/Resources/es/uir.strings
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
"Scale Imported Model"="Redimensionar Modelo Importado";

//
// File: converter.rb
// File: importer.rb
//

"Select a 3D Model"="Seleccionar un Modelo 3D";
"3D Models"="Modelos 3D";
"Select a Texture Atlas (Optional)"="Seleccionar un Atlas de Texturas (Opcional)";
"Images"="Imágenes";
"Do you want to reduce polygon count?"="¿Quieres reducir la cantidad de polígonos?";
"Model has"="El modelo tiene";
"faces"="caras";
"Reduce polygon count?"="¿Reducir la cantidad de polígonos?";
"Target face number"="Número de caras objetivo";
"Polygon Reduction"="Reducción de Polígonos";
"Model height (cm)"="Altura del modelo (cm)";
Expand Down
6 changes: 4 additions & 2 deletions source/universal_importer/Resources/fr/uir.strings
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
"Scale Imported Model"="Redimensionner le modèle importé";

//
// File: converter.rb
// File: importer.rb
//

"Select a 3D Model"="Sélectionner un modèle 3D";
"3D Models"="Modèles 3D";
"Select a Texture Atlas (Optional)"="Sélectionner un atlas de textures (Optionnel)";
"Images"="Images";
"Do you want to reduce polygon count?"="Voulez-vous réduire le nombre de polygones ?";
"Model has"="Le modèle a";
"faces"="faces";
"Reduce polygon count?"="Réduire le nombre de polygones ?";
"Target face number"="Nombre de faces ciblé";
"Polygon Reduction"="Réduction de polygones";
"Model height (cm)"="Hauteur du modèle (cm)";
Expand Down
99 changes: 98 additions & 1 deletion source/universal_importer/assimp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
unless RUBY_VERSION.to_f >= 2.2 # SketchUp 2017 includes Ruby 2.2.4.

require 'sketchup'
require 'fileutils'

# Universal Importer plugin namespace.
module UniversalImporter
Expand Down Expand Up @@ -96,7 +97,7 @@ def self.convert_model(in_path, out_path, log_path)

end

# Extracts embedded textures from a 3D model?
# If they exist: extracts embedded textures from a 3D model.
#
# @param [String] in_path
# @param [String] log_path
Expand Down Expand Up @@ -133,6 +134,102 @@ def self.extract_textures(in_path, log_path)

end

# If they exist: gets texture references of a 3D model.
#
# @param [String] in_path
# @param [String] log_path
# @raise [ArgumentError]
#
# @raise [StandardError]
#
# @return [Array<String>]
def self.get_texture_refs(in_path, log_path)

raise ArgumentError, 'In Path parameter must be a String.'\
unless in_path.is_a?(String)

raise ArgumentError, 'Log Path parameter must be a String.'\
unless log_path.is_a?(String)

texture_refs = []

command = '"' + exe + '" info "' + in_path + '"' + ' > "' + log_path + '"'

status = system(command)

if status != true

result = 'No log available.'

result = File.read(log_path) if File.exist?(log_path)

raise StandardError.new('Command failed: ' + command + "\n\n" + result)

end

info = File.read(log_path)

if info.include?('Texture Refs:')

if info.include?('Named Animations:')

tex_nfo = info.split('Texture Refs:')[1].split('Named Animations:')[0]

else

tex_nfo = info.split('Texture Refs:')[1].split('Node hierarchy:')[0]

end

tex_nfo.lines.each do |line|

cleaned_line = line.strip.sub("'", '').sub(/.*\K'/, '')

if !cleaned_line.empty? && !cleaned_line.start_with?('*')

texture_refs.push(cleaned_line)

end

end

end

texture_refs.uniq

end

# Gets face count of a 3D model.
#
# @param [String] log_path
# @raise [ArgumentError]
#
# @raise [StandardError]
#
# @return [Integer]
def self.get_face_count(log_path)

raise ArgumentError, 'Log Path parameter must be a String.'\
unless log_path.is_a?(String)

face_count = 0

info = File.read(log_path)

info.lines.each do |line|

if line.start_with?('Faces:')

return line.gsub(/[^0-9]/, '').to_i

end

end

face_count

end

end

end
71 changes: 71 additions & 0 deletions source/universal_importer/gltf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Universal Importer extension for SketchUp 2017 or newer.
# Copyright: © 2019 Samuel Tallet <samuel.tallet arobase gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3.0 of the License, or
# (at your option) any later version.
#
# If you release a modified version of this program TO THE PUBLIC,
# the GPL requires you to MAKE THE MODIFIED SOURCE CODE AVAILABLE
# to the program's users, UNDER THE GPL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# Get a copy of the GPL here: https://www.gnu.org/licenses/gpl.html

raise 'The UIR plugin requires at least Ruby 2.2.0 or SketchUp 2017.'\
unless RUBY_VERSION.to_f >= 2.2 # SketchUp 2017 includes Ruby 2.2.4.

require 'fileutils'
require 'json'

# Universal Importer plugin namespace.
module UniversalImporter

# Minimal glTF parser.
class GlTF

# Parses a glTF file.
def initialize(file_path)

raise ArgumentError, 'File Path parameter must be a String.'\
unless file_path.is_a?(String)

file_contents = File.read(file_path)

@json = JSON.parse(file_contents)

end

# Returns buffers paths if they exist.
#
# @return [Array<String>]
def buffers_paths

output = []

if @json.key?('buffers')

@json['buffers'].each do |buffer|

if buffer.key?('uri') && !buffer['uri'].start_with?('data:')

output.push(buffer['uri'])

end

end

end

output

end

end

end
Loading

0 comments on commit e8269aa

Please sign in to comment.