wco_models 3.4.0.10 → 3.5.0.2

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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/wco/main.scss +3 -7
  3. data/app/assets/stylesheets/wco/photos.scss +1 -2
  4. data/app/controllers/wco/api/newspartials_controller.rb +15 -5
  5. data/app/controllers/wco/newspartials_controller.rb +2 -2
  6. data/app/controllers/wco/newsvideos_controller.rb +14 -10
  7. data/app/controllers/wco/office_action_templates_controller.rb +0 -3
  8. data/app/controllers/wco/publishers_controller.rb +16 -6
  9. data/app/controllers/wco/reports_controller.rb +5 -6
  10. data/app/controllers/wco/sitemap_paths_controller.rb +2 -14
  11. data/app/controllers/wco/sites_controller.rb +1 -1
  12. data/app/controllers/wco/tags_controller.rb +1 -1
  13. data/app/models/iro/option.rb +4 -37
  14. data/app/models/iro/priceitem.rb +4 -62
  15. data/app/models/tda/option.rb +41 -39
  16. data/app/models/wco/newspartial.rb +33 -8
  17. data/app/models/wco/newsvideo.rb +4 -3
  18. data/app/models/wco/publisher.rb +8 -29
  19. data/app/models/wco/report.rb +2 -12
  20. data/app/models/wco/setting.rb +1 -1
  21. data/app/models/wco/site.rb +67 -1
  22. data/app/models/wco/sitemap_path.rb +13 -19
  23. data/app/models/wco/tag.rb +8 -15
  24. data/app/models/wco/utils.rb +19 -0
  25. data/app/views/wco/api/newsproducer/_studio_blue2.js +205 -317
  26. data/app/views/wco/api/newsproducer/_studio_fps.js +12 -12
  27. data/app/views/wco/api/newsproducer/studio_blue2.html.erb +25 -24
  28. data/app/views/wco/api/newsproducer/studio_fps.html.erb +8 -10
  29. data/app/views/wco/api/newsproducer/trash/_scenes.js-bk +20 -0
  30. data/app/views/wco/api/newsproducer/trash/_scenes.js.erb +15 -0
  31. data/app/views/wco/api/newsproducer/trash/_studio_blue0.js +326 -0
  32. data/app/views/wco/api/newsproducer/trash/_studio_blue1.js +733 -0
  33. data/app/views/wco/api/newsproducer/trash/studio_blue0.html.erb +27 -0
  34. data/app/views/wco/api/newsproducer/trash/studio_blue1.html.erb +108 -0
  35. data/app/views/wco/api/newsvideos/show.jbuilder +1 -1
  36. data/app/views/wco/newspartials/_form.haml +6 -0
  37. data/app/views/wco/newspartials/_show_in_newsvideo.haml +2 -2
  38. data/app/views/wco/newsvideos/_form.haml +4 -0
  39. data/app/views/wco/newsvideos/show.haml +2 -2
  40. data/app/views/wco/office_action_templates/index.haml +1 -1
  41. data/app/views/wco/office_actions/_actions.haml +1 -1
  42. data/app/views/wco/publishers/_form.haml +2 -11
  43. data/app/views/wco/publishers/_post_with.haml +1 -1
  44. data/app/views/wco/reports/_form.haml +2 -13
  45. data/app/views/wco/reports/_index.haml +11 -18
  46. data/app/views/wco/reports/show.haml +1 -6
  47. data/app/views/wco/sitemap_paths/_index.haml +0 -1
  48. data/app/views/wco/sitemap_paths/check.haml +13 -0
  49. data/app/views/wco/sites/index.haml +0 -6
  50. data/app/views/wco/sites/show.haml +1 -1
  51. data/app/views/wco/tags/_form.haml +0 -3
  52. data/config/routes.rb +12 -11
  53. data/lib/shortcuts.rb +1 -1
  54. data/lib/wco_models.rb +1 -1
  55. metadata +28 -24
  56. data/app/models/wco/publisher_d10.rb +0 -50
  57. data/app/views/wco/api/newsproducer/README_newsproducer.txt +0 -12
  58. data/app/views/wco/sitemap_paths/show.haml +0 -14
  59. /data/app/views/wco/api/newsproducer/{_scenes.js-bk → done/_scenes.js-bk} +0 -0
  60. /data/app/views/wco/api/newsproducer/{_scenes.js.erb → done/_scenes.js.erb} +0 -0
  61. /data/app/views/wco/api/newsproducer/{_studio_1.js → done/_studio_1.js} +0 -0
  62. /data/app/views/wco/api/newsproducer/{_studio_blue0.js → done/_studio_blue0.js} +0 -0
  63. /data/app/views/wco/api/newsproducer/{_studio_blue1.js → done/_studio_blue1.js} +0 -0
  64. /data/app/views/wco/api/newsproducer/{_studio_coc.js → done/_studio_coc.js} +0 -0
  65. /data/app/views/wco/api/newsproducer/{_studio_coc.js-bk → done/_studio_coc.js-bk} +0 -0
  66. /data/app/views/wco/api/newsproducer/{_studio_coc.js-cannon → done/_studio_coc.js-cannon} +0 -0
  67. /data/app/views/wco/api/newsproducer/{_studio_ra2.js → done/_studio_ra2.js} +0 -0
  68. /data/app/views/wco/api/newsproducer/{_touch_controls.js → done/_touch_controls.js} +0 -0
  69. /data/app/views/wco/api/newsproducer/{_touch_pad.css → done/_touch_pad.css} +0 -0
  70. /data/app/views/wco/api/newsproducer/{canvas.html.erb → done/canvas.html.erb} +0 -0
  71. /data/app/views/wco/api/newsproducer/{canvas_minimal.html.erb → done/canvas_minimal.html.erb} +0 -0
  72. /data/app/views/wco/api/newsproducer/{games_fps.html → done/games_fps.html} +0 -0
  73. /data/app/views/wco/api/newsproducer/{studio_1.html.erb → done/studio_1.html.erb} +0 -0
  74. /data/app/views/wco/api/newsproducer/{studio_blue0.html.erb → done/studio_blue0.html.erb} +0 -0
  75. /data/app/views/wco/api/newsproducer/{studio_blue1.html.erb → done/studio_blue1.html.erb} +0 -0
  76. /data/app/views/wco/api/newsproducer/{studio_coc.html.erb → done/studio_coc.html.erb} +0 -0
  77. /data/app/views/wco/api/newsproducer/{studio_ra2.html.erb → done/studio_ra2.html.erb} +0 -0
@@ -10,76 +10,44 @@ const logg = (a, b="", c=null) => {
10
10
  console.log(`+++ ${b}:`, a) // eslint-disable-line no-console
11
11
  }
12
12
 
13
- const MODELS_ROOT = 'https://localhost/vendor/models';
14
- // const AVATARS_ROOT = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.3.0/public/vendor/models/avatars';
15
- const AVATARS_ROOT = 'https://localhost/vendor/models/avatars';
16
- const avatars = {
13
+
14
+ const MODELS_ROOT = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@v0.4.14/public/vendor/models'
15
+ const AVATARS_ROOT = `${MODELS_ROOT}/avatars`
16
+ const avatars_config = {
17
17
  brunette: { type: 'F', url: `${AVATARS_ROOT}/brunette/model.glb` },
18
18
  cara: { type: 'F', url: `${AVATARS_ROOT}/cara/model.glb` }, // short hair
19
- eve: { type: 'F', url: `${AVATARS_ROOT}/eve/model.glb` }, // poison green
19
+ eve: { type: 'F', url: `${AVATARS_ROOT}/eve/model.glb` }, // poison green
20
20
 
21
21
  denis: { type: 'M', url: `${AVATARS_ROOT}/denis/model.glb` }, // beard
22
22
  gregor: { type: 'M', url: `${AVATARS_ROOT}/gregor/model.glb` }, // gray shirt
23
23
  }
24
24
  const AVATAR_STOR = 'avatar'
25
- $('select.avatar').each((_idx, el) => {
26
- const $select = $(el)
27
- $.each(avatars, function(name, url) {
28
- $('<option>', {
29
- value: name,
30
- text: name,
31
- }).appendTo($select)
25
+ $('select.avatars').each((_idx, el) => {
26
+ const $avatar = $(el)
27
+ $.each(avatars_config, function(name) {
28
+ $('<option>', { value: name, text: name }).appendTo($avatar)
32
29
  })
33
30
  try {
34
- const saved = localStorage.getItem(`${AVATAR_STOR}-${$select.data('uid')}`)
35
- if (saved && avatars[saved]) $select.val(saved)
31
+ const saved_name = localStorage.getItem(`${AVATAR_STOR}-${$avatar.data('spot_id')}`)
32
+ if (saved_name && avatars_config[saved_name]) $avatar.val(saved_name)
36
33
  } catch (error) {
37
34
  console.log(error)
38
35
  }
39
36
  })
40
37
 
41
- let scenes = {
42
- skybox_1: {
43
- url: `${MODELS_ROOT}/scenes/000mb skybox_1/scene.glb`,
44
- height: 30,
45
- },
46
- studio_tron: {
47
- height: 10,
48
- url: `${MODELS_ROOT}/scenes/003mb studio_tron/scene.glb`,
49
- },
50
- room_1: {
51
- height: 6,
52
- url: `${MODELS_ROOT}/scenes/000mb room-1/scene.glb`,
53
- },
54
- studio_blue: {
55
- height: 4.3,
56
- url: `${MODELS_ROOT}/scenes/000mb studio_blue/scene.glb`,
57
- },
58
- purple_stage: {
59
- height: 10,
60
- url: `${MODELS_ROOT}/scenes/000mb purple_stage/scene.glb`,
61
- },
62
- red_stage: {
63
- height: 10,
64
- url: `${MODELS_ROOT}/scenes/000mb red_stage/scene.glb`,
65
- },
66
- // skybox_1: `${MODELS_ROOT}/scenes//scene.glb`,
67
-
68
- newsroom_green: `${MODELS_ROOT}/scenes/001mb newsroom_green/scene.glb`,
69
- rick_and_morty_garage: `${MODELS_ROOT}/scenes/003mb rick-and-morty-garage/scene.glb`,
70
- }
71
- const SCENE_STOR = 'studio'
72
- $.each(scenes, (name) => {
73
- $('<option>', { value: name, text: name }).appendTo($('select.studio'))
38
+ let studios_config = await fetch(`${MODELS_ROOT}/scenes/index.json`).then(r => r.json())
39
+ const STUDIO_STOR = 'studio'
40
+ $.each(studios_config, (name) => {
41
+ $('<option>', { value: name, text: name }).appendTo($(`select.${STUDIO_STOR}`))
74
42
  })
75
43
  try {
76
- const saved = localStorage.getItem( SCENE_STOR )
77
- if (saved && scenes[saved]) $('select.studio').val(saved)
44
+ const saved_name = localStorage.getItem( STUDIO_STOR )
45
+ if (saved_name && studios_config[saved_name]) $(`select.${STUDIO_STOR}`).val(saved_name)
78
46
  } catch (error) {
79
47
  console.log(error)
80
48
  }
81
49
 
82
- let scene_url = scenes[$('select.studio').val()] || scenes.rick_and_morty_garage
50
+ let scene_url = studios_config[$(`select.${STUDIO_STOR}`).val()] || studios_config['collision-world']
83
51
 
84
52
  let gestures = {
85
53
  talking_1: (avatar) => `${MODELS_ROOT}/animation-library/feminine/fbx/expression/${avatar.body}_Talking_Variations_001.fbx`,
@@ -98,10 +66,10 @@ $.each(gestures, (name) => {
98
66
  $('<option>', { value: name, text: name }).appendTo($('select.gestures'))
99
67
  })
100
68
 
101
- let u_positions = {
102
- '1': [0, 0, 0],
103
- '2': [1, 0, 0],
104
- '3': [-1, 0, 0],
69
+ let spot_positions = {
70
+ 'spot_1': [0, 0, 0],
71
+ 'spot_2': [1, 0, 0],
72
+ 'spot_3': [-1, 0, 0],
105
73
  }
106
74
 
107
75
 
@@ -115,78 +83,77 @@ import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
115
83
  import { TalkingHead } from "talkinghead"
116
84
 
117
85
  const params = new URLSearchParams(window.location.search)
86
+ const api_key = params.get('api_key')
87
+ const api_secret = params.get('api_secret')
88
+ const wco_origin = params.get('wco_origin')
89
+ const newspartial_id = params.get('newspartial_id')
118
90
 
119
- let config = {
91
+ let streamOpts = {
120
92
  sampleRate: 8000,
121
93
  mood: 'neutral',
122
94
  gain: 0.5,
123
95
  lipsyncType: "visemes",
124
96
  lipsyncLang: "en",
125
97
  waitForAudioChunks: false,
126
- enableMetrics: false,
127
- };
128
-
129
- const onMetrics = (which) => {
130
- logg(which, 'onMetrics')
98
+ metrics: { enabled: false },
131
99
  }
132
100
 
133
101
  const onSubtitles = (which) => {
134
102
  logg(which, 'onSubtitles')
135
103
  }
136
- const streamOpts = {
137
- gain: config.gain,
138
- lipsyncLang: config.lipsyncLang,
139
- lipsyncType: config.lipsyncType,
140
- metrics: config.enableMetrics ? { enabled: true, intervalHz: config.metricsInterval } : { enabled: false },
141
- mood: config.mood,
142
- sampleRate: config.sampleRate,
143
- waitForAudioChunks: config.waitForAudioChunks,
144
- }
145
-
146
104
 
147
105
  let width = 854
148
106
  let height = 480
149
107
  let slug = '<ccapture>'
150
- const fps = 30
108
+ let fps = 30
151
109
 
152
110
  let frame = 0
153
111
  let lastAnimTime = 0
154
112
  let capturing = false
155
113
  let captureFrame = 0
156
114
  let captureTotal = 0
157
- const api_key = params.get('api_key')
158
- const api_secret = params.get('api_secret')
159
- const wco_origin = params.get('wco_origin')
160
- const newspartial_id = params.get('newspartial_id')
161
115
  let totalFrames
162
116
 
163
- let camera, camera_wide, camera_1, camera_2, camera_3
117
+ let active_camera
118
+ let cameras = {
119
+ wide: {
120
+ cam: null,
121
+ tgt: new THREE.Vector3(0.5, 1.2, 0),
122
+ },
123
+ spot_1: {
124
+ cam: null,
125
+ tgt: new THREE.Vector3(0, 1.5, 0),
126
+ },
127
+ spot_2: {
128
+ cam: null,
129
+ tgt: new THREE.Vector3(1, 1.5, 0),
130
+ },
131
+ spot_3: {
132
+ cam: null,
133
+ tgt: new THREE.Vector3(-1, 1.5, 0),
134
+ },
135
+ }
164
136
  let controls, renderer, scene
165
- let head, head_1, head_2, head_3
166
- let faceTarget = new THREE.Vector3()
167
- const cameraTargets = {
168
- wide: new THREE.Vector3(0.5, 1.2, 0),
169
- av_1: new THREE.Vector3(0, 1.5, 0),
170
- av_2: new THREE.Vector3(1, 1.5, 0),
171
- av_3: new THREE.Vector3(-1, 1.5, 0),
137
+ let active_avatar
138
+ let avatars = {
139
+ spot_1: null,
140
+ spot_2: null,
141
+ spot_3: null,
172
142
  }
143
+ let faceTarget = new THREE.Vector3()
173
144
  let cameraTransition = null
174
145
  const CAMERA_BLEND_MS = 900
175
146
  let chunkedInput = null
176
147
  const lights = {}
177
- const LIGHT_CTRL_KEY = 'wco.studio_blue.light-ctrl'
178
- const HEAD_CTRL_KEY = 'wco.studio_blue.head-ctrl'
179
- const CAMERA_CTRL_KEY = 'wco.studio_blue.camera-ctrl'
180
148
  var capturer = new CCapture( { format: 'webm', framerate: fps } )
181
149
  const gltfLoader = new GLTFLoader()
182
- const fbxLoader = new FBXLoader()
183
150
  const loading = document.getElementById('loading')
184
- const status = document.getElementById('status')
151
+ const status = document.getElementById('status')
185
152
 
186
153
  /*
187
154
  **/
188
155
  function point_camera_at_face(cam_id, _head) {
189
- const leftEye = new THREE.Vector3()
156
+ const leftEye = new THREE.Vector3()
190
157
  const rightEye = new THREE.Vector3()
191
158
  _head.objectLeftEye.getWorldPosition(leftEye)
192
159
  _head.objectRightEye.getWorldPosition(rightEye)
@@ -195,10 +162,10 @@ function point_camera_at_face(cam_id, _head) {
195
162
  const camPos = new THREE.Vector3(0, 0, 2)
196
163
  camPos.applyQuaternion(_head.armature.quaternion)
197
164
  camPos.add(faceTarget)
198
- const _camera = cameras_fn(cam_id)
165
+ const _camera = cameras[cam_id].cam
199
166
  _camera.position.copy(camPos)
200
167
  _camera.lookAt(faceTarget)
201
- cameraTargets[cam_id].copy(faceTarget)
168
+ cameras[cam_id].tgt.copy(faceTarget)
202
169
  }
203
170
 
204
171
  /*
@@ -220,19 +187,14 @@ function put_feet_at_origin(_head) {
220
187
 
221
188
  /*
222
189
  **/
223
- function rescale(model, config) {
190
+ function rescale(model, _config) {
224
191
  const box = new THREE.Box3().setFromObject(model)
225
192
  const size = box.getSize(new THREE.Vector3())
226
193
  const currentHeight = size.y
227
- const scale = config.height / currentHeight
194
+ const scale = _config.height / currentHeight
228
195
  model.scale.setScalar(scale)
229
196
  }
230
197
 
231
- function scene_cfg(s) {
232
- if (typeof s === 'string') return { url: s, height: 3.3 }
233
- return { url: s.url, height: s.height || 3.3 }
234
- }
235
-
236
198
  function set_shadows(root, cast, receive) {
237
199
  root.traverse((obj) => {
238
200
  if (obj.isMesh) {
@@ -273,68 +235,15 @@ function setup_light(scene) {
273
235
  lights.rimLight.position.set( 0, 6, -8 )
274
236
  scene.add( lights.rimLight )
275
237
 
276
- restoreLightControls()
277
238
  syncLightsFromControls()
278
239
  }
279
240
 
280
- function restoreLightControls() {
281
- try {
282
- const saved = JSON.parse(localStorage.getItem(LIGHT_CTRL_KEY) || 'null')
283
- if (!saved || typeof saved !== 'object') return
284
- document.querySelectorAll('input.light-ctrl').forEach((input) => {
285
- if (Object.prototype.hasOwnProperty.call(saved, input.name)) {
286
- input.checked = !!saved[input.name]
287
- }
288
- })
289
- } catch (error) {
290
- console.log(error)
291
- }
292
- }
293
-
294
- function persistLightControls() {
295
- const saved = {}
296
- document.querySelectorAll('input.light-ctrl').forEach((input) => {
297
- saved[input.name] = input.checked
298
- })
299
- localStorage.setItem(LIGHT_CTRL_KEY, JSON.stringify(saved))
300
- }
301
-
302
- function restoreHeadControl() {
303
- try {
304
- const saved = localStorage.getItem(HEAD_CTRL_KEY)
305
- if (!saved) return
306
- const input = document.querySelector(`input[name=head][value="${saved}"]`)
307
- if (input) input.checked = true
308
- } catch (error) {
309
- console.log(error)
310
- }
311
- }
312
-
313
- function persistHeadControl(id) {
314
- localStorage.setItem(HEAD_CTRL_KEY, String(id))
315
- }
316
-
317
- function restoreCameraControl() {
318
- try {
319
- const saved = localStorage.getItem(CAMERA_CTRL_KEY)
320
- if (!saved) return
321
- const input = document.querySelector(`input[name=camera][value="${saved}"]`)
322
- if (input) input.checked = true
323
- } catch (error) {
324
- console.log(error)
325
- }
326
- }
327
-
328
- function persistCameraControl(id) {
329
- localStorage.setItem(CAMERA_CTRL_KEY, String(id))
330
- }
331
241
 
332
242
  function syncLightsFromControls() {
333
243
  document.querySelectorAll('input.light-ctrl').forEach((input) => {
334
244
  const light = lights[input.name]
335
245
  if (light) light.visible = input.checked
336
246
  })
337
- persistLightControls()
338
247
  }
339
248
 
340
249
  function sync_shadows() {
@@ -358,36 +267,33 @@ function update_walk(this_head, dt) {
358
267
  this_head.armature.position.addScaledVector(dir, this_head.speed * dt / 1000)
359
268
  }
360
269
 
361
- // function play_animation(config) {
362
- // logg(config, 'my play_animation()')
363
- // let this_head = heads_fn()[config.avatar_id]
364
- // if (this_head) this_head.playAnimation(geastures[config.animation_name](config))
365
- // }
270
+ function play_animation(props) {
271
+ logg(props, 'play_animation()')
272
+ let this_head = avatars[props.spot_id]
273
+ if (this_head) this_head.playAnimation(geastures[props.animation_name](props))
274
+ }
366
275
 
367
276
  function cut_to(key) {
368
- const radio = document.querySelector(`input[name=camera][value="${key}"]`)
277
+ const radio = document.querySelector(`input[name=active_camera][value="${key}"]`)
369
278
  if (radio) radio.checked = true
370
279
  setActiveCamera(key, true)
371
280
  }
372
281
 
373
- function move_camera(config) {
374
- const fromKey = String(config.from)
375
- const toKey = String(config.to)
376
- const duration = Number(config.duration) > 0 ? Number(config.duration) : CAMERA_BLEND_MS
377
- const src = cameras_fn(fromKey)
378
- const dest = cameras_fn(toKey)
282
+ function move_camera(props) {
283
+ const fromKey = String(props.from)
284
+ const toKey = String(props.to)
285
+ const duration = Number(props.duration) > 0 ? Number(props.duration) : CAMERA_BLEND_MS
286
+ const src = cameras[fromKey].cam
287
+ const dest = cameras[toKey].cam
379
288
  const startTarget = (cameraTargets[fromKey] || cameraTargets.wide).clone()
380
289
  const destTarget = (cameraTargets[toKey] || cameraTargets.wide).clone()
381
290
 
382
- persistCameraControl(toKey)
383
291
  const radio = document.querySelector(`input[name=camera][value="${toKey}"]`)
384
292
  if (radio) radio.checked = true
385
293
 
386
- ;[camera_wide, camera_1, camera_2, camera_3, camera].forEach((cam) => {
387
- if (cam) {
388
- cam.aspect = width / height
389
- cam.updateProjectionMatrix()
390
- }
294
+ Object.entries(cameras).forEach(([key, value]) => {
295
+ value.cam.aspect = width / height
296
+ value.cam.updateProjectionMatrix()
391
297
  })
392
298
 
393
299
  src.updateMatrixWorld()
@@ -419,7 +325,7 @@ function move_camera(config) {
419
325
  }
420
326
  }
421
327
 
422
- // window.play_animation = play_animation
328
+ window.play_animation = play_animation
423
329
  window.move_camera = move_camera
424
330
  window.cut_to = cut_to
425
331
 
@@ -434,14 +340,24 @@ function tickEvents(elapsedMs) {
434
340
  }
435
341
  }
436
342
 
437
-
343
+ let studio
344
+ async function load_studio(cfg) {
345
+ logg(cfg, 'load_studio()')
346
+ if (studio && studio.parent) studio.parent.remove(studio)
347
+ studio = (await gltfLoader.loadAsync(`${cfg.path}/scene.glb`)).scene
348
+ rescale(studio, { height: cfg.height })
349
+ set_shadows(studio, false, true)
350
+ scene.add(studio)
351
+ }
438
352
 
439
353
  /*
440
354
  **/
441
355
  async function init() {
356
+ logg(null, 'init()')
357
+
442
358
  if (newspartial_id) {
443
359
  try {
444
- const url = wco_origin + '/wco/api/newspartials/' + newspartial_id + '/config.json?api_key=' + api_key + '&api_secret=' + api_secret
360
+ const url = 'https://' + wco_origin + '/wco/api/newspartials/' + newspartial_id + '/config.json?api_key=' + api_key + '&api_secret=' + api_secret
445
361
  chunkedInput = await fetch(url).then(r => r.json())
446
362
  logg(chunkedInput, 'chunkedInput')
447
363
 
@@ -457,6 +373,19 @@ async function init() {
457
373
  totalFrames = undefined
458
374
  }
459
375
  }
376
+ if (chunkedInput.studio) {
377
+ $(`select.${STUDIO_STOR}`).val(chunkedInput.studio)
378
+ load_studio(studios_config[chunkedInput.studio])
379
+ }
380
+ if (chunkedInput.spot_1) {
381
+ $('select.avatars[data-spot_id="spot_1"]').val(chunkedInput.spot_1)
382
+ }
383
+ if (chunkedInput.spot_2) {
384
+ $('select.avatars[data-spot_id="spot_2"]').val(chunkedInput.spot_2)
385
+ }
386
+ if (chunkedInput.spot_3) {
387
+ $('select.avatars[data-spot_id="spot_3"]').val(chunkedInput.spot_3)
388
+ }
460
389
 
461
390
  scene = new THREE.Scene()
462
391
  scene.background = new THREE.Color(0x333333) // new THREE.Color(0xd3d3d3)
@@ -466,6 +395,8 @@ async function init() {
466
395
  * near — Camera frustum near plane.
467
396
  * far — Camera frustum far plane.
468
397
  **/
398
+ let camera_1, camera_2, camera_3, camera_wide
399
+
469
400
  camera_1 = new THREE.PerspectiveCamera( 10, width/height, 0.1, 1000 )
470
401
  camera_1.position.set( 0, 1.6, 4 )
471
402
  camera_1.lookAt( 0, 1.5, 0 )
@@ -482,11 +413,16 @@ async function init() {
482
413
  camera_wide.position.set( -2, 2.2, 8 )
483
414
  camera_wide.lookAt( 0.5, 1.2, 0 )
484
415
 
485
- camera = new THREE.PerspectiveCamera( 10, width/height, 0.1, 1000 )
486
- camera.position.copy( camera_wide.position )
487
- camera.quaternion.copy( camera_wide.quaternion )
488
- camera.fov = camera_wide.fov
489
- camera.updateProjectionMatrix()
416
+ cameras.wide.cam = camera_wide
417
+ cameras.spot_1.cam = camera_1
418
+ cameras.spot_2.cam = camera_2
419
+ cameras.spot_3.cam = camera_3
420
+
421
+ active_camera = new THREE.PerspectiveCamera( 10, width/height, 0.1, 1000 )
422
+ active_camera.position.copy( camera_wide.position )
423
+ active_camera.quaternion.copy( camera_wide.quaternion )
424
+ active_camera.fov = camera_wide.fov
425
+ active_camera.updateProjectionMatrix()
490
426
 
491
427
  setup_light(scene)
492
428
 
@@ -494,22 +430,12 @@ async function init() {
494
430
  grid.position.y = 0
495
431
  scene.add(grid)
496
432
 
497
-
498
- let studio
499
- async function load_studio(s) {
500
- const cfg = scene_cfg(s)
501
- if (studio && studio.parent) studio.parent.remove(studio)
502
- studio = (await gltfLoader.loadAsync(cfg.url)).scene
503
- rescale(studio, { height: cfg.height })
504
- set_shadows(studio, false, true)
505
- scene.add(studio)
506
- }
507
433
  await load_studio(scene_url)
508
- $('select.studio').on('change', async function() {
434
+ $(`select.${STUDIO_STOR}`).on('change', async function() {
509
435
  const name = $(this).val()
510
- if (!scenes[name]) return
511
- localStorage.setItem(SCENE_STOR, name)
512
- scene_url = scenes[name]
436
+ if (!studios_config[name]) return
437
+ localStorage.setItem(STUDIO_STOR, name)
438
+ scene_url = studios_config[name]
513
439
  loading.textContent = 'Loading...'
514
440
  try {
515
441
  await load_studio(scene_url)
@@ -521,13 +447,7 @@ async function init() {
521
447
  })
522
448
 
523
449
 
524
- // head = new TalkingHead( document.getElementById('avatar'), {
525
- // avatarOnly: true,
526
- // avatarOnlyScene: scene,
527
- // avatarOnlyCamera: camera,
528
- // lipsyncModules: ["en"],
529
- // dracoEnabled: true,
530
- // })
450
+ let head_1, head_2, head_3
531
451
  head_1 = new TalkingHead( document.getElementById('avatar_1'), {
532
452
  avatarOnly: true,
533
453
  avatarOnlyScene: scene,
@@ -549,47 +469,47 @@ async function init() {
549
469
  lipsyncModules: ["en"],
550
470
  dracoEnabled: true,
551
471
  })
472
+ avatars.spot_1 = head_1
473
+ avatars.spot_2 = head_2
474
+ avatars.spot_3 = head_3
552
475
 
553
476
 
554
-
555
-
556
- $('select.avatar').on('change', async function() {
557
- const uid = String($(this).data('uid'))
558
- const thisHead = heads_fn(uid)
559
- const val = $(this).val()
560
- localStorage.setItem(`${AVATAR_STOR}-${uid}`, val || '')
561
- if (!thisHead) return
562
- if (thisHead.armature && thisHead.armature.parent) thisHead.armature.parent.remove(thisHead.armature)
563
- const avatar = avatars[val]
564
- if (!avatar || !avatar.url) return
477
+ $('select.avatars').on('change', async function() {
478
+ const spot_id = $(this).data('spot_id')
479
+ const name = $(this).val()
480
+ if (!name) return; // empty spot
481
+ const thisAvatar = avatars[spot_id]
482
+ localStorage.setItem(`${AVATAR_STOR}-${spot_id}`, name)
483
+ if (!thisAvatar) return
484
+ if (thisAvatar.armature && thisAvatar.armature.parent) thisAvatar.armature.parent.remove(thisAvatar.armature)
485
+ const avatar_config = avatars_config[name]
565
486
  loading.textContent = 'Loading...'
566
487
  try {
567
- if (thisHead.armature && thisHead.armature.parent) thisHead.armature.parent.remove(thisHead.armature)
568
- await thisHead.showAvatar({
569
- url: avatar.url,
570
- body: avatar.type,
488
+ await thisAvatar.showAvatar({
489
+ url: avatar_config.url,
490
+ body: avatar_config.type,
571
491
  avatarMood: 'neutral',
572
492
  lipsyncLang: 'en'
573
493
  }, (ev) => {
574
494
  if ( ev.lengthComputable ) {
575
- let val = Math.min(100,Math.round(ev.loaded/ev.total * 100 ))
576
- loading.textContent = "Loading " + val + "%"
495
+ let percent = Math.min(100,Math.round(ev.loaded/ev.total * 100 ))
496
+ loading.textContent = `Loading ${percent}%`
577
497
  }
578
498
  })
579
- thisHead.armature.rotation.set(0, 0, 0)
580
- set_shadows(thisHead.armature, true, false)
581
- scene.add(thisHead.armature)
582
- put_feet_at_origin(thisHead)
583
- thisHead.armature.position.add(new THREE.Vector3(...u_positions[uid]))
584
- point_camera_at_face(`av_${uid}`, thisHead)
585
- await thisHead.streamStart(streamOpts, () => {}, () => {}, onSubtitles, onMetrics)
499
+ thisAvatar.armature.rotation.set(0, 0, 0)
500
+ set_shadows(thisAvatar.armature, true, false)
501
+ scene.add(thisAvatar.armature)
502
+ put_feet_at_origin(thisAvatar)
503
+ thisAvatar.armature.position.add(new THREE.Vector3(...spot_positions[spot_id]))
504
+ point_camera_at_face(spot_id, thisAvatar)
505
+ await thisAvatar.streamStart(streamOpts, () => {}, () => {}, onSubtitles)
586
506
  loading.textContent = 'loaded'
587
507
  } catch (error) {
588
508
  console.log(error)
589
509
  loading.textContent = error.toString()
590
510
  }
591
511
  })
592
- $('select.avatar').trigger('change')
512
+ $('select.avatars').trigger('change')
593
513
 
594
514
 
595
515
 
@@ -611,7 +531,7 @@ async function init() {
611
531
 
612
532
  //
613
533
 
614
- controls = new OrbitControls( camera, renderer.domElement )
534
+ controls = new OrbitControls( active_camera, renderer.domElement )
615
535
  controls.enableDamping = true
616
536
  controls.enableRotate = true
617
537
  controls.enablePan = true
@@ -622,25 +542,31 @@ async function init() {
622
542
  controls.autoRotate = false
623
543
  controls.update()
624
544
 
625
- restoreHeadControl()
626
- document.querySelectorAll('input[name=head]').forEach((input) => {
545
+ document.querySelectorAll('input[name=active_spot]').forEach((input) => {
627
546
  input.addEventListener('change', () => {
628
547
  if (!input.checked) return
629
- setActiveHead(input.value)
548
+ active_avatar = avatars[input.value]
630
549
  })
550
+ if (chunkedInput.active_spot && input.value === chunkedInput.active_spot) {
551
+ input.checked = true
552
+ }
631
553
  })
632
- const selectedHead = document.querySelector('input[name=head]:checked')
633
- setActiveHead(selectedHead ? selectedHead.value : '1')
554
+ const active_spot = document.querySelector('input[name=active_spot]:checked')
555
+ if (active_spot) {
556
+ active_avatar = avatars[active_spot.value]
557
+ }
634
558
 
635
- restoreCameraControl()
636
- document.querySelectorAll('input[name=camera]').forEach((input) => {
559
+ document.querySelectorAll('input[name=active_camera]').forEach((input) => {
637
560
  input.addEventListener('change', () => {
638
561
  if (!input.checked) return
639
562
  setActiveCamera(input.value)
640
563
  })
564
+ if (chunkedInput.active_camera && input.value === chunkedInput.active_camera) {
565
+ input.checked = true
566
+ }
641
567
  })
642
- const selected = document.querySelector('input[name=camera]:checked')
643
- setActiveCamera(selected ? selected.value : 'wide', true)
568
+ const selected = document.querySelector('input[name=active_camera]:checked')
569
+ if (selected.value) setActiveCamera(selected.value, true)
644
570
 
645
571
  document.querySelectorAll('input.light-ctrl').forEach((input) => {
646
572
  input.addEventListener('change', syncLightsFromControls)
@@ -659,6 +585,7 @@ async function init() {
659
585
  renderer.setAnimationLoop(animate)
660
586
  }
661
587
 
588
+ /*
662
589
  let semafore = false
663
590
  document.addEventListener('DOMContentLoaded', async function(e) {
664
591
  if (!semafore) {
@@ -666,73 +593,38 @@ document.addEventListener('DOMContentLoaded', async function(e) {
666
593
  await init()
667
594
  }
668
595
  })
669
-
670
- function cameras_fn(which) {
671
- switch (which) {
672
- case 'wide':
673
- return camera_wide
674
- case 'av_1':
675
- return camera_1
676
- case 'av_2':
677
- return camera_2
678
- case 'av_3':
679
- return camera_3
680
- default:
681
- logg('fpq - cameras_fn default - this should never happen')
682
- return camera_wide
683
- }
596
+ */
597
+ if (document.readyState === 'loading') {
598
+ document.addEventListener('DOMContentLoaded', init)
599
+ } else {
600
+ init()
684
601
  }
685
602
 
686
- function heads_fn(which) {
687
- switch (which) {
688
- case '1':
689
- return head_1
690
- break;
691
- case '2':
692
- return head_2
693
- break;
694
- case '3':
695
- return head_3
696
- break;
697
- default:
698
- logg('fpp - heads_fn default - this should never happen')
699
- return head_1
700
- }
701
- }
702
-
703
- function setActiveHead(id) {
704
- head = heads_fn(id)
705
- persistHeadControl(id)
706
- }
707
603
 
708
604
  function easeInOutCubic(t) {
709
605
  return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2
710
606
  }
711
607
 
712
- function setActiveCamera(id, instant = false) {
713
- const key = String(id)
714
- persistCameraControl(key)
715
- const dest = cameras_fn(key)
716
- const destTarget = (cameraTargets[key] || cameraTargets.wide).clone()
717
- ;[camera_wide, camera_1, camera_2, camera_3, camera].forEach((cam) => {
718
- if (cam) {
719
- cam.aspect = width / height
720
- cam.updateProjectionMatrix()
721
- }
722
- })
608
+ function setActiveCamera(key, instant = false) {
609
+ const dest = cameras[key].cam
610
+ const destTarget = cameras[key].tgt.clone()
723
611
 
612
+ Object.entries(cameras).forEach(([key, value]) => {
613
+ value.cam.aspect = width / height
614
+ value.cam.updateProjectionMatrix()
615
+ })
724
616
  dest.updateMatrixWorld()
725
617
 
726
- const endPos = dest.position.clone()
618
+ const endPos = dest.position.clone()
727
619
  const endQuat = dest.quaternion.clone()
728
620
 
729
621
  if (instant || !controls) {
730
- camera.position.copy(endPos)
731
- camera.quaternion.copy(endQuat)
732
- camera.fov = dest.fov
733
- camera.near = dest.near
734
- camera.far = dest.far
735
- camera.updateProjectionMatrix()
622
+ active_camera.position.copy(endPos)
623
+ active_camera.quaternion.copy(endQuat)
624
+ active_camera.fov = dest.fov
625
+ active_camera.near = dest.near
626
+ active_camera.far = dest.far
627
+ active_camera.updateProjectionMatrix()
736
628
  faceTarget.copy(destTarget)
737
629
  if (controls) {
738
630
  controls.target.copy(destTarget)
@@ -743,9 +635,9 @@ function setActiveCamera(id, instant = false) {
743
635
  }
744
636
 
745
637
  cameraTransition = {
746
- startPos: camera.position.clone(),
747
- startQuat: camera.quaternion.clone(),
748
- startFov: camera.fov,
638
+ startPos: active_camera.position.clone(),
639
+ startQuat: active_camera.quaternion.clone(),
640
+ startFov: active_camera.fov,
749
641
  startTarget: controls.target.clone(),
750
642
  endPos: endPos,
751
643
  endQuat: endQuat,
@@ -763,10 +655,10 @@ function updateCameraTransition(dt) {
763
655
  const u = Math.min(1, cameraTransition.elapsed / cameraTransition.duration)
764
656
  const e = easeInOutCubic(u)
765
657
  const tr = cameraTransition
766
- camera.position.lerpVectors(tr.startPos, tr.endPos, e)
767
- camera.quaternion.slerpQuaternions(tr.startQuat, tr.endQuat, e)
768
- camera.fov = tr.startFov + (tr.endFov - tr.startFov) * e
769
- camera.updateProjectionMatrix()
658
+ active_camera.position.lerpVectors(tr.startPos, tr.endPos, e)
659
+ active_camera.quaternion.slerpQuaternions(tr.startQuat, tr.endQuat, e)
660
+ active_camera.fov = tr.startFov + (tr.endFov - tr.startFov) * e
661
+ active_camera.updateProjectionMatrix()
770
662
  if (controls) {
771
663
  controls.target.lerpVectors(tr.startTarget, tr.endTarget, e)
772
664
  faceTarget.copy(controls.target)
@@ -783,18 +675,16 @@ function updateCameraTransition(dt) {
783
675
  }
784
676
 
785
677
  function onWindowResize() {
786
- ;[camera_wide, camera_1, camera_2, camera_3].forEach((cam) => {
787
- if (cam) {
788
- cam.aspect = width / height
789
- cam.updateProjectionMatrix()
790
- }
678
+ Object.entries(cameras).forEach(([key, value]) => {
679
+ value.cam.aspect = width / height
680
+ value.cam.updateProjectionMatrix()
791
681
  })
792
682
  renderer.setSize( width, height )
793
683
  render()
794
684
  }
795
685
 
796
686
  function render() {
797
- renderer.render( scene, camera )
687
+ renderer.render( scene, active_camera )
798
688
  }
799
689
 
800
690
  function animate() {
@@ -810,15 +700,13 @@ function animate() {
810
700
 
811
701
  if (capturing) tickEvents(captureFrame * dt)
812
702
 
813
- if (head_1) head_1.animate(dt)
814
- if (head_2) head_2.animate(dt)
815
- if (head_3) head_3.animate(dt)
816
- update_walk(head_1, dt)
817
- update_walk(head_2, dt)
818
- update_walk(head_3, dt)
703
+ Object.entries(avatars).forEach(([name, _avatar]) => {
704
+ _avatar.animate(dt)
705
+ update_walk(_avatar, dt)
706
+ })
819
707
  updateCameraTransition(dt)
820
708
  if (!cameraTransition && !capturing) controls.update()
821
- renderer.render( scene, camera )
709
+ renderer.render( scene, active_camera )
822
710
 
823
711
  if (capturing) {
824
712
  capturer.capture( renderer.domElement )
@@ -831,8 +719,9 @@ function animate() {
831
719
 
832
720
  async function startSpeakCapture() {
833
721
  if (capturing) return
834
- if (!head) return
722
+ if (!active_avatar) return
835
723
  if (!chunkedInput) return
724
+ logg(null, 'startSpeakCapture()')
836
725
 
837
726
  const last = chunkedInput.wtimes.length - 1
838
727
  const duration_ms = chunkedInput.wtimes[last] + chunkedInput.wdurations[last]
@@ -847,7 +736,7 @@ async function startSpeakCapture() {
847
736
  capturer.start()
848
737
  logg('capturer.start')
849
738
  status.textContent = 'capturing'
850
- head.streamAudio(chunkedInput)
739
+ active_avatar.streamAudio(chunkedInput)
851
740
  }
852
741
 
853
742
  function finishCapture() {
@@ -867,9 +756,8 @@ function finishCapture() {
867
756
  form.append('thumb', thumb)
868
757
  if (newspartial_id) form.append('newspartial_id', newspartial_id)
869
758
 
870
- const url = wco_origin
871
- ? (wco_origin + '/wco/api/videos/?api_key=' + api_key + '&api_secret=' + api_secret)
872
- : '/wco/api/videos/'
759
+ const url = 'https://' + wco_origin + '/wco/api/videos/?api_key=' + api_key + '&api_secret=' + api_secret
760
+
873
761
  fetch(url, {
874
762
  method: 'POST',
875
763
  body: form,
@@ -898,15 +786,15 @@ $('#speak').on('click', async () => {
898
786
 
899
787
  $('#jesture').on('click', async () => {
900
788
  try {
901
- if (!head) return
789
+ if (!active_avatar) return
902
790
  const name = $('select.gestures').val()
903
791
  const g = gestures[name]
904
- const _anim = gesture_url(g, head.avatar)
905
- head.speed = (g && typeof g === 'object' && g.speed) ? g.speed : 0
906
- head.playAnimation( _anim )
792
+ const _anim = gesture_url(g, active_avatar.avatar)
793
+ active_avatar.speed = (g && typeof g === 'object' && g.speed) ? g.speed : 0
794
+ active_avatar.playAnimation( _anim )
907
795
  } catch (error) {
908
796
  console.log(error)
909
797
  }
910
798
  })
911
799
 
912
- console.log('+++ loaded wco_models :: newsproducer :: studio_blue.js')
800
+ console.log('+++ loaded wco_models :: newsproducer :: studio_blue2.js')