wco_models 3.1.0.328 → 3.4.0.3
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.
- checksums.yaml +4 -4
- data/app/controllers/wco/api/newspartials_controller.rb +0 -9
- data/app/controllers/wco/newsvideos_controller.rb +6 -12
- data/app/models/iro/option.rb +1 -1
- data/app/models/wco/newspartial.rb +2 -12
- data/app/models/wco/setting.rb +1 -1
- data/app/views/wco/api/newsproducer/README_newsproducer.txt +12 -0
- data/app/views/wco/api/newsproducer/_studio_blue2.js +37 -16
- data/app/views/wco/api/newsproducer/_studio_fps.js +12 -12
- data/app/views/wco/api/newsproducer/studio_fps.html.erb +10 -8
- data/app/views/wco/api/newsvideos/show.jbuilder +1 -1
- data/app/views/wco/newsvideos/show.haml +2 -2
- data/config/routes.rb +10 -11
- data/lib/shortcuts.rb +1 -1
- metadata +22 -29
- data/app/models/wco/site.rb-trash +0 -65
- data/app/views/wco/api/newsproducer/trash/_scenes.js-bk +0 -20
- data/app/views/wco/api/newsproducer/trash/_scenes.js.erb +0 -15
- data/app/views/wco/api/newsproducer/trash/_studio_blue0.js +0 -326
- data/app/views/wco/api/newsproducer/trash/_studio_blue1.js +0 -733
- data/app/views/wco/api/newsproducer/trash/studio_blue0.html.erb +0 -27
- data/app/views/wco/api/newsproducer/trash/studio_blue1.html.erb +0 -108
- data/app/views/wco/sitemap_paths/check.haml-trash +0 -13
- /data/app/views/wco/api/newsproducer/{done/_scenes.js-bk → _scenes.js-bk} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_scenes.js.erb → _scenes.js.erb} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_studio_1.js → _studio_1.js} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_studio_blue0.js → _studio_blue0.js} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_studio_blue1.js → _studio_blue1.js} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_studio_coc.js → _studio_coc.js} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_studio_coc.js-bk → _studio_coc.js-bk} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_studio_coc.js-cannon → _studio_coc.js-cannon} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_studio_ra2.js → _studio_ra2.js} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_touch_controls.js → _touch_controls.js} +0 -0
- /data/app/views/wco/api/newsproducer/{done/_touch_pad.css → _touch_pad.css} +0 -0
- /data/app/views/wco/api/newsproducer/{done/canvas.html.erb → canvas.html.erb} +0 -0
- /data/app/views/wco/api/newsproducer/{done/canvas_minimal.html.erb → canvas_minimal.html.erb} +0 -0
- /data/app/views/wco/api/newsproducer/{done/games_fps.html → games_fps.html} +0 -0
- /data/app/views/wco/api/newsproducer/{done/studio_1.html.erb → studio_1.html.erb} +0 -0
- /data/app/views/wco/api/newsproducer/{done/studio_blue0.html.erb → studio_blue0.html.erb} +0 -0
- /data/app/views/wco/api/newsproducer/{done/studio_blue1.html.erb → studio_blue1.html.erb} +0 -0
- /data/app/views/wco/api/newsproducer/{done/studio_coc.html.erb → studio_coc.html.erb} +0 -0
- /data/app/views/wco/api/newsproducer/{done/studio_ra2.html.erb → studio_ra2.html.erb} +0 -0
|
@@ -1,733 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/*
|
|
3
|
-
**/
|
|
4
|
-
const logg = (a, b="", c=null) => {
|
|
5
|
-
if ('undefined' === typeof window) { return }
|
|
6
|
-
c = "string" === typeof c ? c : b.replace(/\W/g, '')
|
|
7
|
-
if (c.length > 0) {
|
|
8
|
-
window[c] = a
|
|
9
|
-
}
|
|
10
|
-
console.log(`+++ ${b}:`, a) // eslint-disable-line no-console
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let avatar_brunette_url = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.2.0/public/vendor/models/avatars/brunette/model.glb'
|
|
14
|
-
let avatar_avaturn_url = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.2.0/public/vendor/models/avatars/avaturn/model.glb'
|
|
15
|
-
// cute short-haired girl
|
|
16
|
-
let avatar_45_url = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.2.0/public/vendor/models/avatars/extra/45.glb'
|
|
17
|
-
let avatar_mula_url = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.2.0/public/vendor/models/avatars/mula/model.glb'
|
|
18
|
-
// works! male-x, buddy-y. Yes, it took me like 3 days to find a single good male avatar.
|
|
19
|
-
let avatar_male_url = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.2.0/public/vendor/models/avatars/buddy-y/model.glb'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let scene_url = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.2.0/public/vendor/models/scenes/001mb newsroom_green/scene.glb'
|
|
23
|
-
|
|
24
|
-
// let wave_url = "https://cdn.jsdelivr.net/gh/met4citizen/TalkingHead@main/animations/walking.fbx"
|
|
25
|
-
// let wave_url = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.2.0/public/vendor/models/animations/F_Crouch_Strafe_Left.fbx'
|
|
26
|
-
let wave_url = 'https://wco-drupal-prod.s3.amazonaws.com/public/2026-08/F_Talking_Variations_004.fbx'
|
|
27
|
-
// let wave_url = 'https://cdn.jsdelivr.net/gh/wasya-co/ishlib3js@0.2.0/public/vendor/models/animations/catwalk.fbx'
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let avatar_1_url = avatar_brunette_url
|
|
31
|
-
let avatar_2_url = avatar_male_url
|
|
32
|
-
// let avatar_3_url = avatar_mula_url
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
import * as THREE from 'three'
|
|
37
|
-
|
|
38
|
-
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
|
|
39
|
-
import { FBXLoader } from 'three/addons/loaders/FBXLoader.js'
|
|
40
|
-
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
|
|
41
|
-
|
|
42
|
-
import { TalkingHead } from "talkinghead"
|
|
43
|
-
|
|
44
|
-
const params = new URLSearchParams(window.location.search)
|
|
45
|
-
|
|
46
|
-
let config = {
|
|
47
|
-
sampleRate: 8000,
|
|
48
|
-
mood: 'neutral',
|
|
49
|
-
gain: 0.5,
|
|
50
|
-
lipsyncType: "visemes",
|
|
51
|
-
lipsyncLang: "en",
|
|
52
|
-
waitForAudioChunks: false,
|
|
53
|
-
enableMetrics: false,
|
|
54
|
-
}
|
|
55
|
-
let width = 854
|
|
56
|
-
let height = 480
|
|
57
|
-
let slug = '<ccapture>'
|
|
58
|
-
const fps = 24
|
|
59
|
-
|
|
60
|
-
let frame = 0
|
|
61
|
-
let lastAnimTime = 0
|
|
62
|
-
let capturing = false
|
|
63
|
-
let captureFrame = 0
|
|
64
|
-
let captureTotal = 0
|
|
65
|
-
const api_key = params.get('api_key')
|
|
66
|
-
const api_secret = params.get('api_secret')
|
|
67
|
-
const wco_origin = params.get('wco_origin')
|
|
68
|
-
const newspartial_id = params.get('newspartial_id')
|
|
69
|
-
let totalFrames
|
|
70
|
-
|
|
71
|
-
let camera, camera_1, camera_2, camera_3
|
|
72
|
-
let controls, renderer, scene
|
|
73
|
-
let head, head_1, head_2, head_3
|
|
74
|
-
let faceTarget = new THREE.Vector3()
|
|
75
|
-
const cameraTargets = {
|
|
76
|
-
'1': new THREE.Vector3(0, 1.5, 0),
|
|
77
|
-
'2': new THREE.Vector3(1, 1.5, 0),
|
|
78
|
-
'3': new THREE.Vector3(0.5, 1.2, 0),
|
|
79
|
-
}
|
|
80
|
-
let cameraTransition = null
|
|
81
|
-
const CAMERA_BLEND_MS = 900
|
|
82
|
-
let chunkedInput = null
|
|
83
|
-
const lights = {}
|
|
84
|
-
const LIGHT_CTRL_KEY = 'wco.studio_blue.light-ctrl'
|
|
85
|
-
const HEAD_CTRL_KEY = 'wco.studio_blue.head-ctrl'
|
|
86
|
-
const CAMERA_CTRL_KEY = 'wco.studio_blue.camera-ctrl'
|
|
87
|
-
var capturer = new CCapture( { format: 'webm', framerate: fps } )
|
|
88
|
-
const gltfLoader = new GLTFLoader()
|
|
89
|
-
const fbxLoader = new FBXLoader()
|
|
90
|
-
const loading = document.getElementById('loading')
|
|
91
|
-
|
|
92
|
-
/*
|
|
93
|
-
**/
|
|
94
|
-
function point_camera_at_face(_camera, _head, targetKey) {
|
|
95
|
-
const leftEye = new THREE.Vector3()
|
|
96
|
-
const rightEye = new THREE.Vector3()
|
|
97
|
-
_head.objectLeftEye.getWorldPosition(leftEye)
|
|
98
|
-
_head.objectRightEye.getWorldPosition(rightEye)
|
|
99
|
-
faceTarget.copy(leftEye).add(rightEye).multiplyScalar(0.5)
|
|
100
|
-
|
|
101
|
-
const camPos = new THREE.Vector3(0, 0, 2)
|
|
102
|
-
camPos.applyQuaternion(_head.armature.quaternion)
|
|
103
|
-
camPos.add(faceTarget)
|
|
104
|
-
_camera.position.copy(camPos)
|
|
105
|
-
_camera.lookAt(faceTarget)
|
|
106
|
-
if (targetKey) cameraTargets[targetKey].copy(faceTarget)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/*
|
|
110
|
-
**/
|
|
111
|
-
function put_feet_at_origin(_head) {
|
|
112
|
-
// Put feet at the origin
|
|
113
|
-
_head.armature.updateMatrixWorld(true)
|
|
114
|
-
const leftToe = new THREE.Vector3()
|
|
115
|
-
const rightToe = new THREE.Vector3()
|
|
116
|
-
_head.objectLeftToeBase.getWorldPosition(leftToe)
|
|
117
|
-
_head.objectRightToeBase.getWorldPosition(rightToe)
|
|
118
|
-
_head.armature.position.set(
|
|
119
|
-
-(leftToe.x + rightToe.x) / 2,
|
|
120
|
-
-Math.min(leftToe.y, rightToe.y),
|
|
121
|
-
-(leftToe.z + rightToe.z) / 2
|
|
122
|
-
)
|
|
123
|
-
_head.armature.updateMatrixWorld(true)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/*
|
|
127
|
-
**/
|
|
128
|
-
function rescale(model, config) {
|
|
129
|
-
const box = new THREE.Box3().setFromObject(model)
|
|
130
|
-
const size = box.getSize(new THREE.Vector3())
|
|
131
|
-
const currentHeight = size.y
|
|
132
|
-
const scale = config.height / currentHeight
|
|
133
|
-
model.scale.setScalar(scale)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/*
|
|
137
|
-
**/
|
|
138
|
-
function setup_light(scene) {
|
|
139
|
-
lights.ambientLight = new THREE.AmbientLight( 0xffffff, 0.6 )
|
|
140
|
-
scene.add( lights.ambientLight )
|
|
141
|
-
|
|
142
|
-
lights.hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444, 1.2 )
|
|
143
|
-
lights.hemiLight.position.set( 0, 20, 0 )
|
|
144
|
-
scene.add( lights.hemiLight )
|
|
145
|
-
|
|
146
|
-
lights.keyLight = new THREE.DirectionalLight( 0xffffff, 2.5 )
|
|
147
|
-
lights.keyLight.position.set( 5, 10, 7 )
|
|
148
|
-
scene.add( lights.keyLight )
|
|
149
|
-
|
|
150
|
-
lights.fillLight = new THREE.DirectionalLight( 0xffffff, 1.2 )
|
|
151
|
-
lights.fillLight.position.set( -5, 4, -2 )
|
|
152
|
-
scene.add( lights.fillLight )
|
|
153
|
-
|
|
154
|
-
lights.rimLight = new THREE.DirectionalLight( 0xffffff, 0.8 )
|
|
155
|
-
lights.rimLight.position.set( 0, 6, -8 )
|
|
156
|
-
scene.add( lights.rimLight )
|
|
157
|
-
|
|
158
|
-
restoreLightControls()
|
|
159
|
-
syncLightsFromControls()
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function restoreLightControls() {
|
|
163
|
-
try {
|
|
164
|
-
const saved = JSON.parse(localStorage.getItem(LIGHT_CTRL_KEY) || 'null')
|
|
165
|
-
if (!saved || typeof saved !== 'object') return
|
|
166
|
-
document.querySelectorAll('input.light-ctrl').forEach((input) => {
|
|
167
|
-
if (Object.prototype.hasOwnProperty.call(saved, input.name)) {
|
|
168
|
-
input.checked = !!saved[input.name]
|
|
169
|
-
}
|
|
170
|
-
})
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.log(error)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function persistLightControls() {
|
|
177
|
-
const saved = {}
|
|
178
|
-
document.querySelectorAll('input.light-ctrl').forEach((input) => {
|
|
179
|
-
saved[input.name] = input.checked
|
|
180
|
-
})
|
|
181
|
-
localStorage.setItem(LIGHT_CTRL_KEY, JSON.stringify(saved))
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function restoreHeadControl() {
|
|
185
|
-
try {
|
|
186
|
-
const saved = localStorage.getItem(HEAD_CTRL_KEY)
|
|
187
|
-
if (!saved) return
|
|
188
|
-
const input = document.querySelector(`input[name=head][value="${saved}"]`)
|
|
189
|
-
if (input) input.checked = true
|
|
190
|
-
} catch (error) {
|
|
191
|
-
console.log(error)
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function persistHeadControl(id) {
|
|
196
|
-
localStorage.setItem(HEAD_CTRL_KEY, String(id))
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function restoreCameraControl() {
|
|
200
|
-
try {
|
|
201
|
-
const saved = localStorage.getItem(CAMERA_CTRL_KEY)
|
|
202
|
-
if (!saved) return
|
|
203
|
-
const input = document.querySelector(`input[name=camera][value="${saved}"]`)
|
|
204
|
-
if (input) input.checked = true
|
|
205
|
-
} catch (error) {
|
|
206
|
-
console.log(error)
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function persistCameraControl(id) {
|
|
211
|
-
localStorage.setItem(CAMERA_CTRL_KEY, String(id))
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function syncLightsFromControls() {
|
|
215
|
-
document.querySelectorAll('input.light-ctrl').forEach((input) => {
|
|
216
|
-
const light = lights[input.name]
|
|
217
|
-
if (light) light.visible = input.checked
|
|
218
|
-
})
|
|
219
|
-
persistLightControls()
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const animations_h = {
|
|
223
|
-
talking_variation_4: 'https://wco-drupal-prod.s3.amazonaws.com/public/2026-08/F_Talking_Variations_004.fbx',
|
|
224
|
-
}
|
|
225
|
-
function play_animation(config) {
|
|
226
|
-
let this_head = heads()[config.avatar_id]
|
|
227
|
-
if (this_head) this_head.playAnimation(animations_h[config.animation_name])
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function move_camera(config) {
|
|
231
|
-
const fromKey = String(config.from)
|
|
232
|
-
const toKey = String(config.to)
|
|
233
|
-
const duration = Number(config.duration) > 0 ? Number(config.duration) : CAMERA_BLEND_MS
|
|
234
|
-
const src = cameras()[fromKey] || camera_1
|
|
235
|
-
const dest = cameras()[toKey] || camera_1
|
|
236
|
-
const startTarget = (cameraTargets[fromKey] || cameraTargets['1']).clone()
|
|
237
|
-
const destTarget = (cameraTargets[toKey] || cameraTargets['1']).clone()
|
|
238
|
-
|
|
239
|
-
persistCameraControl(toKey)
|
|
240
|
-
const radio = document.querySelector(`input[name=camera][value="${toKey}"]`)
|
|
241
|
-
if (radio) radio.checked = true
|
|
242
|
-
|
|
243
|
-
;[camera_1, camera_2, camera_3, camera].forEach((cam) => {
|
|
244
|
-
if (cam) {
|
|
245
|
-
cam.aspect = width / height
|
|
246
|
-
cam.updateProjectionMatrix()
|
|
247
|
-
}
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
src.updateMatrixWorld()
|
|
251
|
-
dest.updateMatrixWorld()
|
|
252
|
-
|
|
253
|
-
camera.position.copy(src.position)
|
|
254
|
-
camera.quaternion.copy(src.quaternion)
|
|
255
|
-
camera.fov = src.fov
|
|
256
|
-
camera.near = dest.near
|
|
257
|
-
camera.far = dest.far
|
|
258
|
-
camera.updateProjectionMatrix()
|
|
259
|
-
faceTarget.copy(startTarget)
|
|
260
|
-
if (controls) {
|
|
261
|
-
controls.target.copy(startTarget)
|
|
262
|
-
controls.enabled = false
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
cameraTransition = {
|
|
266
|
-
startPos: src.position.clone(),
|
|
267
|
-
startQuat: src.quaternion.clone(),
|
|
268
|
-
startFov: src.fov,
|
|
269
|
-
startTarget: startTarget,
|
|
270
|
-
endPos: dest.position.clone(),
|
|
271
|
-
endQuat: dest.quaternion.clone(),
|
|
272
|
-
endFov: dest.fov,
|
|
273
|
-
endTarget: destTarget,
|
|
274
|
-
elapsed: 0,
|
|
275
|
-
duration: duration,
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
window.play_animation = play_animation
|
|
280
|
-
window.move_camera = move_camera
|
|
281
|
-
|
|
282
|
-
let eventsIndex = 0
|
|
283
|
-
function tickEvents(elapsedMs) {
|
|
284
|
-
if (!chunkedInput || !chunkedInput.ftimes || !chunkedInput.fns) return
|
|
285
|
-
while (eventsIndex < chunkedInput.ftimes.length && elapsedMs >= chunkedInput.ftimes[eventsIndex]) {
|
|
286
|
-
const fn = chunkedInput.fns[eventsIndex]
|
|
287
|
-
logg(fn, 'fn')
|
|
288
|
-
eventsIndex++
|
|
289
|
-
eval(fn)
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
/*
|
|
296
|
-
**/
|
|
297
|
-
async function init() {
|
|
298
|
-
if (newspartial_id) {
|
|
299
|
-
try {
|
|
300
|
-
const url = wco_origin + '/wco/api/newspartials/' + newspartial_id + '/config.json?api_key=' + api_key + '&api_secret=' + api_secret
|
|
301
|
-
chunkedInput = await fetch(url).then(r => r.json())
|
|
302
|
-
logg(chunkedInput, 'chunkedInput')
|
|
303
|
-
|
|
304
|
-
const last = chunkedInput.wtimes.length-1
|
|
305
|
-
const duration_ms = chunkedInput.wtimes[last] + chunkedInput.wdurations[last]
|
|
306
|
-
totalFrames = duration_ms/1000*fps
|
|
307
|
-
width = chunkedInput.w_px
|
|
308
|
-
height = chunkedInput.h_px
|
|
309
|
-
slug = chunkedInput.slug
|
|
310
|
-
} catch (error) {
|
|
311
|
-
console.log(error)
|
|
312
|
-
chunkedInput = null
|
|
313
|
-
totalFrames = undefined
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
scene = new THREE.Scene()
|
|
318
|
-
scene.background = new THREE.Color(0xd3d3d3)
|
|
319
|
-
|
|
320
|
-
/* fov — Camera frustum vertical field of view.
|
|
321
|
-
* aspect — Camera frustum aspect ratio.
|
|
322
|
-
* near — Camera frustum near plane.
|
|
323
|
-
* far — Camera frustum far plane.
|
|
324
|
-
**/
|
|
325
|
-
camera_1 = new THREE.PerspectiveCamera( 10, width/height, 0.1, 1000 )
|
|
326
|
-
camera_1.position.set( 0, 1.6, 4 )
|
|
327
|
-
camera_1.lookAt( 0, 1.5, 0 )
|
|
328
|
-
|
|
329
|
-
camera_2 = new THREE.PerspectiveCamera( 10, width/height, 0.1, 1000 )
|
|
330
|
-
camera_2.position.set( 2, 1.6, 4 )
|
|
331
|
-
camera_2.lookAt( 1, 1.5, 0 )
|
|
332
|
-
|
|
333
|
-
camera_3 = new THREE.PerspectiveCamera( 25, width/height, 0.1, 1000 )
|
|
334
|
-
camera_3.position.set( -2, 2.2, 8 )
|
|
335
|
-
camera_3.lookAt( 0.5, 1.2, 0 )
|
|
336
|
-
|
|
337
|
-
camera = new THREE.PerspectiveCamera( 10, width/height, 0.1, 1000 )
|
|
338
|
-
camera.position.copy( camera_1.position )
|
|
339
|
-
camera.quaternion.copy( camera_1.quaternion )
|
|
340
|
-
camera.fov = camera_1.fov
|
|
341
|
-
camera.updateProjectionMatrix()
|
|
342
|
-
|
|
343
|
-
setup_light(scene)
|
|
344
|
-
|
|
345
|
-
const grid = new THREE.GridHelper(10, 10, 0x888888, 0xbbbbbb)
|
|
346
|
-
grid.position.y = 0
|
|
347
|
-
scene.add(grid)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const studio = (await gltfLoader.loadAsync(scene_url)).scene
|
|
351
|
-
rescale(studio, { height: 3.3 })
|
|
352
|
-
scene.add(studio)
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
// head = new TalkingHead( document.getElementById('avatar'), {
|
|
356
|
-
// avatarOnly: true,
|
|
357
|
-
// avatarOnlyScene: scene,
|
|
358
|
-
// avatarOnlyCamera: camera,
|
|
359
|
-
// lipsyncModules: ["en"],
|
|
360
|
-
// dracoEnabled: true,
|
|
361
|
-
// })
|
|
362
|
-
head_1 = new TalkingHead( document.getElementById('avatar_1'), {
|
|
363
|
-
avatarOnly: true,
|
|
364
|
-
avatarOnlyScene: scene,
|
|
365
|
-
avatarOnlyCamera: camera_1,
|
|
366
|
-
lipsyncModules: ["en"],
|
|
367
|
-
dracoEnabled: true,
|
|
368
|
-
})
|
|
369
|
-
head_2 = new TalkingHead( document.getElementById('avatar_2'), {
|
|
370
|
-
avatarOnly: true,
|
|
371
|
-
avatarOnlyScene: scene,
|
|
372
|
-
avatarOnlyCamera: camera_1,
|
|
373
|
-
lipsyncModules: ["en"],
|
|
374
|
-
dracoEnabled: true,
|
|
375
|
-
})
|
|
376
|
-
// head_3 = new TalkingHead( document.getElementById('avatar_3'), {
|
|
377
|
-
// avatarOnly: true,
|
|
378
|
-
// avatarOnlyScene: scene,
|
|
379
|
-
// avatarOnlyCamera: camera,
|
|
380
|
-
// lipsyncModules: ["en"],
|
|
381
|
-
// dracoEnabled: true,
|
|
382
|
-
// })
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
try {
|
|
386
|
-
loading.textContent = "Loading..."
|
|
387
|
-
await head_1.showAvatar( {
|
|
388
|
-
url: avatar_1_url,
|
|
389
|
-
body: 'F',
|
|
390
|
-
avatarMood: 'neutral',
|
|
391
|
-
lipsyncLang: 'en'
|
|
392
|
-
}, (ev) => {
|
|
393
|
-
if ( ev.lengthComputable ) {
|
|
394
|
-
let val = Math.min(100,Math.round(ev.loaded/ev.total * 100 ))
|
|
395
|
-
loading.textContent = "Loading " + val + "%"
|
|
396
|
-
}
|
|
397
|
-
})
|
|
398
|
-
await head_2.showAvatar( {
|
|
399
|
-
url: avatar_2_url,
|
|
400
|
-
body: 'F',
|
|
401
|
-
avatarMood: 'neutral',
|
|
402
|
-
lipsyncLang: 'en'
|
|
403
|
-
}, (ev) => {
|
|
404
|
-
if ( ev.lengthComputable ) {
|
|
405
|
-
let val = Math.min(100,Math.round(ev.loaded/ev.total * 100 ))
|
|
406
|
-
loading.textContent = "Loading " + val + "%"
|
|
407
|
-
}
|
|
408
|
-
})
|
|
409
|
-
loading.style.display = 'none'
|
|
410
|
-
|
|
411
|
-
head_1.armature.position.set(0, 0, 0)
|
|
412
|
-
head_1.armature.rotation.set(0, 0, 0)
|
|
413
|
-
scene.add(head_1.armature)
|
|
414
|
-
put_feet_at_origin(head_1)
|
|
415
|
-
point_camera_at_face(camera_1, head_1, '1')
|
|
416
|
-
|
|
417
|
-
head_2.armature.position.set(1, 0, 0)
|
|
418
|
-
head_2.armature.rotation.set(0, 0, 0)
|
|
419
|
-
scene.add(head_2.armature)
|
|
420
|
-
put_feet_at_origin(head_2)
|
|
421
|
-
point_camera_at_face(camera_2, head_2, '2')
|
|
422
|
-
|
|
423
|
-
const onMetrics = (which) => {
|
|
424
|
-
logg(which, 'onMetrics')
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
const onSubtitles = (which) => {
|
|
428
|
-
// logg(which)
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const streamOpts = {
|
|
432
|
-
gain: config.gain,
|
|
433
|
-
lipsyncLang: config.lipsyncLang,
|
|
434
|
-
lipsyncType: config.lipsyncType,
|
|
435
|
-
metrics: config.enableMetrics ? { enabled: true, intervalHz: config.metricsInterval } : { enabled: false },
|
|
436
|
-
mood: config.mood,
|
|
437
|
-
sampleRate: config.sampleRate,
|
|
438
|
-
waitForAudioChunks: config.waitForAudioChunks,
|
|
439
|
-
}
|
|
440
|
-
await head_1.streamStart(streamOpts, () => {}, () => {}, onSubtitles, onMetrics)
|
|
441
|
-
await head_2.streamStart(streamOpts, () => {}, () => {}, onSubtitles, onMetrics)
|
|
442
|
-
|
|
443
|
-
} catch (error) {
|
|
444
|
-
console.log(error)
|
|
445
|
-
loading.textContent = error.toString()
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
//
|
|
450
|
-
|
|
451
|
-
renderer = new THREE.WebGLRenderer( {
|
|
452
|
-
alpha: false,
|
|
453
|
-
antialias: true,
|
|
454
|
-
} )
|
|
455
|
-
renderer.setClearColor(0xd3d3d3, 1)
|
|
456
|
-
renderer.setPixelRatio( 1 ); // window.devicePixelRatio )
|
|
457
|
-
renderer.setSize( width, height )
|
|
458
|
-
renderer.toneMapping = THREE.ACESFilmicToneMapping
|
|
459
|
-
renderer.toneMappingExposure = 1
|
|
460
|
-
renderer.outputColorSpace = THREE.SRGBColorSpace
|
|
461
|
-
document.getElementById('rotatingC').appendChild( renderer.domElement )
|
|
462
|
-
|
|
463
|
-
//
|
|
464
|
-
|
|
465
|
-
controls = new OrbitControls( camera, renderer.domElement )
|
|
466
|
-
controls.enableDamping = true
|
|
467
|
-
controls.enableRotate = true
|
|
468
|
-
controls.enablePan = true
|
|
469
|
-
controls.enableZoom = true
|
|
470
|
-
controls.minDistance = 0.5
|
|
471
|
-
controls.maxDistance = 100
|
|
472
|
-
controls.target.copy(faceTarget)
|
|
473
|
-
controls.autoRotate = false
|
|
474
|
-
controls.update()
|
|
475
|
-
|
|
476
|
-
restoreHeadControl()
|
|
477
|
-
document.querySelectorAll('input[name=head]').forEach((input) => {
|
|
478
|
-
input.addEventListener('change', () => {
|
|
479
|
-
if (!input.checked) return
|
|
480
|
-
setActiveHead(input.value)
|
|
481
|
-
})
|
|
482
|
-
})
|
|
483
|
-
const selectedHead = document.querySelector('input[name=head]:checked')
|
|
484
|
-
setActiveHead(selectedHead ? selectedHead.value : '1')
|
|
485
|
-
|
|
486
|
-
restoreCameraControl()
|
|
487
|
-
document.querySelectorAll('input[name=camera]').forEach((input) => {
|
|
488
|
-
input.addEventListener('change', () => {
|
|
489
|
-
if (!input.checked) return
|
|
490
|
-
setActiveCamera(input.value)
|
|
491
|
-
})
|
|
492
|
-
})
|
|
493
|
-
const selected = document.querySelector('input[name=camera]:checked')
|
|
494
|
-
setActiveCamera(selected ? selected.value : '1', true)
|
|
495
|
-
|
|
496
|
-
document.querySelectorAll('input.light-ctrl').forEach((input) => {
|
|
497
|
-
input.addEventListener('change', syncLightsFromControls)
|
|
498
|
-
})
|
|
499
|
-
syncLightsFromControls()
|
|
500
|
-
|
|
501
|
-
//
|
|
502
|
-
|
|
503
|
-
window.addEventListener( 'resize', onWindowResize )
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
// Keep rendering so OrbitControls drag/damping stay live
|
|
507
|
-
lastAnimTime = performance.now()
|
|
508
|
-
renderer.setAnimationLoop(animate)
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
let semafore = false
|
|
512
|
-
document.addEventListener('DOMContentLoaded', async function(e) {
|
|
513
|
-
if (!semafore) {
|
|
514
|
-
semafore = true
|
|
515
|
-
await init()
|
|
516
|
-
}
|
|
517
|
-
})
|
|
518
|
-
|
|
519
|
-
function cameras() {
|
|
520
|
-
return { '1': camera_1, '2': camera_2, '3': camera_3 }
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
function heads() {
|
|
524
|
-
return { '1': head_1, '2': head_2, '3': head_3 }
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
function setActiveHead(id) {
|
|
528
|
-
const key = String(id)
|
|
529
|
-
head = heads()[key] || head_1
|
|
530
|
-
persistHeadControl(key)
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
function easeInOutCubic(t) {
|
|
534
|
-
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
function setActiveCamera(id, instant = false) {
|
|
538
|
-
const key = String(id)
|
|
539
|
-
persistCameraControl(key)
|
|
540
|
-
const dest = cameras()[key] || camera_1
|
|
541
|
-
const destTarget = (cameraTargets[key] || cameraTargets['1']).clone()
|
|
542
|
-
;[camera_1, camera_2, camera_3, camera].forEach((cam) => {
|
|
543
|
-
if (cam) {
|
|
544
|
-
cam.aspect = width / height
|
|
545
|
-
cam.updateProjectionMatrix()
|
|
546
|
-
}
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
dest.updateMatrixWorld()
|
|
550
|
-
|
|
551
|
-
const endPos = dest.position.clone()
|
|
552
|
-
const endQuat = dest.quaternion.clone()
|
|
553
|
-
|
|
554
|
-
if (instant || !controls) {
|
|
555
|
-
camera.position.copy(endPos)
|
|
556
|
-
camera.quaternion.copy(endQuat)
|
|
557
|
-
camera.fov = dest.fov
|
|
558
|
-
camera.near = dest.near
|
|
559
|
-
camera.far = dest.far
|
|
560
|
-
camera.updateProjectionMatrix()
|
|
561
|
-
faceTarget.copy(destTarget)
|
|
562
|
-
if (controls) {
|
|
563
|
-
controls.target.copy(destTarget)
|
|
564
|
-
controls.update()
|
|
565
|
-
}
|
|
566
|
-
cameraTransition = null
|
|
567
|
-
return
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
cameraTransition = {
|
|
571
|
-
startPos: camera.position.clone(),
|
|
572
|
-
startQuat: camera.quaternion.clone(),
|
|
573
|
-
startFov: camera.fov,
|
|
574
|
-
startTarget: controls.target.clone(),
|
|
575
|
-
endPos: endPos,
|
|
576
|
-
endQuat: endQuat,
|
|
577
|
-
endFov: dest.fov,
|
|
578
|
-
endTarget: destTarget,
|
|
579
|
-
elapsed: 0,
|
|
580
|
-
duration: CAMERA_BLEND_MS,
|
|
581
|
-
}
|
|
582
|
-
controls.enabled = false
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
function updateCameraTransition(dt) {
|
|
586
|
-
if (!cameraTransition) return
|
|
587
|
-
cameraTransition.elapsed += dt
|
|
588
|
-
const u = Math.min(1, cameraTransition.elapsed / cameraTransition.duration)
|
|
589
|
-
const e = easeInOutCubic(u)
|
|
590
|
-
const tr = cameraTransition
|
|
591
|
-
camera.position.lerpVectors(tr.startPos, tr.endPos, e)
|
|
592
|
-
camera.quaternion.slerpQuaternions(tr.startQuat, tr.endQuat, e)
|
|
593
|
-
camera.fov = tr.startFov + (tr.endFov - tr.startFov) * e
|
|
594
|
-
camera.updateProjectionMatrix()
|
|
595
|
-
if (controls) {
|
|
596
|
-
controls.target.lerpVectors(tr.startTarget, tr.endTarget, e)
|
|
597
|
-
faceTarget.copy(controls.target)
|
|
598
|
-
} else {
|
|
599
|
-
faceTarget.lerpVectors(tr.startTarget, tr.endTarget, e)
|
|
600
|
-
}
|
|
601
|
-
if (u >= 1) {
|
|
602
|
-
cameraTransition = null
|
|
603
|
-
if (!capturing && controls) {
|
|
604
|
-
controls.enabled = true
|
|
605
|
-
controls.update()
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
function onWindowResize() {
|
|
611
|
-
;[camera_1, camera_2, camera_3].forEach((cam) => {
|
|
612
|
-
if (cam) {
|
|
613
|
-
cam.aspect = width / height
|
|
614
|
-
cam.updateProjectionMatrix()
|
|
615
|
-
}
|
|
616
|
-
})
|
|
617
|
-
renderer.setSize( width, height )
|
|
618
|
-
render()
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
function render() {
|
|
622
|
-
renderer.render( scene, camera )
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
function animate() {
|
|
626
|
-
let dt
|
|
627
|
-
if (capturing) {
|
|
628
|
-
dt = 1000 / fps
|
|
629
|
-
} else {
|
|
630
|
-
const now = performance.now()
|
|
631
|
-
dt = lastAnimTime ? (now - lastAnimTime) : (1000 / fps)
|
|
632
|
-
lastAnimTime = now
|
|
633
|
-
if (dt > 100) dt = 100
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
if (capturing) tickEvents(captureFrame * dt)
|
|
637
|
-
|
|
638
|
-
if (head_1) head_1.animate(dt)
|
|
639
|
-
if (head_2) head_2.animate(dt)
|
|
640
|
-
if (head_3) head_3.animate(dt)
|
|
641
|
-
updateCameraTransition(dt)
|
|
642
|
-
if (!cameraTransition && !capturing) controls.update()
|
|
643
|
-
renderer.render( scene, camera )
|
|
644
|
-
|
|
645
|
-
if (capturing) {
|
|
646
|
-
capturer.capture( renderer.domElement )
|
|
647
|
-
captureFrame++
|
|
648
|
-
if (captureFrame >= captureTotal) {
|
|
649
|
-
finishCapture()
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
async function startSpeakCapture() {
|
|
655
|
-
if (capturing) return
|
|
656
|
-
if (!head) return
|
|
657
|
-
if (!chunkedInput) {
|
|
658
|
-
console.log('no chunkedInput')
|
|
659
|
-
return
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
const last = chunkedInput.wtimes.length - 1
|
|
663
|
-
const duration_ms = chunkedInput.wtimes[last] + chunkedInput.wdurations[last]
|
|
664
|
-
captureTotal = Math.max(1, Math.ceil(duration_ms / 1000 * fps))
|
|
665
|
-
captureFrame = 0
|
|
666
|
-
eventsIndex = 0
|
|
667
|
-
capturing = true
|
|
668
|
-
cameraTransition = null
|
|
669
|
-
if (controls) controls.enabled = false
|
|
670
|
-
|
|
671
|
-
capturer = new CCapture( { format: 'webm', framerate: fps } )
|
|
672
|
-
capturer.start()
|
|
673
|
-
logg('capturer.start')
|
|
674
|
-
document.getElementById('status').textContent = 'capturing'
|
|
675
|
-
head.streamAudio(chunkedInput)
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
function finishCapture() {
|
|
679
|
-
capturing = false
|
|
680
|
-
capturer.stop()
|
|
681
|
-
logg('capturer.stop')
|
|
682
|
-
lastAnimTime = performance.now()
|
|
683
|
-
if (controls) controls.enabled = true
|
|
684
|
-
|
|
685
|
-
capturer.save((blob) => {
|
|
686
|
-
logg(blob, 'blob')
|
|
687
|
-
renderer.domElement.toBlob((thumb) => {
|
|
688
|
-
logg(thumb, 'thumb')
|
|
689
|
-
const form = new FormData()
|
|
690
|
-
form.append('video', blob, 'lips.webm')
|
|
691
|
-
form.append('name', slug)
|
|
692
|
-
form.append('thumb', thumb)
|
|
693
|
-
if (newspartial_id) form.append('newspartial_id', newspartial_id)
|
|
694
|
-
|
|
695
|
-
const url = wco_origin
|
|
696
|
-
? (wco_origin + '/wco/api/videos/?api_key=' + api_key + '&api_secret=' + api_secret)
|
|
697
|
-
: '/wco/api/videos/'
|
|
698
|
-
fetch(url, {
|
|
699
|
-
method: 'POST',
|
|
700
|
-
body: form,
|
|
701
|
-
}).then(() => {
|
|
702
|
-
document.getElementById('status').textContent = 'finished'
|
|
703
|
-
}).catch((error) => {
|
|
704
|
-
console.log(error)
|
|
705
|
-
document.getElementById('status').textContent = 'save failed'
|
|
706
|
-
})
|
|
707
|
-
})
|
|
708
|
-
})
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
// Speak when clicked
|
|
713
|
-
document.getElementById('speak').addEventListener('click', async function () {
|
|
714
|
-
try {
|
|
715
|
-
await startSpeakCapture()
|
|
716
|
-
} catch (error) {
|
|
717
|
-
console.log(error)
|
|
718
|
-
capturing = false
|
|
719
|
-
lastAnimTime = performance.now()
|
|
720
|
-
if (controls) controls.enabled = true
|
|
721
|
-
}
|
|
722
|
-
})
|
|
723
|
-
|
|
724
|
-
document.getElementById('wave').addEventListener('click', async function () {
|
|
725
|
-
try {
|
|
726
|
-
if (!head) return
|
|
727
|
-
head.playAnimation(wave_url)
|
|
728
|
-
} catch (error) {
|
|
729
|
-
console.log(error)
|
|
730
|
-
}
|
|
731
|
-
})
|
|
732
|
-
|
|
733
|
-
console.log('+++ loaded wco_models :: newsproducer :: studio_blue.js')
|