Class: Three::Backends::ThreeJS::RubyWasmAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/three/backends/threejs/ruby_wasm_adapter.rb

Constant Summary collapse

TEXTURE_SLOTS =
%w[
  map
  normalMap
  roughnessMap
  metalnessMap
  aoMap
  emissiveMap
  alphaMap
  bumpMap
  displacementMap
  envMap
  gradientMap
  lightMap
  matcap
  specularMap
  anisotropyMap
  clearcoatMap
  clearcoatNormalMap
  clearcoatRoughnessMap
  transmissionMap
  thicknessMap
  iridescenceMap
  iridescenceThicknessMap
  sheenColorMap
  sheenRoughnessMap
  specularColorMap
  specularIntensityMap
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(three: nil) ⇒ RubyWasmAdapter

Returns a new instance of RubyWasmAdapter.



36
37
38
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 36

def initialize(three: nil)
  @three = three || default_three
end

Instance Method Details

#add_child(parent, child) ⇒ Object



567
568
569
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 567

def add_child(parent, child)
  parent.call(:add, child)
end

#add_geometry_group(geometry, start, count, material_index) ⇒ Object



423
424
425
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 423

def add_geometry_group(geometry, start, count, material_index)
  geometry.call(:addGroup, start, count, material_index)
end

#animation_clip_duration(clip) ⇒ Object



191
192
193
194
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 191

def animation_clip_duration(clip)
  value = clip[:duration]
  js_present?(value) ? value.to_f : 0.0
end

#animation_clip_name(clip) ⇒ Object



186
187
188
189
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 186

def animation_clip_name(clip)
  value = clip[:name]
  js_present?(value) ? value.to_s : ""
end

#animation_mixer_clip_action(mixer, clip, root = nil) ⇒ Object



200
201
202
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 200

def animation_mixer_clip_action(mixer, clip, root = nil)
  root ? mixer.call(:clipAction, clip, root) : mixer.call(:clipAction, clip)
end

#clear_children(parent) ⇒ Object



571
572
573
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 571

def clear_children(parent)
  parent.call(:clear)
end

#clear_geometry_groups(geometry) ⇒ Object



419
420
421
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 419

def clear_geometry_groups(geometry)
  geometry.call(:clearGroups)
end

#delete_geometry_attribute(geometry, name) ⇒ Object



415
416
417
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 415

def delete_geometry_attribute(geometry, name)
  geometry.call(:deleteAttribute, name.to_s)
end

#dispose(handle) ⇒ Object



583
584
585
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 583

def dispose(handle)
  handle.call(:dispose) if handle.respond_to?(:call)
end

#dispose_controls(control) ⇒ Object



271
272
273
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 271

def dispose_controls(control)
  control.call(:dispose)
end

#dispose_effect_composer(composer) ⇒ Object



103
104
105
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 103

def dispose_effect_composer(composer)
  composer.call(:dispose)
end

#dispose_object3d_subtree(object, remove: true, dispose_geometries: true, dispose_materials: true, dispose_textures: false, dispose_skeletons: true) ⇒ Object



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 633

def dispose_object3d_subtree(
  object,
  remove: true,
  dispose_geometries: true,
  dispose_materials: true,
  dispose_textures: false,
  dispose_skeletons: true
)
  resources = {
    geometries: JS.global[:Set].new,
    materials: JS.global[:Set].new,
    textures: JS.global[:Set].new,
    skeletons: JS.global[:Set].new
  }

  traverse_object3d(object, proc do |node|
    collect_object3d_resources(
      node,
      resources,
      dispose_geometries: dispose_geometries,
      dispose_materials: dispose_materials,
      dispose_textures: dispose_textures,
      dispose_skeletons: dispose_skeletons
    )
  end)

  remove_from_js_parent(object) if remove

  dispose_js_set(resources[:geometries])
  dispose_js_set(resources[:materials])
  dispose_js_set(resources[:textures])
  dispose_js_set(resources[:skeletons])
  object
end

#effect_composer_add_pass(composer, pass) ⇒ Object



85
86
87
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 85

def effect_composer_add_pass(composer, pass)
  composer.call(:addPass, pass)
end

#effect_composer_render(composer) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 93

def effect_composer_render(composer)
  render_helper = JS.global[:__threeRbRenderComposer]
  if render_helper.typeof == "function"
    JS.global[:__threeRbCurrentComposer] = composer
    JS.global.call(:__threeRbRenderComposer)
  else
    composer.call(:render)
  end
end

#effect_composer_set_size(composer, width, height) ⇒ Object



89
90
91
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 89

def effect_composer_set_size(composer, width, height)
  composer.call(:setSize, width, height)
end

#fade_in_animation_action(action, duration) ⇒ Object



232
233
234
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 232

def fade_in_animation_action(action, duration)
  action.call(:fadeIn, duration)
end

#fade_out_animation_action(action, duration) ⇒ Object



236
237
238
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 236

def fade_out_animation_action(action, duration)
  action.call(:fadeOut, duration)
end

#gltf_animations(gltf) ⇒ Object



181
182
183
184
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 181

def gltf_animations(gltf)
  animations = gltf[:animations]
  js_present?(animations) ? animations.to_a : []
end

#intersect_objects(raycaster, objects, recursive: false) ⇒ Object



152
153
154
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 152

def intersect_objects(raycaster, objects, recursive: false)
  raycaster.call(:intersectObjects, js_array(objects), recursive).to_a
end

#intersection_distance(intersection) ⇒ Object



594
595
596
597
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 594

def intersection_distance(intersection)
  value = intersection[:distance]
  js_present?(value) ? value.to_f : nil
end

#intersection_face_index(intersection) ⇒ Object



613
614
615
616
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 613

def intersection_face_index(intersection)
  value = intersection[:faceIndex]
  js_present?(value) ? value.to_i : nil
end

#intersection_index(intersection) ⇒ Object



618
619
620
621
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 618

def intersection_index(intersection)
  value = intersection[:index]
  js_present?(value) ? value.to_i : nil
end

#intersection_instance_id(intersection) ⇒ Object



623
624
625
626
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 623

def intersection_instance_id(intersection)
  value = intersection[:instanceId]
  js_present?(value) ? value.to_i : nil
end

#intersection_object(intersection) ⇒ Object



604
605
606
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 604

def intersection_object(intersection)
  intersection[:object]
end

#intersection_point(intersection) ⇒ Object



599
600
601
602
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 599

def intersection_point(intersection)
  point = intersection[:point]
  js_present?(point) ? js_vector_to_a(point, 3) : nil
end

#intersection_uv(intersection) ⇒ Object



608
609
610
611
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 608

def intersection_uv(intersection)
  uv = intersection[:uv]
  js_present?(uv) ? js_vector_to_a(uv, 2) : nil
end

#load_cube_texture(sources, parameters = {}) ⇒ Object



162
163
164
165
166
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 162

def load_cube_texture(sources, parameters = {})
  texture = @three[:CubeTextureLoader].new.call(:load, js_array(sources))
  update_texture(texture, parameters)
  texture
end

#load_gltf(source, draco_decoder_path: nil, draco_decoder_config: nil) ⇒ Object



175
176
177
178
179
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 175

def load_gltf(source, draco_decoder_path: nil, draco_decoder_config: nil)
  loader = gltf_loader_constructor.new
  configure_draco_loader(loader, draco_decoder_path, draco_decoder_config) if draco_decoder_path
  loader.call(:loadAsync, source)
end

#load_rgbe_texture(source, parameters = {}) ⇒ Object



168
169
170
171
172
173
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 168

def load_rgbe_texture(source, parameters = {})
  texture = rgbe_loader_constructor.new.call(:loadAsync, source)
  texture = texture.await if texture.respond_to?(:await)
  update_texture(texture, parameters)
  texture
end

#load_texture(source, parameters = {}) ⇒ Object



156
157
158
159
160
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 156

def load_texture(source, parameters = {})
  texture = @three[:TextureLoader].new.call(:load, source)
  update_texture(texture, parameters)
  texture
end

#new_ambient_light(color, intensity) ⇒ Object



303
304
305
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 303

def new_ambient_light(color, intensity)
  @three[:AmbientLight].new(color, intensity)
end

#new_animation_mixer(root) ⇒ Object



196
197
198
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 196

def new_animation_mixer(root)
  @three[:AnimationMixer].new(root)
end

#new_box_geometry(width, height, depth, width_segments, height_segments, depth_segments) ⇒ Object



386
387
388
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 386

def new_box_geometry(width, height, depth, width_segments, height_segments, depth_segments)
  @three[:BoxGeometry].new(width, height, depth, width_segments, height_segments, depth_segments)
end

#new_buffer_attribute(component_type, array, item_size, normalized) ⇒ Object



402
403
404
405
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 402

def new_buffer_attribute(component_type, array, item_size, normalized)
  typed_array = typed_array(component_type, array)
  @three[:BufferAttribute].new(typed_array, item_size, normalized)
end

#new_buffer_geometryObject



398
399
400
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 398

def new_buffer_geometry
  @three[:BufferGeometry].new
end

#new_directional_light(color, intensity) ⇒ Object



307
308
309
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 307

def new_directional_light(color, intensity)
  @three[:DirectionalLight].new(color, intensity)
end

#new_dot_screen_pass(center, angle, scale) ⇒ Object



115
116
117
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 115

def new_dot_screen_pass(center, angle, scale)
  dot_screen_pass_constructor.new(@three[:Vector2].new(*center), angle, scale)
end

#new_effect_composer(renderer) ⇒ Object



81
82
83
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 81

def new_effect_composer(renderer)
  effect_composer_constructor.new(renderer)
end

#new_groupObject



287
288
289
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 287

def new_group
  @three[:Group].new
end

#new_hemisphere_light(sky_color, ground_color, intensity) ⇒ Object



315
316
317
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 315

def new_hemisphere_light(sky_color, ground_color, intensity)
  @three[:HemisphereLight].new(sky_color, ground_color, intensity)
end

#new_instanced_mesh(geometry, material, count) ⇒ Object



335
336
337
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 335

def new_instanced_mesh(geometry, material, count)
  @three[:InstancedMesh].new(geometry, material, count)
end

#new_line(geometry, material) ⇒ Object



323
324
325
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 323

def new_line(geometry, material)
  @three[:Line].new(geometry, material)
end

#new_line_basic_material(parameters) ⇒ Object



435
436
437
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 435

def new_line_basic_material(parameters)
  @three[:LineBasicMaterial].new(stringify_keys(parameters))
end

#new_mesh(geometry, material) ⇒ Object



319
320
321
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 319

def new_mesh(geometry, material)
  @three[:Mesh].new(geometry, material)
end

#new_mesh_basic_material(parameters) ⇒ Object



431
432
433
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 431

def new_mesh_basic_material(parameters)
  @three[:MeshBasicMaterial].new(stringify_keys(parameters))
end

#new_mesh_lambert_material(parameters) ⇒ Object



439
440
441
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 439

def new_mesh_lambert_material(parameters)
  @three[:MeshLambertMaterial].new(stringify_keys(parameters))
end

#new_mesh_matcap_material(parameters) ⇒ Object



443
444
445
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 443

def new_mesh_matcap_material(parameters)
  @three[:MeshMatcapMaterial].new(stringify_keys(parameters))
end

#new_mesh_normal_material(parameters) ⇒ Object



447
448
449
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 447

def new_mesh_normal_material(parameters)
  @three[:MeshNormalMaterial].new(stringify_keys(parameters))
end

#new_mesh_phong_material(parameters) ⇒ Object



451
452
453
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 451

def new_mesh_phong_material(parameters)
  @three[:MeshPhongMaterial].new(stringify_keys(parameters))
end

#new_mesh_physical_material(parameters) ⇒ Object



455
456
457
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 455

def new_mesh_physical_material(parameters)
  @three[:MeshPhysicalMaterial].new(stringify_keys(parameters))
end

#new_mesh_standard_material(parameters) ⇒ Object



459
460
461
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 459

def new_mesh_standard_material(parameters)
  @three[:MeshStandardMaterial].new(stringify_keys(parameters))
end

#new_mesh_toon_material(parameters) ⇒ Object



463
464
465
466
467
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 463

def new_mesh_toon_material(parameters)
  material = @three[:MeshToonMaterial].new(stringify_keys(parameters))
  update_material(material, parameters)
  material
end

#new_object3dObject



291
292
293
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 291

def new_object3d
  @three[:Object3D].new
end

#new_orbit_controls(camera, dom_element) ⇒ Object



139
140
141
142
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 139

def new_orbit_controls(camera, dom_element)
  constructor = orbit_controls_constructor
  dom_element ? constructor.new(camera, dom_element) : constructor.new(camera)
end

#new_orthographic_camera(left, right, top, bottom, near, far) ⇒ Object



299
300
301
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 299

def new_orthographic_camera(left, right, top, bottom, near, far)
  @three[:OrthographicCamera].new(left, right, top, bottom, near, far)
end

#new_output_passObject



119
120
121
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 119

def new_output_pass
  output_pass_constructor.new
end

#new_perspective_camera(fov, aspect, near, far) ⇒ Object



295
296
297
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 295

def new_perspective_camera(fov, aspect, near, far)
  @three[:PerspectiveCamera].new(fov, aspect, near, far)
end

#new_plane_geometry(width, height, width_segments, height_segments) ⇒ Object



390
391
392
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 390

def new_plane_geometry(width, height, width_segments, height_segments)
  @three[:PlaneGeometry].new(width, height, width_segments, height_segments)
end

#new_point_light(color, intensity, distance, decay) ⇒ Object



311
312
313
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 311

def new_point_light(color, intensity, distance, decay)
  @three[:PointLight].new(color, intensity, distance, decay)
end

#new_points(geometry, material) ⇒ Object



327
328
329
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 327

def new_points(geometry, material)
  @three[:Points].new(geometry, material)
end

#new_points_material(parameters) ⇒ Object



469
470
471
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 469

def new_points_material(parameters)
  @three[:PointsMaterial].new(stringify_keys(parameters))
end

#new_raycasterObject



144
145
146
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 144

def new_raycaster
  @three[:Raycaster].new
end

#new_render_pass(scene, camera) ⇒ Object



107
108
109
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 107

def new_render_pass(scene, camera)
  render_pass_constructor.new(scene, camera)
end

#new_sceneObject



283
284
285
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 283

def new_scene
  @three[:Scene].new
end

#new_shadow_material(parameters) ⇒ Object



473
474
475
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 473

def new_shadow_material(parameters)
  @three[:ShadowMaterial].new(stringify_keys(parameters))
end

#new_sphere_geometry(radius, width_segments, height_segments, phi_start, phi_length, theta_start, theta_length) ⇒ Object



394
395
396
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 394

def new_sphere_geometry(radius, width_segments, height_segments, phi_start, phi_length, theta_start, theta_length)
  @three[:SphereGeometry].new(radius, width_segments, height_segments, phi_start, phi_length, theta_start, theta_length)
end

#new_sprite(material) ⇒ Object



331
332
333
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 331

def new_sprite(material)
  @three[:Sprite].new(material)
end

#new_sprite_material(parameters) ⇒ Object



477
478
479
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 477

def new_sprite_material(parameters)
  @three[:SpriteMaterial].new(stringify_keys(parameters))
end

#new_unreal_bloom_pass(resolution, strength, radius, threshold) ⇒ Object



111
112
113
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 111

def new_unreal_bloom_pass(resolution, strength, radius, threshold)
  unreal_bloom_pass_constructor.new(@three[:Vector2].new(*resolution), strength, radius, threshold)
end

#new_webgl_renderer(options = {}) ⇒ Object



40
41
42
43
44
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 40

def new_webgl_renderer(options = {})
  parameters = stringify_keys(options)
  parameters["canvas"] = resolve_canvas(options[:canvas] || options["canvas"]) if options[:canvas] || options["canvas"]
  @three[:WebGLRenderer].new(parameters)
end

#object_handle_key(object) ⇒ Object



587
588
589
590
591
592
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 587

def object_handle_key(object)
  return nil unless js_present?(object)

  uuid = object[:uuid]
  js_present?(uuid) ? uuid.to_s : nil
end

#object_transform(object) ⇒ Object



275
276
277
278
279
280
281
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 275

def object_transform(object)
  [
    js_vector_to_a(object[:position], 3),
    js_vector_to_a(object[:quaternion], 4),
    js_vector_to_a(object[:scale], 3)
  ]
end

#play_animation_action(action) ⇒ Object



220
221
222
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 220

def play_animation_action(action)
  action.call(:play)
end

#render(renderer, scene, camera) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 69

def render(renderer, scene, camera)
  render_helper = JS.global[:__threeRbRender]
  if render_helper.typeof == "function"
    JS.global[:__threeRbCurrentRenderer] = renderer
    JS.global[:__threeRbCurrentScene] = scene
    JS.global[:__threeRbCurrentCamera] = camera
    JS.global.call(:__threeRbRender)
  else
    renderer.call(:render, scene, camera)
  end
end

#renderer_dom_element(renderer) ⇒ Object



46
47
48
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 46

def renderer_dom_element(renderer)
  renderer[:domElement]
end

#reset_animation_action(action) ⇒ Object



228
229
230
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 228

def reset_animation_action(action)
  action.call(:reset)
end

#set_animation_action_property(action, name, value) ⇒ Object



216
217
218
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 216

def set_animation_action_property(action, name, value)
  action[name] = value
end

#set_animation_loop(renderer, callback) ⇒ Object



65
66
67
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 65

def set_animation_loop(renderer, callback)
  renderer.call(:setAnimationLoop, callback)
end

#set_clear_color(renderer, color, alpha = 1) ⇒ Object



54
55
56
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 54

def set_clear_color(renderer, color, alpha = 1)
  renderer.call(:setClearColor, color, alpha)
end

#set_control_property(control, name, value) ⇒ Object



259
260
261
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 259

def set_control_property(control, name, value)
  control[name] = value
end

#set_geometry_attribute(geometry, name, attribute) ⇒ Object



411
412
413
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 411

def set_geometry_attribute(geometry, name, attribute)
  geometry.call(:setAttribute, name.to_s, attribute)
end

#set_geometry_draw_range(geometry, start, count) ⇒ Object



427
428
429
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 427

def set_geometry_draw_range(geometry, start, count)
  geometry.call(:setDrawRange, start, count)
end

#set_geometry_index(geometry, attribute) ⇒ Object



407
408
409
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 407

def set_geometry_index(geometry, attribute)
  geometry.call(:setIndex, attribute)
end

#set_instanced_mesh_color_at(mesh, index, color) ⇒ Object



377
378
379
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 377

def set_instanced_mesh_color_at(mesh, index, color)
  mesh.call(:setColorAt, index, @three[:Color].new(*color))
end

#set_instanced_mesh_count(mesh, count) ⇒ Object



363
364
365
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 363

def set_instanced_mesh_count(mesh, count)
  mesh[:count] = count
end

#set_instanced_mesh_instance_color_needs_update(mesh, value) ⇒ Object



381
382
383
384
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 381

def set_instanced_mesh_instance_color_needs_update(mesh, value)
  instance_color = mesh[:instanceColor]
  instance_color[:needsUpdate] = value if js_present?(instance_color)
end

#set_instanced_mesh_instance_matrix_needs_update(mesh, value) ⇒ Object



373
374
375
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 373

def set_instanced_mesh_instance_matrix_needs_update(mesh, value)
  mesh[:instanceMatrix][:needsUpdate] = value
end

#set_instanced_mesh_matrix_at(mesh, index, elements) ⇒ Object



367
368
369
370
371
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 367

def set_instanced_mesh_matrix_at(mesh, index, elements)
  matrix = @three[:Matrix4].new
  matrix.call(:fromArray, js_array(elements))
  mesh.call(:setMatrixAt, index, matrix)
end

#set_mesh_geometry(mesh, geometry) ⇒ Object



347
348
349
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 347

def set_mesh_geometry(mesh, geometry)
  set_object_geometry(mesh, geometry)
end

#set_mesh_material(mesh, material) ⇒ Object



351
352
353
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 351

def set_mesh_material(mesh, material)
  set_object_material(mesh, material)
end

#set_object_geometry(object, geometry) ⇒ Object



339
340
341
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 339

def set_object_geometry(object, geometry)
  object[:geometry] = geometry
end

#set_object_layers(object, mask) ⇒ Object



359
360
361
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 359

def set_object_layers(object, mask)
  object[:layers][:mask] = mask if js_present?(object[:layers])
end

#set_object_material(object, material) ⇒ Object



343
344
345
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 343

def set_object_material(object, material)
  object[:material] = material
end

#set_object_name(object, name) ⇒ Object



481
482
483
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 481

def set_object_name(object, name)
  object[:name] = name
end

#set_object_shadow(object, cast_shadow, receive_shadow) ⇒ Object



489
490
491
492
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 489

def set_object_shadow(object, cast_shadow, receive_shadow)
  object[:castShadow] = cast_shadow
  object[:receiveShadow] = receive_shadow
end

#set_object_transform(object, position, quaternion, scale) ⇒ Object



494
495
496
497
498
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 494

def set_object_transform(object, position, quaternion, scale)
  object[:position].call(:set, *position)
  object[:quaternion].call(:set, *quaternion)
  object[:scale].call(:set, *scale)
end

#set_object_visible(object, visible) ⇒ Object



485
486
487
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 485

def set_object_visible(object, visible)
  object[:visible] = visible
end

#set_orbit_controls_target(control, target) ⇒ Object



263
264
265
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 263

def set_orbit_controls_target(control, target)
  control[:target].call(:set, *target)
end

#set_postprocessing_pass_property(pass, name, value) ⇒ Object



123
124
125
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 123

def set_postprocessing_pass_property(pass, name, value)
  pass[name] = value
end

#set_postprocessing_pass_uniform(pass, name, value) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 127

def set_postprocessing_pass_uniform(pass, name, value)
  uniform = pass[:uniforms][name]
  return unless js_present?(uniform)

  target = uniform[:value]
  if value.respond_to?(:to_a) && js_present?(target) && target.respond_to?(:call)
    target.call(:set, *value.to_a)
  else
    uniform[:value] = value
  end
end

#set_raycaster_from_camera(raycaster, coords, camera) ⇒ Object



148
149
150
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 148

def set_raycaster_from_camera(raycaster, coords, camera)
  raycaster.call(:setFromCamera, @three[:Vector2].new(*coords), camera)
end

#set_renderer_shadow_map(renderer, enabled: nil, type: nil, auto_update: nil) ⇒ Object



58
59
60
61
62
63
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 58

def set_renderer_shadow_map(renderer, enabled: nil, type: nil, auto_update: nil)
  shadow_map = renderer[:shadowMap]
  shadow_map[:enabled] = enabled unless enabled.nil?
  shadow_map[:type] = type unless type.nil?
  shadow_map[:autoUpdate] = auto_update unless auto_update.nil?
end

#set_renderer_size(renderer, width, height) ⇒ Object



50
51
52
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 50

def set_renderer_size(renderer, width, height)
  renderer.call(:setSize, width, height)
end

#set_scene_background(scene, background) ⇒ Object



575
576
577
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 575

def set_scene_background(scene, background)
  scene[:background] = background
end

#set_scene_environment(scene, environment) ⇒ Object



579
580
581
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 579

def set_scene_environment(scene, environment)
  scene[:environment] = environment
end

#set_sprite_center(sprite, center) ⇒ Object



355
356
357
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 355

def set_sprite_center(sprite, center)
  sprite[:center].call(:set, *center)
end

#stop_all_animation_actions(mixer) ⇒ Object



208
209
210
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 208

def stop_all_animation_actions(mixer)
  mixer.call(:stopAllAction)
end

#stop_animation_action(action) ⇒ Object



224
225
226
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 224

def stop_animation_action(action)
  action.call(:stop)
end

#traverse_object3d(object, callback) ⇒ Object



628
629
630
631
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 628

def traverse_object3d(object, callback)
  object.call(:traverse, callback)
  object
end

#uncache_animation_root(mixer, root) ⇒ Object



212
213
214
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 212

def uncache_animation_root(mixer, root)
  mixer.call(:uncacheRoot, root)
end

#update_animation_mixer(mixer, delta) ⇒ Object



204
205
206
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 204

def update_animation_mixer(mixer, delta)
  mixer.call(:update, delta)
end

#update_controls(control) ⇒ Object



267
268
269
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 267

def update_controls(control)
  control.call(:update)
end

#update_hemisphere_light(light, sky_color, ground_color, intensity) ⇒ Object



531
532
533
534
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 531

def update_hemisphere_light(light, sky_color, ground_color, intensity)
  update_light(light, sky_color, intensity)
  light[:groundColor].call(:setHex, ground_color)
end

#update_light(light, color, intensity) ⇒ Object



520
521
522
523
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 520

def update_light(light, color, intensity)
  light[:color].call(:setHex, color)
  light[:intensity] = intensity
end

#update_light_shadow(light, parameters) ⇒ Object



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 536

def update_light_shadow(light, parameters)
  shadow = light[:shadow]
  return unless js_present?(shadow)

  if parameters[:map_size]
    shadow[:mapSize].call(:set, *parameters[:map_size])
  end
  shadow[:bias] = parameters[:bias] unless parameters[:bias].nil?
  shadow[:normalBias] = parameters[:normal_bias] unless parameters[:normal_bias].nil?
  shadow[:radius] = parameters[:radius] unless parameters[:radius].nil?

  camera = shadow[:camera]
  if js_present?(camera) && parameters[:camera]
    parameters[:camera].each do |key, value|
      camera[key] = value
    end
    camera.call(:updateProjectionMatrix)
  end
end

#update_material(material, parameters) ⇒ Object



556
557
558
559
560
561
562
563
564
565
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 556

def update_material(material, parameters)
  parameters.each do |key, value|
    if MATERIAL_COLOR_PARAMETERS.include?(key)
      material[key].call(:setHex, value)
    else
      material[key] = value
    end
  end
  material[:needsUpdate] = true
end

#update_orthographic_camera(camera, left, right, top, bottom, near, far, zoom) ⇒ Object



509
510
511
512
513
514
515
516
517
518
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 509

def update_orthographic_camera(camera, left, right, top, bottom, near, far, zoom)
  camera[:left] = left
  camera[:right] = right
  camera[:top] = top
  camera[:bottom] = bottom
  camera[:near] = near
  camera[:far] = far
  camera[:zoom] = zoom
  camera.call(:updateProjectionMatrix)
end

#update_perspective_camera(camera, fov, aspect, near, far, zoom) ⇒ Object



500
501
502
503
504
505
506
507
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 500

def update_perspective_camera(camera, fov, aspect, near, far, zoom)
  camera[:fov] = fov
  camera[:aspect] = aspect
  camera[:near] = near
  camera[:far] = far
  camera[:zoom] = zoom
  camera.call(:updateProjectionMatrix)
end

#update_point_light(light, color, intensity, distance, decay) ⇒ Object



525
526
527
528
529
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 525

def update_point_light(light, color, intensity, distance, decay)
  update_light(light, color, intensity)
  light[:distance] = distance
  light[:decay] = decay
end

#update_texture(texture, parameters) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/three/backends/threejs/ruby_wasm_adapter.rb', line 240

def update_texture(texture, parameters)
  texture[:mapping] = parameters[:mapping] unless parameters[:mapping].nil?
  texture[:colorSpace] = parameters[:color_space] unless parameters[:color_space].nil?
  texture[:flipY] = parameters[:flip_y] unless parameters[:flip_y].nil?
  texture[:wrapS] = parameters[:wrap_s] unless parameters[:wrap_s].nil?
  texture[:wrapT] = parameters[:wrap_t] unless parameters[:wrap_t].nil?
  texture[:magFilter] = parameters[:mag_filter] unless parameters[:mag_filter].nil?
  texture[:minFilter] = parameters[:min_filter] unless parameters[:min_filter].nil?
  texture[:offset].call(:set, *parameters[:offset]) if parameters[:offset]
  texture[:repeat].call(:set, *parameters[:repeat]) if parameters[:repeat]
  texture[:center].call(:set, *parameters[:center]) if parameters[:center]
  texture[:rotation] = parameters[:rotation] unless parameters[:rotation].nil?
  texture[:matrixAutoUpdate] = parameters[:matrix_auto_update] unless parameters[:matrix_auto_update].nil?
  texture[:matrix].call(:fromArray, js_array(parameters[:matrix])) if parameters[:matrix]
  texture.call(:updateMatrix) if parameters[:matrix_auto_update]
  texture[:needsUpdate] = true
  texture
end