Hi there! I use three.js to display 3D object onto web page as you can see here. But I would like to get the specific area coordinate of the 3D object to create a texture on Blender. So what my question is how to get the coordinates of some area on 3D object’s and then use this area in Blender to create some drawing in UV mapping in blender?
js code here:
// THREE.JS
let scene, camera, renderer, mesh, controls;
function initThreeJS(containerId) {
const container = document.getElementById(containerId);
scene = new THREE.Scene();
scene.background = new THREE.Color(0xeeeeee);
camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
camera.position.set(0, 0, 5);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(container.clientWidth, container.clientHeight);
container.appendChild(renderer.domElement);
// Işıklandırma
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(1, 1, 1);
scene.add(light);
scene.add(new THREE.AmbientLight(0x404040));
// Kontroller (Fare ile döndürme/zoom)
controls = new THREE.OrbitControls(camera, renderer.domElement);
// controle.enableZoom = false; dediğimizde bu kontrol için zoom özelliğini disable yapıyoruz.
// controls.enableZoom = false;
animate();
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
// STL Dosyasını Yükleme
function loadSTL(url) {
const loader = new THREE.STLLoader();
loader.load(url, (geometry) => {
if (mesh) scene.remove(mesh); // Eski modeli sil
const material = new THREE.MeshPhongMaterial({ color: 0x606060, specular: 0x111111, shininess: 200 });
mesh = new THREE.Mesh(geometry, material);
// Modeli merkeze al
geometry.computeBoundingBox();
const center = new THREE.Vector3();
geometry.boundingBox.getCenter(center);
mesh.position.sub(center);
scene.add(mesh);
});
}
// Dosya Seçimi (Genişletilmiş)
fileInput.onchange = (e) => {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
const isSTL = file.name.toLowerCase().endsWith('.stl');
reader.onload = (ev) => {
if (isSTL) {
// Görseli gizle, ThreeJS alanını göster
displayImage.style.display = 'none';
placeholderText.style.display = 'none';
document.getElementById('three-container').style.display = 'block';
if (!scene) initThreeJS('three-container'); // İlk kez ise başlat
loadSTL(ev.target.result);
} else {
// Görsel göster, ThreeJS'i gizle
document.getElementById('three-container').style.display = 'none';
displayImage.src = ev.target.result;
displayImage.style.display = 'block';
placeholderText.style.display = 'none';
}
};
if (isSTL) reader.readAsDataURL(file); // STL'i URL olarak oku
else reader.readAsDataURL(file); // Görseli URL olarak oku
};
// If the user clicked the lock button for drawing on 3D object
const lockBtn = document.getElementById(“lock-object”);
const lockIcon = document.getElementById(“lock-icon”);
lockBtn.addEventListener(“click”, function () {
controls.enabled = !controls.enabled;
lockIcon.classList.toggle("locked");
lockBtn.classList.toggle("active");
if (lockIcon.classList.contains("fa-lock")) {
lockIcon.classList.replace("fa-lock", "fa-lock-open");
} else {
lockIcon.classList.replace("fa-lock-open", "fa-lock");
}
});
