Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant move on 3D Model With Three.js #57

Open
ErenKrt opened this issue Dec 22, 2024 · 0 comments
Open

Cant move on 3D Model With Three.js #57

ErenKrt opened this issue Dec 22, 2024 · 0 comments

Comments

@ErenKrt
Copy link

ErenKrt commented Dec 22, 2024

Hello, I imported my 3D model with THREE.js using GLTF and Draco. I added a simple circle with Zim and assigned it to my model with canvas texture. There is no problem with the image, but I cannot move it.

Video;
https://github.com/user-attachments/assets/4b39df92-0ebc-4d90-b6ab-65836f678b43

My Code;

import { Frame, TextureActive, Circle, Label, TextureActives } from "zimjs"
import * as THREE from "three"
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"
import { DRACOLoader, GLTFLoader } from 'three/examples/jsm/Addons.js';
import { Three } from "@zimjs/three"

new Frame(FIT, 4096, 4096, black, darker, ready);

function ready() {

  const interactive = new TextureActive({
    width: W,
    height: H,
    color: yellow,
    corner: 0
  }).addTo();

  const circle = new Circle(50, purple).
    center(interactive)
    .pos(1000, 500)
    .transform({
      customCursors: true,
      rotate: true,
      showRotate: true,
      container: interactive
    });

  new Label("test", 30, null, white).center(circle);

  const three = new Three({
    width: window.innerWidth,
    height: window.innerHeight,
    cameraPosition: new THREE.Vector3(0, 1.8, 1),
    textureActive: true
  });


  const renderer = three.renderer;
  const scene = three.scene;
  const camera = three.camera;


  const controls = new OrbitControls(camera, three.canvas);

  const textureActives = new TextureActives([interactive], THREE, three, renderer, scene, camera, controls, 1, 0, 1000);

  const loader = new GLTFLoader();
  const dracoLoader = new DRACOLoader();
  dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.7/');
  loader.setDRACOLoader(dracoLoader);

  loader.load("/assets/jersey/model/forma_18.12.gltf", function (gltf) {
    var model = gltf.scene;

    const cubeTexture = new THREE.CanvasTexture(interactive.canvas);
    cubeTexture.flipY = false;
    const cubeMaterial = new THREE.MeshLambertMaterial({ map: cubeTexture });

    model.traverse((child) => {
      child.material = cubeMaterial;
    });

    scene.add(model);
    textureActives.addMesh(model, 1);
  })


  const light1 = new THREE.DirectionalLight(0xffffff, 1 * Math.PI);
  light1.position.set(100, 200, 100);
  scene.add(light1);

  const light2 = new THREE.AmbientLight(0xffffff, .6 * Math.PI);
  scene.add(light2);

  const light3 = new THREE.DirectionalLight(0xffffff, .3 * Math.PI);
  light3.position.set(-100, -200, 100);
  scene.add(light3);
}
@ErenKrt ErenKrt changed the title Cant move on 3D Model Cant move on 3D Model With Three.js Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant