Class: Nebula::WebClient::Viewer

Inherits:
Object
  • Object
show all
Defined in:
lib/nebula/webclient/viewer.rb

Overview

The main class of generating HTML code for Nebula Viewer.

Constant Summary collapse

SampleModel =

An address of a sample model.

'http://nebula.gems8.com/Home/Sample/Apple'

Class Method Summary collapse

Class Method Details

.html(args) ⇒ String

Generate code of an iframe containing the viewer of the specified model.

Parameters:

  • args (Hash)
    • :uri => (String) Address of the 3D model, required.

    • :width => (String) or (Fixnum) Width in pixels of the viewer.

    • :height => (String) or (Fixnum) Height in pixels of the viewer.

    • :id => (String) Id of the HTML element.

    • :class_name => (String) Class name of the HTML element.

    • :selector => (String) Id or the class name of the HTML element. If the selector starts with “#”, it means an id. If starts with “.”, it means the class name. Or, id by default.

    • “setting => (Setting) Advanced setting of the viewer

Returns:

  • (String)

    Html code of the embedded Nebula Viewer.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nebula/webclient/viewer.rb', line 28

def self.html(args)
  uri = args[:uri]
  id, klass = selector(args)
  setting = setting(args)

  s = ''
  s << '<iframe src="' << ServiceHostAddress << '/EmbeddedViewer'
  s << setting.to_url_parameters(uri)
  s << '" width="' << Encoder.str(setting.width)
  s << '" height="' << Encoder.str(setting.height)
  s << '" class="' << Encoder.str(klass) if !klass.blank?
  s << '" id=' << Encoder.str(id) if !id.blank?
  s << '" scrolling="no" frameBorder="0"></iframe>'
end

.javascript(args) ⇒ String

Generate a javascript statement to load the viewer to the specified HTML element container, with the specified model address and advanced settings.

Parameters:

  • args (Hash)
    • :uri => (String) Address of the 3D model, required.

    • :width => (String) or (Fixnum) Width in pixels of the viewer.

    • :height => (String) or (Fixnum) Height in pixels of the viewer.

    • :id => (String) Id of the HTML element.

    • :class_name => (String) Class name of the HTML element.

    • :selector => (String) Id or the class name of the HTML element. If the selector starts with “#”, it means an id. If starts with “.”, it means the class name. Or, id by default.

    • “setting => (Setting) Advanced setting of the viewer

Returns:

  • (String)

    Html code of the JavaScript code.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nebula/webclient/viewer.rb', line 46

def self.javascript(args)
  uri = args[:uri]
  selector = args[:selector]

  s = ''
  s << 'new NebulaViewer('
  s << Encoder.js(selector)
  s << ','
  s << setting(args).to_json(uri)
  s << ');'
end

.javascript_section(args) ⇒ String

Generate a javascript tag to load the viewer to the specified HTML element container, with the specified model address and advanced settings.

Parameters:

  • args (Hash)
    • :uri => (String) Address of the 3D model, required.

    • :width => (String) or (Fixnum) Width in pixels of the viewer.

    • :height => (String) or (Fixnum) Height in pixels of the viewer.

    • :id => (String) Id of the HTML element.

    • :class_name => (String) Class name of the HTML element.

    • :selector => (String) Id or the class name of the HTML element. If the selector starts with “#”, it means an id. If starts with “.”, it means the class name. Or, id by default.

    • “setting => (Setting) Advanced setting of the viewer

Returns:

  • (String)

    Html code of the JavaScript section.



61
62
63
# File 'lib/nebula/webclient/viewer.rb', line 61

def self.javascript_section(args)
  '<script type="text/javascript">' << javascript(args) << '</script>'
end

.thumbnail(args) ⇒ Object

Create a img tag of a thumbnail to preview a 3D model.

Parameters:

  • args (Hash)
    • :uri => (String) Address of the 3D model, required.

    • :width => (String) or (Fixnum) Width in pixels of the viewer.

    • :height => (String) or (Fixnum) Height in pixels of the viewer.

    • :id => (String) Id of the HTML element.

    • :class_name => (String) Class name of the HTML element.

    • :selector => (String) Id or the class name of the HTML element. If the selector starts with “#”, it means an id. If starts with “.”, it means the class name. Or, id by default.

    • “setting => (Setting) Advanced setting of the viewer

Returns:

  • A HTML string of the thumbnail.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nebula/webclient/viewer.rb', line 68

def self.thumbnail(args)
  uri = args[:uri]
  id, klass = selector(args)
  width = args[:width]
  height = args[:height]

  s = ''
  s << '<img src="' << thumbnail_url(args)
  s << '" width="' << Encoder.str(width)
  s << '" height="' << Encoder.str(height)
  s << '" id="' << Encoder.str(id) if !id.blank?
  s << '" class="' << Encoder.str(klass) if !klass.blank?
  s << '" />'
end

.thumbnail_url(args) ⇒ Object

Create a unescaped url of a thumbnail to preview a 3D model.

Parameters:

  • args (Hash)
    • :uri => (String) Address of the 3D model, required.

    • :width => (String) or (Fixnum) Width in pixels of the viewer.

    • :height => (String) or (Fixnum) Height in pixels of the viewer.

    • :id => (String) Id of the HTML element.

    • :class_name => (String) Class name of the HTML element.

    • :selector => (String) Id or the class name of the HTML element. If the selector starts with “#”, it means an id. If starts with “.”, it means the class name. Or, id by default.

    • “setting => (Setting) Advanced setting of the viewer

Returns:

  • An url string of the thumbnail.



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nebula/webclient/viewer.rb', line 86

def self.thumbnail_url(args)
  uri = args[:uri]
  uri = 'image/jpeg@' << uri if !uri.index('@')
  render = RenderSetting.new(args[:width], args[:height])

  s = ''
  s << ServiceHostAddress
  s << '/Render?u=' << Encoder.url(uri)
  s << '&c=d'
  s << '&s=' << Encoder.url(render.to_json)
  s << '&timestamp=thumbnail'
end