Class: Three::Backends::ThreeJS
- Includes:
- Materialization, Parameters, ResourceManagement, Synchronization
- Defined in:
- lib/three/backends/threejs.rb,
lib/three/backends/threejs/parameters.rb,
lib/three/backends/threejs/materialization.rb,
lib/three/backends/threejs/synchronization.rb,
lib/three/backends/threejs/ruby_wasm_adapter.rb,
lib/three/backends/threejs/resource_management.rb
Defined Under Namespace
Modules: Materialization, Parameters, ResourceManagement, Synchronization Classes: RubyWasmAdapter
Constant Summary collapse
- MATERIAL_TEXTURE_PARAMETERS =
{ map: :map, alpha_map: :alphaMap, ao_map: :aoMap, bump_map: :bumpMap, displacement_map: :displacementMap, emissive_map: :emissiveMap, env_map: :envMap, gradient_map: :gradientMap, light_map: :lightMap, matcap: :matcap, metalness_map: :metalnessMap, normal_map: :normalMap, roughness_map: :roughnessMap, specular_map: :specularMap, anisotropy_map: :anisotropyMap, clearcoat_map: :clearcoatMap, clearcoat_normal_map: :clearcoatNormalMap, clearcoat_roughness_map: :clearcoatRoughnessMap, transmission_map: :transmissionMap, thickness_map: :thicknessMap, iridescence_map: :iridescenceMap, iridescence_thickness_map: :iridescenceThicknessMap, sheen_color_map: :sheenColorMap, sheen_roughness_map: :sheenRoughnessMap, specular_color_map: :specularColorMap, specular_intensity_map: :specularIntensityMap }.freeze
- MATERIAL_COLOR_PARAMETERS =
%i[color emissive specular attenuationColor sheenColor specularColor].freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#handles ⇒ Object
readonly
Returns the value of attribute handles.
Instance Method Summary collapse
- #add_effect_composer_pass(composer_handle, pass_handle) ⇒ Object
- #animation_mixer_clip_action(mixer_handle, clip_handle, root_handle = nil) ⇒ Object
- #create_animation_mixer(root_handle) ⇒ Object
- #create_dot_screen_pass(center, angle, scale) ⇒ Object
- #create_effect_composer(renderer_handle) ⇒ Object
- #create_orbit_controls(camera, dom_element = nil) ⇒ Object
- #create_output_pass ⇒ Object
- #create_raycaster ⇒ Object
- #create_render_pass(scene, camera) ⇒ Object
- #create_renderer(canvas: nil, **options) ⇒ Object
- #create_unreal_bloom_pass(resolution, strength, radius, threshold) ⇒ Object
- #dispose(object, dispose_textures: false) ⇒ Object
- #dispose_controls(control_handle) ⇒ Object
- #dispose_effect_composer(composer_handle) ⇒ Object
- #dispose_subtree(object, remove: true, dispose_geometries: true, dispose_materials: true, dispose_textures: false, dispose_skeletons: true) ⇒ Object
- #fade_in_animation_action(action_handle, duration) ⇒ Object
- #fade_out_animation_action(action_handle, duration) ⇒ Object
-
#initialize(adapter: nil) ⇒ ThreeJS
constructor
A new instance of ThreeJS.
- #intersect_objects(raycaster_handle, objects, recursive: false) ⇒ Object
- #materialize(object) ⇒ Object
- #play_animation_action(action_handle) ⇒ Object
- #render(renderer_handle, scene, camera) ⇒ Object
- #render_effect_composer(composer_handle, scene = nil, camera = nil) ⇒ Object
- #renderer_dom_element(renderer_handle) ⇒ Object
- #reset_animation_action(action_handle) ⇒ Object
- #set_animation_action_property(action_handle, name, value) ⇒ Object
- #set_animation_loop(renderer_handle, callback) ⇒ Object
- #set_clear_color(renderer_handle, color, alpha = 1) ⇒ Object
- #set_control_property(control_handle, name, value) ⇒ Object
- #set_effect_composer_size(composer_handle, width, height) ⇒ Object
- #set_orbit_controls_target(control_handle, target) ⇒ Object
- #set_postprocessing_pass_property(pass_handle, name, value) ⇒ Object
- #set_postprocessing_pass_uniform(pass_handle, name, value) ⇒ Object
- #set_raycaster_from_camera(raycaster_handle, coords, camera) ⇒ Object
- #set_renderer_shadow_map(renderer_handle, enabled: nil, type: nil, auto_update: nil) ⇒ Object
- #set_renderer_size(renderer_handle, width, height) ⇒ Object
- #stop_all_animation_actions(mixer_handle) ⇒ Object
- #stop_animation_action(action_handle) ⇒ Object
- #sync(object) ⇒ Object
- #sync_object_transform_from_handle(object) ⇒ Object
- #traverse_handles(object, &block) ⇒ Object
- #uncache_animation_root(mixer_handle, root_handle) ⇒ Object
- #update_animation_mixer(mixer_handle, delta) ⇒ Object
- #update_controls(control_handle) ⇒ Object
Constructor Details
#initialize(adapter: nil) ⇒ ThreeJS
Returns a new instance of ThreeJS.
73 74 75 76 77 78 |
# File 'lib/three/backends/threejs.rb', line 73 def initialize(adapter: nil) @adapter = adapter || RubyWasmAdapter.new @handles = {} @objects_by_handle_key = {} @geometry_attribute_names = {} end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
71 72 73 |
# File 'lib/three/backends/threejs.rb', line 71 def adapter @adapter end |
#handles ⇒ Object (readonly)
Returns the value of attribute handles.
71 72 73 |
# File 'lib/three/backends/threejs.rb', line 71 def handles @handles end |
Instance Method Details
#add_effect_composer_pass(composer_handle, pass_handle) ⇒ Object
114 115 116 |
# File 'lib/three/backends/threejs.rb', line 114 def add_effect_composer_pass(composer_handle, pass_handle) @adapter.effect_composer_add_pass(composer_handle, pass_handle) end |
#animation_mixer_clip_action(mixer_handle, clip_handle, root_handle = nil) ⇒ Object
205 206 207 |
# File 'lib/three/backends/threejs.rb', line 205 def animation_mixer_clip_action(mixer_handle, clip_handle, root_handle = nil) @adapter.animation_mixer_clip_action(mixer_handle, clip_handle, root_handle) end |
#create_animation_mixer(root_handle) ⇒ Object
201 202 203 |
# File 'lib/three/backends/threejs.rb', line 201 def create_animation_mixer(root_handle) @adapter.new_animation_mixer(root_handle) end |
#create_dot_screen_pass(center, angle, scale) ⇒ Object
140 141 142 |
# File 'lib/three/backends/threejs.rb', line 140 def create_dot_screen_pass(center, angle, scale) @adapter.new_dot_screen_pass(center, angle, scale) end |
#create_effect_composer(renderer_handle) ⇒ Object
110 111 112 |
# File 'lib/three/backends/threejs.rb', line 110 def create_effect_composer(renderer_handle) @adapter.new_effect_composer(renderer_handle) end |
#create_orbit_controls(camera, dom_element = nil) ⇒ Object
156 157 158 |
# File 'lib/three/backends/threejs.rb', line 156 def create_orbit_controls(camera, dom_element = nil) @adapter.new_orbit_controls(camera, dom_element) end |
#create_output_pass ⇒ Object
144 145 146 |
# File 'lib/three/backends/threejs.rb', line 144 def create_output_pass @adapter.new_output_pass end |
#create_raycaster ⇒ Object
186 187 188 |
# File 'lib/three/backends/threejs.rb', line 186 def create_raycaster @adapter.new_raycaster end |
#create_render_pass(scene, camera) ⇒ Object
132 133 134 |
# File 'lib/three/backends/threejs.rb', line 132 def create_render_pass(scene, camera) @adapter.new_render_pass(sync(scene), sync(camera)) end |
#create_renderer(canvas: nil, **options) ⇒ Object
80 81 82 |
# File 'lib/three/backends/threejs.rb', line 80 def create_renderer(canvas: nil, **) @adapter.new_webgl_renderer({ canvas: canvas }.merge()) end |
#create_unreal_bloom_pass(resolution, strength, radius, threshold) ⇒ Object
136 137 138 |
# File 'lib/three/backends/threejs.rb', line 136 def create_unreal_bloom_pass(resolution, strength, radius, threshold) @adapter.new_unreal_bloom_pass(resolution, strength, radius, threshold) end |
#dispose(object, dispose_textures: false) ⇒ Object
273 274 275 276 277 278 279 280 281 282 |
# File 'lib/three/backends/threejs.rb', line 273 def dispose(object, dispose_textures: false) dispose_material_textures(object) if dispose_textures && object.is_a?(Material) key = cache_key(object) handle = key ? @handles.delete(key) : nil handle_key = @adapter.object_handle_key(handle) if handle @objects_by_handle_key.delete(handle_key) if handle_key @adapter.dispose(handle) if handle handle end |
#dispose_controls(control_handle) ⇒ Object
172 173 174 |
# File 'lib/three/backends/threejs.rb', line 172 def dispose_controls(control_handle) @adapter.dispose_controls(control_handle) end |
#dispose_effect_composer(composer_handle) ⇒ Object
128 129 130 |
# File 'lib/three/backends/threejs.rb', line 128 def dispose_effect_composer(composer_handle) @adapter.dispose_effect_composer(composer_handle) end |
#dispose_subtree(object, remove: true, dispose_geometries: true, dispose_materials: true, dispose_textures: false, dispose_skeletons: true) ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/three/backends/threejs.rb', line 292 def dispose_subtree( object, remove: true, dispose_geometries: true, dispose_materials: true, dispose_textures: false, dispose_skeletons: true ) handle = object3d_handle(object) @adapter.dispose_object3d_subtree( handle, remove: remove, dispose_geometries: dispose_geometries, dispose_materials: dispose_materials, dispose_textures: dispose_textures, dispose_skeletons: dispose_skeletons ) object.remove_from_parent if remove && object.respond_to?(:remove_from_parent) release_cached_subtree_handles( object, dispose_geometries: dispose_geometries, dispose_materials: dispose_materials, dispose_textures: dispose_textures ) handle end |
#fade_in_animation_action(action_handle, duration) ⇒ Object
237 238 239 |
# File 'lib/three/backends/threejs.rb', line 237 def fade_in_animation_action(action_handle, duration) @adapter.fade_in_animation_action(action_handle, duration) end |
#fade_out_animation_action(action_handle, duration) ⇒ Object
241 242 243 |
# File 'lib/three/backends/threejs.rb', line 241 def fade_out_animation_action(action_handle, duration) @adapter.fade_out_animation_action(action_handle, duration) end |
#intersect_objects(raycaster_handle, objects, recursive: false) ⇒ Object
194 195 196 197 198 199 |
# File 'lib/three/backends/threejs.rb', line 194 def intersect_objects(raycaster_handle, objects, recursive: false) handles = Array(objects).map { |object| sync(object) } @adapter.intersect_objects(raycaster_handle, handles, recursive: recursive).map do |intersection| normalize_intersection(intersection) end end |
#materialize(object) ⇒ Object
245 246 247 248 249 250 251 252 253 254 |
# File 'lib/three/backends/threejs.rb', line 245 def materialize(object) key = cache_key(object) return @handles[key] if key && @handles.key?(key) handle = build_handle(object) @handles[key] = handle if key register_object_handle(object, handle) mark_clean_after_materialize(object) handle end |
#play_animation_action(action_handle) ⇒ Object
225 226 227 |
# File 'lib/three/backends/threejs.rb', line 225 def play_animation_action(action_handle) @adapter.play_animation_action(action_handle) end |
#render(renderer_handle, scene, camera) ⇒ Object
104 105 106 107 108 |
# File 'lib/three/backends/threejs.rb', line 104 def render(renderer_handle, scene, camera) scene_handle = sync(scene) camera_handle = sync(camera) @adapter.render(renderer_handle, scene_handle, camera_handle) end |
#render_effect_composer(composer_handle, scene = nil, camera = nil) ⇒ Object
122 123 124 125 126 |
# File 'lib/three/backends/threejs.rb', line 122 def render_effect_composer(composer_handle, scene = nil, camera = nil) sync(scene) if scene sync(camera) if camera @adapter.effect_composer_render(composer_handle) end |
#renderer_dom_element(renderer_handle) ⇒ Object
84 85 86 |
# File 'lib/three/backends/threejs.rb', line 84 def renderer_dom_element(renderer_handle) @adapter.renderer_dom_element(renderer_handle) end |
#reset_animation_action(action_handle) ⇒ Object
233 234 235 |
# File 'lib/three/backends/threejs.rb', line 233 def reset_animation_action(action_handle) @adapter.reset_animation_action(action_handle) end |
#set_animation_action_property(action_handle, name, value) ⇒ Object
221 222 223 |
# File 'lib/three/backends/threejs.rb', line 221 def set_animation_action_property(action_handle, name, value) @adapter.set_animation_action_property(action_handle, name, value) end |
#set_animation_loop(renderer_handle, callback) ⇒ Object
100 101 102 |
# File 'lib/three/backends/threejs.rb', line 100 def set_animation_loop(renderer_handle, callback) @adapter.set_animation_loop(renderer_handle, callback) end |
#set_clear_color(renderer_handle, color, alpha = 1) ⇒ Object
92 93 94 |
# File 'lib/three/backends/threejs.rb', line 92 def set_clear_color(renderer_handle, color, alpha = 1) @adapter.set_clear_color(renderer_handle, color, alpha) end |
#set_control_property(control_handle, name, value) ⇒ Object
160 161 162 |
# File 'lib/three/backends/threejs.rb', line 160 def set_control_property(control_handle, name, value) @adapter.set_control_property(control_handle, name, value) end |
#set_effect_composer_size(composer_handle, width, height) ⇒ Object
118 119 120 |
# File 'lib/three/backends/threejs.rb', line 118 def set_effect_composer_size(composer_handle, width, height) @adapter.effect_composer_set_size(composer_handle, width, height) end |
#set_orbit_controls_target(control_handle, target) ⇒ Object
164 165 166 |
# File 'lib/three/backends/threejs.rb', line 164 def set_orbit_controls_target(control_handle, target) @adapter.set_orbit_controls_target(control_handle, target) end |
#set_postprocessing_pass_property(pass_handle, name, value) ⇒ Object
148 149 150 |
# File 'lib/three/backends/threejs.rb', line 148 def set_postprocessing_pass_property(pass_handle, name, value) @adapter.set_postprocessing_pass_property(pass_handle, name, value) end |
#set_postprocessing_pass_uniform(pass_handle, name, value) ⇒ Object
152 153 154 |
# File 'lib/three/backends/threejs.rb', line 152 def set_postprocessing_pass_uniform(pass_handle, name, value) @adapter.set_postprocessing_pass_uniform(pass_handle, name, value) end |
#set_raycaster_from_camera(raycaster_handle, coords, camera) ⇒ Object
190 191 192 |
# File 'lib/three/backends/threejs.rb', line 190 def set_raycaster_from_camera(raycaster_handle, coords, camera) @adapter.set_raycaster_from_camera(raycaster_handle, coords, sync(camera)) end |
#set_renderer_shadow_map(renderer_handle, enabled: nil, type: nil, auto_update: nil) ⇒ Object
96 97 98 |
# File 'lib/three/backends/threejs.rb', line 96 def set_renderer_shadow_map(renderer_handle, enabled: nil, type: nil, auto_update: nil) @adapter.set_renderer_shadow_map(renderer_handle, enabled: enabled, type: type, auto_update: auto_update) end |
#set_renderer_size(renderer_handle, width, height) ⇒ Object
88 89 90 |
# File 'lib/three/backends/threejs.rb', line 88 def set_renderer_size(renderer_handle, width, height) @adapter.set_renderer_size(renderer_handle, width, height) end |
#stop_all_animation_actions(mixer_handle) ⇒ Object
213 214 215 |
# File 'lib/three/backends/threejs.rb', line 213 def stop_all_animation_actions(mixer_handle) @adapter.stop_all_animation_actions(mixer_handle) end |
#stop_animation_action(action_handle) ⇒ Object
229 230 231 |
# File 'lib/three/backends/threejs.rb', line 229 def stop_animation_action(action_handle) @adapter.stop_animation_action(action_handle) end |
#sync(object) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/three/backends/threejs.rb', line 256 def sync(object) handle = materialize(object) case object when Object3D sync_object3d(object, handle) when BufferGeometry sync_geometry(object, handle) when Texture sync_texture(object, handle) when Material sync_material(object, handle) end handle end |
#sync_object_transform_from_handle(object) ⇒ Object
176 177 178 179 180 181 182 183 184 |
# File 'lib/three/backends/threejs.rb', line 176 def sync_object_transform_from_handle(object) handle = materialize(object) position, quaternion, scale = @adapter.object_transform(handle) object.position.set(*position) object.quaternion.set(*quaternion) object.scale.set(*scale) object.mark_clean!(:transform) if object.respond_to?(:mark_clean!) object end |
#traverse_handles(object, &block) ⇒ Object
284 285 286 287 288 289 290 |
# File 'lib/three/backends/threejs.rb', line 284 def traverse_handles(object, &block) return enum_for(:traverse_handles, object) unless block handle = object3d_handle(object) @adapter.traverse_object3d(handle, block) handle end |
#uncache_animation_root(mixer_handle, root_handle) ⇒ Object
217 218 219 |
# File 'lib/three/backends/threejs.rb', line 217 def uncache_animation_root(mixer_handle, root_handle) @adapter.uncache_animation_root(mixer_handle, root_handle) end |
#update_animation_mixer(mixer_handle, delta) ⇒ Object
209 210 211 |
# File 'lib/three/backends/threejs.rb', line 209 def update_animation_mixer(mixer_handle, delta) @adapter.update_animation_mixer(mixer_handle, delta) end |
#update_controls(control_handle) ⇒ Object
168 169 170 |
# File 'lib/three/backends/threejs.rb', line 168 def update_controls(control_handle) @adapter.update_controls(control_handle) end |