-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-orbit.js
More file actions
57 lines (47 loc) · 1.59 KB
/
Copy pathadd-orbit.js
File metadata and controls
57 lines (47 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require('fs');
const path = require('path');
const filesToUpdate = [
'que-es-threejs.astro',
'primera-escena.astro',
'renderer.astro',
'geometrias.astro',
'materiales.astro',
'meshes.astro',
'luces.astro',
'texturas.astro',
'animaciones.astro',
'interacciones-3d.astro'
];
const dir = path.join(__dirname, 'src/pages/threejs');
filesToUpdate.forEach(file => {
const filePath = path.join(dir, file);
if (!fs.existsSync(filePath)) return;
let content = fs.readFileSync(filePath, 'utf8');
// Si ya tiene OrbitControls, lo saltamos
if (content.includes('OrbitControls')) {
console.log(`Skipping ${file}, already has OrbitControls`);
return;
}
// 1. Añadir import
content = content.replace(
`import * as THREE from 'three';`,
`import * as THREE from 'three';\n import { OrbitControls } from 'three/addons/controls/OrbitControls.js';`
);
// 2. Añadir instanciación
content = content.replace(
`container.appendChild(renderer.domElement);`,
`container.appendChild(renderer.domElement);\n\n const controls = new OrbitControls(camera, renderer.domElement);\n controls.enableDamping = true;\n controls.enablePan = false;`
);
// 3. Añadir update()
content = content.replace(
`animationId = requestAnimationFrame(animate);`,
`animationId = requestAnimationFrame(animate);\n controls.update();`
);
// 4. Añadir dispose()
content = content.replace(
`renderer.dispose();`,
`controls.dispose();\n renderer.dispose();`
);
fs.writeFileSync(filePath, content, 'utf8');
console.log(`Updated ${file}`);
});