nebula-webclient 8.0.10286 → 8.0.10290
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +1 -0
- data/lib/nebula/webclient/setting.rb +49 -16
- data/lib/nebula/webclient/viewer.rb +41 -9
- metadata +4 -2
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private
|
@@ -4,6 +4,7 @@ require 'erb'
|
|
4
4
|
module Nebula
|
5
5
|
module WebClient
|
6
6
|
|
7
|
+
# @private
|
7
8
|
class Encoder
|
8
9
|
|
9
10
|
def self.str(s)
|
@@ -27,13 +28,20 @@ module Nebula
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
31
|
+
# Border setting of the Nebula Viewer.
|
30
32
|
class Border
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
# @param args [Hash]
|
34
|
+
# * :style => (String) The HTML style of the border, e.g., "solid", "dashed".
|
35
|
+
# * :width => (String) or [Fixnum] The width of the border in pixels.
|
36
|
+
# * :color => (String) The color of the border, e.g., "#302903".
|
37
|
+
def initialize(args = {})
|
38
|
+
@style = args[:style] || 'solid'
|
39
|
+
@width = args[:width] || 0
|
40
|
+
@color = args[:color] || '#000'
|
35
41
|
end
|
36
42
|
|
43
|
+
# Convert the border setting to HTML string, e.g., "solid 1px #302903".
|
44
|
+
# @return [String] A HTML string like "solid 1px #303902".
|
37
45
|
def to_s
|
38
46
|
'' << style.to_s << ' ' << width.to_s << 'px ' << color.to_s
|
39
47
|
end
|
@@ -43,35 +51,52 @@ module Nebula
|
|
43
51
|
attr(:color, true)
|
44
52
|
end
|
45
53
|
|
54
|
+
# The configuration of the Nebula Viewer, including its scale, the border and some other advanced configurations.
|
46
55
|
class Setting
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
# @param args [Hash]
|
57
|
+
# * :width => [String] or [Fixnum] Width of the viewer.
|
58
|
+
# * :height => [String] or [Fixnum] Height of the viewer.
|
59
|
+
# * :border => [Border] Border setting of the viewer.
|
60
|
+
# * :menu_docking => [Symbol] Docking position of the main menu, one of :bottom, :right.
|
61
|
+
# * :render_mode => [Symbol] Default rendering mode of the viewer, one of :realistic, :fantastic, :technical.
|
62
|
+
# realistic: Realistic rendering mode, with global shadow and lights.
|
63
|
+
# fanstastic: Fantastic rendering mode, with realistic shadows and multiple texture-mapping.
|
64
|
+
# technical: Technical rendering mode, with triangles in different colors.
|
65
|
+
# * :language => Language package to be loaded, one of :english, :french, :simplified_chinese, :traditional_chinese, :japanese.
|
66
|
+
def initialize(args = {})
|
67
|
+
@width = args[:width] || 640
|
68
|
+
@height = args[:height] || 480
|
69
|
+
@border = args[:border] || Border.new
|
70
|
+
@menu_docking = args[:menu_docking] || :bottom
|
71
|
+
@render_mode = args[:render_mode] || :realistic
|
72
|
+
@language = args[:language] || :english
|
54
73
|
end
|
55
74
|
|
56
|
-
|
75
|
+
# Generate the url parameters to describe the settings.
|
76
|
+
# @param uri [String] Uri of the model to be loaded, empty for nothing.
|
77
|
+
# @return [String] A encoded string as a url parameter (query).
|
78
|
+
def to_url_parameters(uri = nil)
|
57
79
|
s = ''
|
58
80
|
s << '?w=' << Encoder.str(width)
|
59
81
|
s << '&h=' << Encoder.str(height)
|
60
82
|
s << '&b=' << Encoder.url(border) if border.width > 0
|
61
83
|
s << '&m=' << Encoder.str(menu_docking) if menu_docking != :bottom
|
62
|
-
s << '&r=' << Encoder.str(render_mode) if render_mode != :default
|
84
|
+
s << '&r=' << Encoder.str(RenderModes[render_mode]) if render_mode != :default
|
63
85
|
s << '&l=' << Encoder.str(Languages[language]) if language != :english
|
64
86
|
s << '&u=' << Encoder.url(uri) if uri
|
65
87
|
s
|
66
88
|
end
|
67
89
|
|
68
|
-
|
90
|
+
# Generate the JSON code of the setting.
|
91
|
+
# @param uri [String] Uri of the model to be loaded, empty for nothing.
|
92
|
+
# @return [String] A JSON string.
|
93
|
+
def to_json(uri = nil)
|
69
94
|
s = ''
|
70
95
|
s << '{width:' << Encoder.str(width)
|
71
96
|
s << ',height:' << Encoder.str(height)
|
72
97
|
s << ',border:' << Encoder.str(border) if border.width > 0
|
73
98
|
s << ',menuDocking:' << Encoder.str(menu_docking) if menu_docking != :bottom
|
74
|
-
s << ',renderMode:' << Encoder.str(render_mode) if render_mode != :
|
99
|
+
s << ',renderMode:' << Encoder.str(RenderModes[render_mode]) if render_mode != :realistic
|
75
100
|
s << ',language:' << Encoder.str(Languages[language]) if language != :english
|
76
101
|
s << ',uri' << Encoder.js(uri) if uri
|
77
102
|
s << '}'
|
@@ -85,14 +110,22 @@ module Nebula
|
|
85
110
|
attr(:render_mode, true)
|
86
111
|
attr(:language, true)
|
87
112
|
|
113
|
+
# @private
|
88
114
|
Languages = {:english => 'en-us',
|
89
115
|
:french => 'fr',
|
90
116
|
:simplified_chinese => 'zh-cn',
|
91
117
|
:traditional_chinese => 'zh-tw',
|
92
118
|
:japanese => 'jp'
|
93
119
|
}
|
120
|
+
|
121
|
+
# @private
|
122
|
+
RenderModes = {:realistic => 'default',
|
123
|
+
:fantastic => 'realistic',
|
124
|
+
:technical => 'diagnostic'
|
125
|
+
}
|
94
126
|
end
|
95
127
|
|
128
|
+
# @private
|
96
129
|
class RenderSetting
|
97
130
|
def initialize(w, h, mode = :default, set = '', view = '', version = '1.0')
|
98
131
|
@width = w
|
@@ -103,7 +136,7 @@ module Nebula
|
|
103
136
|
@version = version
|
104
137
|
end
|
105
138
|
|
106
|
-
def
|
139
|
+
def to_json
|
107
140
|
s = ''
|
108
141
|
s << '{screenWidth:' << Encoder.str(width)
|
109
142
|
s << ',screenHeight:' << Encoder.str(height)
|
@@ -1,10 +1,30 @@
|
|
1
1
|
|
2
2
|
module Nebula
|
3
|
+
# The main module that contains code generating classes of the Nebula Viewer.
|
3
4
|
module WebClient
|
4
5
|
|
6
|
+
# The main class of generating HTML code for Nebula Viewer.
|
5
7
|
class Viewer
|
8
|
+
|
9
|
+
# @private
|
6
10
|
ServiceHostAddress = 'http://nebula.gems8.com/__nebulaviewerv100__'
|
7
11
|
|
12
|
+
# An address of a sample model.
|
13
|
+
SampleModel = 'http://nebula.gems8.com/Home/Sample/Apple'
|
14
|
+
|
15
|
+
# Generate code of an iframe containing the viewer of the specified model.
|
16
|
+
# @param args [Hash]
|
17
|
+
# * :uri => (String) Address of the 3D model, required.
|
18
|
+
# * :width => (String) or (Fixnum) Width in pixels of the viewer.
|
19
|
+
# * :height => (String) or (Fixnum) Height in pixels of the viewer.
|
20
|
+
# * :id => (String) Id of the HTML element.
|
21
|
+
# * :class_name => (String) Class name of the HTML element.
|
22
|
+
# * :selector => (String) Id or the class name of the HTML element.
|
23
|
+
# If the selector starts with "#", it means an id.
|
24
|
+
# If starts with ".", it means the class name.
|
25
|
+
# Or, id by default.
|
26
|
+
# * "setting => (Setting) Advanced setting of the viewer
|
27
|
+
# @return [String] Html code of the embedded Nebula Viewer.
|
8
28
|
def self.html(args)
|
9
29
|
uri = args[:uri]
|
10
30
|
id, klass = selector(args)
|
@@ -12,7 +32,7 @@ module Nebula
|
|
12
32
|
|
13
33
|
s = ''
|
14
34
|
s << '<iframe src="' << ServiceHostAddress << '/EmbeddedViewer'
|
15
|
-
s << setting.
|
35
|
+
s << setting.to_url_parameters(uri)
|
16
36
|
s << '" width="' << Encoder.str(setting.width)
|
17
37
|
s << '" height="' << Encoder.str(setting.height)
|
18
38
|
s << '" class="' << Encoder.str(klass) if !klass.blank?
|
@@ -20,6 +40,9 @@ module Nebula
|
|
20
40
|
s << '" scrolling="no" frameBorder="0"></iframe>'
|
21
41
|
end
|
22
42
|
|
43
|
+
# Generate a javascript statement to load the viewer to the specified HTML element container, with the specified model address and advanced settings.
|
44
|
+
# @param (see .html)
|
45
|
+
# @return (String) Html code of the JavaScript code.
|
23
46
|
def self.javascript(args)
|
24
47
|
uri = args[:uri]
|
25
48
|
selector = args[:selector]
|
@@ -28,14 +51,20 @@ module Nebula
|
|
28
51
|
s << 'new NebulaViewer('
|
29
52
|
s << Encoder.js(selector)
|
30
53
|
s << ','
|
31
|
-
s << setting(args).
|
54
|
+
s << setting(args).to_json(uri)
|
32
55
|
s << ');'
|
33
56
|
end
|
34
57
|
|
35
|
-
|
58
|
+
# Generate a javascript tag to load the viewer to the specified HTML element container, with the specified model address and advanced settings.
|
59
|
+
# @param (see .html)
|
60
|
+
# @return (String) Html code of the JavaScript section.
|
61
|
+
def self.javascript_section(args)
|
36
62
|
'<script type="text/javascript">' << javascript(args) << '</script>'
|
37
63
|
end
|
38
64
|
|
65
|
+
# Create a img tag of a thumbnail to preview a 3D model.
|
66
|
+
# @param (see .html)
|
67
|
+
# @return A HTML string of the thumbnail.
|
39
68
|
def self.thumbnail(args)
|
40
69
|
uri = args[:uri]
|
41
70
|
id, klass = selector(args)
|
@@ -51,21 +80,23 @@ module Nebula
|
|
51
80
|
s << '" />'
|
52
81
|
end
|
53
82
|
|
83
|
+
# Create a unescaped url of a thumbnail to preview a 3D model.
|
84
|
+
# @param (see .html)
|
85
|
+
# @return An url string of the thumbnail.
|
54
86
|
def self.thumbnail_url(args)
|
55
87
|
uri = args[:uri]
|
56
|
-
id, klass = selector(args)
|
57
|
-
render = RenderSetting.new(args[:width], args[:height])
|
58
|
-
|
59
88
|
uri = 'image/jpeg@' << uri if !uri.index('@')
|
89
|
+
render = RenderSetting.new(args[:width], args[:height])
|
60
90
|
|
61
91
|
s = ''
|
62
92
|
s << ServiceHostAddress
|
63
93
|
s << '/Render?u=' << Encoder.url(uri)
|
64
94
|
s << '&c=d'
|
65
|
-
s << '&s=' << Encoder.url(render.
|
95
|
+
s << '&s=' << Encoder.url(render.to_json)
|
66
96
|
s << '×tamp=thumbnail'
|
67
97
|
end
|
68
98
|
|
99
|
+
# @private
|
69
100
|
def self.setting(args)
|
70
101
|
setting = args[:setting] || Setting.new
|
71
102
|
setting.width = args[:width] if args[:width]
|
@@ -73,10 +104,11 @@ module Nebula
|
|
73
104
|
setting
|
74
105
|
end
|
75
106
|
|
107
|
+
# @private
|
76
108
|
def self.selector(args)
|
77
|
-
selector = args[:
|
109
|
+
selector = args[:selector]
|
78
110
|
if selector.blank?
|
79
|
-
return args[:id], args[:
|
111
|
+
return args[:id], args[:class_name]
|
80
112
|
else
|
81
113
|
selector.strip!
|
82
114
|
if selector.start_with?('#')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nebula-webclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.0.
|
4
|
+
version: 8.0.10290
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: The library of Nebula Viewer web client.
|
15
15
|
email: nebula@gems8.com
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- lib/nebula/webclient/viewer.rb
|
22
22
|
- lib/nebula/webclient.rb
|
23
23
|
- lib/nebula-webclient.rb
|
24
|
+
- .yardopts
|
24
25
|
homepage: http://nebula.gems8.com
|
25
26
|
licenses: []
|
26
27
|
post_install_message:
|
@@ -46,3 +47,4 @@ signing_key:
|
|
46
47
|
specification_version: 3
|
47
48
|
summary: The library of Nebula Viewer web client.
|
48
49
|
test_files: []
|
50
|
+
has_rdoc:
|