Display your own 3D Model with Javascript | three.js

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2020
  • In this video I'll teach you how to use three.js to display any 3d model with Javascript! We use the GLTFLoader module to import a .gltf model.
    three.js github link: github.com/mrdoob/three.js/
    Info on same origin policy (live server requirement): en.wikipedia.org/wiki/Same_ori...
    I will be making daily videos about programming on this channel, so subscribe for more great content! Don't be shy to comment too with any questions.
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 91

  • @SuperAkhilkrishnan
    @SuperAkhilkrishnan 3 ปีที่แล้ว +11

    I have tried many videos, but I haven't got the output. But you are really great. You have explained each and every step. Now I got the output. Thank you very much, Mike.

  • @solocani6922
    @solocani6922 3 ปีที่แล้ว +1

    Finally a clear and simple video about this topic, thanks man!! :)

  • @igrb
    @igrb 3 ปีที่แล้ว +2

    You're doing an amazing job man, such a helpful video

  • @SDMattos
    @SDMattos 2 ปีที่แล้ว

    Dude...AWESOME tutorial, thanks for the clarity.

  • @VikNov
    @VikNov 2 ปีที่แล้ว

    Great! Helped me. Also, if you guys want to get rid of that errors in console at the end of the video, then place animate() call into loader.load() second parameter (on loaded function).

  • @mrshanks1457
    @mrshanks1457 3 ปีที่แล้ว

    Thank you so much man, this is the best instruction about gltf!

  • @albertogandarillas657
    @albertogandarillas657 2 ปีที่แล้ว

    Thank you Mike , very helpful tutorial !

  • @marquisegbunike5773
    @marquisegbunike5773 11 หลายเดือนก่อน

    I've tried not just one or two videos like this but you just break my curiosity as to why mine wasn't working. many thanks for putting this out here.

  • @dclxviclan
    @dclxviclan ปีที่แล้ว

    Thanks bro, this awesome, i look many videos and read many documentation, but dont understand, and when i look u video i understand all mechanics, thank u, u cool bro

  • @cube6338
    @cube6338 2 ปีที่แล้ว

    I have been seeking this for hours. Thank u ,u made my day (qwq)

  • @donal9914
    @donal9914 2 ปีที่แล้ว

    Very good video by the way sad that you got not that much subscribers, content 10+

  • @issammerikhi5359
    @issammerikhi5359 3 ปีที่แล้ว +1

    Thanks a lot !!! I was struggling for 2 days with this shit ! God bless you

  • @sadmanyasar17
    @sadmanyasar17 3 ปีที่แล้ว +2

    Thank you soooo much. Just one problem I faced was when importing GLTFLoader at 4:20 in the video. So I installed three.js using npm on the project directory and did not change the line 64 on GLTFLoader.js file. Then imported it using import {GLTFLoader} from "./three/examples/jsm/loaders/GLTFLoader.js"; instead of "./GLTFLoader.js" (5:00) and everything worked just fine!

  • @sheiskryptonite
    @sheiskryptonite ปีที่แล้ว

    Thanks so much! Loved your video

  • @gabriellengoo8511
    @gabriellengoo8511 3 ปีที่แล้ว

    AHHHH Finally Something that works!!! , subscribed

  • @ritikverma312
    @ritikverma312 ปีที่แล้ว

    Thanks bro very much appreciated 💪🏼

  • @terra9226
    @terra9226 3 ปีที่แล้ว

    Mr. Cube is the real MVP here...

  • @eliascerne6786
    @eliascerne6786 2 ปีที่แล้ว +1

    omfg thanks I had some issues with importing the modules

  • @kiranmr8525
    @kiranmr8525 3 ปีที่แล้ว

    Good one ! Keep it up

  • @yifeige6089
    @yifeige6089 3 ปีที่แล้ว +7

    Hey Mike,
    Thanks for the tutorial, the error you thrown in the last minute of your video is not caused by the live server. It's loader.load() function is asynchronous
    So basically the loader is still loading the scene.gltf and JS will continue to run the code below, however since the obj.rotation and scene.add(light) depends the loading, then you see all the errors on the console.
    To solve this issue you need to do the following:
    //let's load the scene.gltf file
    //loader.load takes 2 parameters
    //1) .gltf file
    //2). a callback function
    loader.load("scene.gltf", function (gltf) {
    obj = gltf.scene;
    scene.add(gltf.scene);
    //after the scene is loaded
    //we can add the background and light
    //also run the animate function
    scene.background = new THREE.Color(0xffffff);
    var light = new THREE.HemisphereLight(0xffffff, 0x000000, 10);
    scene.add(light);
    camera.position.set(0, 10, 40);
    animate();
    });
    basically, you set the backgound and the light inside this callback function and finally run the animate() function
    The async javascript is tricky, check this article
    developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous

  • @shafeeanwar3785
    @shafeeanwar3785 2 ปีที่แล้ว

    I like this guy's honesty, he's not trying to read a statement from wikipedia presenting himself as mr. known it all(which most other uthubers do). When you don't know much about a topic then dont buII$hlt

  • @matthewbaynham6286
    @matthewbaynham6286 ปีที่แล้ว

    Fantastic it works

  • @developer1107
    @developer1107 3 ปีที่แล้ว +1

    Hey smith, you're such a great programmer. Can I ask a video from your tutorial here in youtube. A 3D model in sketchfab which you can navigate or can rotate by the mouse cursor like an orbit function in sketchup. Thank you. I'm your new subscriber

  • @brflimproduction7689
    @brflimproduction7689 2 ปีที่แล้ว

    Thanks man its awesome

  • @felipeolguera
    @felipeolguera 3 ปีที่แล้ว

    Amazing job, please dont stop, you help a lot. One question, do you know how to do this, if i click on the gltf model it will change color? please thanks

  • @ajaybhati5830
    @ajaybhati5830 ปีที่แล้ว

    thank you sooooo much it final worked

  • @sahilagarwal7752
    @sahilagarwal7752 ปีที่แล้ว

    thanks a lot!

  • @guardianvicio3367
    @guardianvicio3367 2 ปีที่แล้ว

    Thanks man :D!

  • @tervancovan
    @tervancovan 2 ปีที่แล้ว

    Wow it is awesome

  • @kamill704
    @kamill704 3 ปีที่แล้ว

    its CORS kind sir, to resolve: 1.you can use an extension 2. dont load them from your pc, get them hosted somewhere and just link it up. 3. if you host that in flask for example, flask cors will take care of it for you

  • @paradisepicks.
    @paradisepicks. 2 ปีที่แล้ว

    Great video! do you know if there is anyway that we could move the model, like up and down ?

  • @chriscalabrese2209
    @chriscalabrese2209 2 ปีที่แล้ว

    Great vid.
    Does this work with an OBJ file or would I need OBJ specific loader code?

  • @nafaynajam2279
    @nafaynajam2279 3 ปีที่แล้ว

    Hello. Please make a video on how you would run this on Flask instead of Live server. Thank you

  • @SuperAkhilkrishnan
    @SuperAkhilkrishnan 3 ปีที่แล้ว

    Please make more videos in Three.JS

  • @Allenthegreat
    @Allenthegreat 2 ปีที่แล้ว

    thanks very useful, please make ur camera smaller next time so it doesn't block vsc

  • @gmchessplay9043
    @gmchessplay9043 3 ปีที่แล้ว +1

    Can you do this, but with Angular, importing THREE and other dependencies using npm etc. That would be awesome, thanks.

  • @vermillionorange3294
    @vermillionorange3294 2 ปีที่แล้ว

    Tysm

  • @irinafawcett4684
    @irinafawcett4684 3 ปีที่แล้ว

    this was SO helpful thank you so much!!!

  • @yienmh3015
    @yienmh3015 2 ปีที่แล้ว

    It works after following this video , but how can I setup the shadow to make it more like reality?
    And one more. How can I navigate or can rotate by the mouse cursor like an orbit function on website.
    thank you for the helpful video!

  • @inside_ethereal
    @inside_ethereal ปีที่แล้ว

    fucking chad, it finally worked

  • @petervarga2616
    @petervarga2616 2 ปีที่แล้ว

    is it possible to use the camera from the [imported] file?
    (instead of coding one as demonstrated here)
    thanks!

  • @moonie9848
    @moonie9848 2 ปีที่แล้ว

  • @waheedsharif5514
    @waheedsharif5514 3 ปีที่แล้ว

    Can you make a tutorial about displaying a large .obj file on web? The file is over 2.5 gb

  • @felipeduarte6218
    @felipeduarte6218 ปีที่แล้ว

    me ajudou pkrl valeu 😀

  • @zachio69
    @zachio69 ปีที่แล้ว +1

    I'm getting an error with my code. Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

    • @kaustubh52q45
      @kaustubh52q45 ปีที่แล้ว

      even i am getting same error, have you resolved it ?

  • @user-zv4tq2uw9y
    @user-zv4tq2uw9y 2 ปีที่แล้ว

    you fucking saved my ass! thank you so much. I was searching for days....

  • @Riggs212121
    @Riggs212121 3 ปีที่แล้ว

    Hey Mike great video but I'm a little stuck on something and was wondering you could me out. I've downloaded the three.js zip folder from the three.js site but the code within GLTFLoader.js file is completely different from the one you have, am I getting the wrong files? I ended up grabbing your version from a previous comment but I'm just wondering why your file is different from the one off the site?

    • @mixschnack
      @mixschnack 3 ปีที่แล้ว

      Me too. Wondering. You seem to need exactly that missing piece.

  • @jounalansman1769
    @jounalansman1769 3 ปีที่แล้ว

    So does this work with the glb binary format also?

  • @AnweshAdhikari
    @AnweshAdhikari ปีที่แล้ว

  • @scottonanski4173
    @scottonanski4173 2 ปีที่แล้ว

    Would we need to import the OrbitControls in the same manner?

  • @alexrivera2343
    @alexrivera2343 2 ปีที่แล้ว

    Personally feel that I am in love with this wonderful man

  • @avatr7109
    @avatr7109 2 ปีที่แล้ว

    Bro Get IN more Threejs Tuts ...
    i would love to se0e

  • @PriyanshuKumar-io4cs
    @PriyanshuKumar-io4cs 3 ปีที่แล้ว

    Can you help me out...how can I add color customizer into this??

  • @MrDnong
    @MrDnong 2 ปีที่แล้ว

    Thanks for your video, but I got an error showed "The requested module './GLTFLoader.js' does not provide an export named 'GLTFloader'", could you please help me with that?

  • @michaelrichter1378
    @michaelrichter1378 2 ปีที่แล้ว

    i fucking love you and your voice

  • @muneeburrehmankhan938
    @muneeburrehmankhan938 3 ปีที่แล้ว

    brother i do the same but facing error i am new would you please help me:
    Uncaught SyntaxError: Cannot use import statement outside a module

  • @tadachaipanya6647
    @tadachaipanya6647 3 ปีที่แล้ว

    Can u make the extension content that makes options to change the color of the car?

    • @MikeSmith-mb5em
      @MikeSmith-mb5em  3 ปีที่แล้ว

      I'm unfortunately taking a break from videos for school at the moment, but I'll remember this in the future! For now, try looking at the three.js documentation, or perhaps what you could do is change the model colors in whatever 3d modelling software you're using and then switch the models at a press of a button. That solution would work, but would perhaps be inefficient loading so many models, I'm sure there is a way to do it within three.js.

  • @sirwanjaff1050
    @sirwanjaff1050 3 ปีที่แล้ว

    Good.
    Can you help me to create a project use three.js ?

  • @mrsilver8151
    @mrsilver8151 2 ปีที่แล้ว

    hi sir, thanks for the great work
    I am new to Three.js, and I follow your steps, but it doesn't work with me.
    my question is do I need NodeJs to use "import {filename} from" or it should be work fine by adding type="module",
    or maybe its just the package version issue, I really need to know why it doesn't work even the background was white, but with no error on the console.
    thanks in advance

    • @vicecersa3470
      @vicecersa3470 ปีที่แล้ว

      same with me do you got any solution to this?

  • @dhanushkumar7226
    @dhanushkumar7226 3 ปีที่แล้ว

    hey can u pls share the the github link for the project

  • @TheRuturaj9
    @TheRuturaj9 2 ปีที่แล้ว

    hi looking to load ply files to just view?? any help??

  •  2 ปีที่แล้ว

    Hey Mike, Firstly Thanks a lot for this full of information video. I think my fault but can you help me? I have this errors on my page. When I save the codes I dont see anything. I am clearly write the codes but not works.
    three.module.js:49851 WARNING: Multiple instances of Three.js being imported.
    3D.html:30 Uncaught TypeError: THREE.WebGlRenderer is not a constructor

    •  2 ปีที่แล้ว

      @mike smith

    • @VMNthemaster
      @VMNthemaster 2 ปีที่แล้ว +1

      L capital in GLRenderer

  • @k0r114
    @k0r114 2 ปีที่แล้ว +1

    Hey Smith, I followed each one of your steps but I get an error on the browser console: Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../". If you or anyone can solve this it'be great!!

    • @VanillaBoyz
      @VanillaBoyz 2 ปีที่แล้ว

      now, can you solve this?

    • @angeldarco
      @angeldarco 2 ปีที่แล้ว

      In the html, before the threejs import
      { "imports": { "three": "../build/three.module.js" } }

  • @antonboreiko109
    @antonboreiko109 2 ปีที่แล้ว

    Thanks a lot. but there is an error question: TypeError: Cannot read properties of undefined (reading 'rotation')
    at animate

    • @antonboreiko109
      @antonboreiko109 2 ปีที่แล้ว

      found the answer in a minute)) not obj.rotation.y + = 0.01; => scene.rotation.y + = 0.01;

  • @kaitlyngross6912
    @kaitlyngross6912 3 ปีที่แล้ว +4

    Hi Mike,
    I am getting the error : " WARNING: Multiple instances of Three.js being imported. @ three.module.js:49490 ." What could cause this issue?

    • @loganbates8533
      @loganbates8533 2 ปีที่แล้ว

      Same here, I still cant find the solution

  • @tadachaipanya6647
    @tadachaipanya6647 3 ปีที่แล้ว

    4:30 I could not use this form, I need to write this down instead "./three.module". I don't know why. can you explain to me?

    • @MikeSmith-mb5em
      @MikeSmith-mb5em  3 ปีที่แล้ว

      Hmm, I would go to that directory and see if there is a .js file extension on that file to get some more insight. Seems weird that it wouldn't be included on the file. Maybe some sort of bug happened when it was being downloaded, or perhaps you got the files from a different place than I did?

  • @Alex-er1oj
    @Alex-er1oj 2 ปีที่แล้ว

    Thanks for this video. But I got a WARNING: Multiple instances of Three.js being imported. three.module.js:48909 How can this problem be solved?

  • @davidguru5650
    @davidguru5650 3 ปีที่แล้ว

    hey mike, I tried using your code to import my 3d model but it doesnt work, can i have the code you typed in
    or email me

    • @MikeSmith-mb5em
      @MikeSmith-mb5em  3 ปีที่แล้ว +1

      Sure thing, David. I put the files I made in the video on to github at this link: github.com/michaelmss/threejsfileimport

    • @MikeSmith-mb5em
      @MikeSmith-mb5em  3 ปีที่แล้ว +1

      I did not include the model files I used because they were too big for github, but if you just put your .gltf and .bin file into the source directory it should work. You might have to mess around with background colors and camera position, check my reply to Philip Rosner in this comment section for more on that. (Also, be sure that you are using some sort of live hosting feature as you cant just open the .html file, it has to be hosted because of some obscure browser rules with model files, see the link in the description for more on that.)

  • @kira3821
    @kira3821 ปีที่แล้ว

    same steps on 2023?

  • @PriyanshuKumar-io4cs
    @PriyanshuKumar-io4cs 3 ปีที่แล้ว

    Please help me out with color customizer!!

    • @MikeSmith-mb5em
      @MikeSmith-mb5em  3 ปีที่แล้ว +1

      Maybe this link could help you: tympanus.net/codrops/2019/09/17/how-to-build-a-color-customizer-app-for-a-3d-model-with-three-js/

    • @PriyanshuKumar-io4cs
      @PriyanshuKumar-io4cs 3 ปีที่แล้ว

      @@MikeSmith-mb5em thanks!! Better if u make such videos of adding customizer...

  • @dimitrynevermind7804
    @dimitrynevermind7804 2 ปีที่แล้ว

    4:12 I don't have it inside GLTFLoader.js

    • @dimitrynevermind7804
      @dimitrynevermind7804 2 ปีที่แล้ว

      I found it, looks like library contains two files with the same name... we need one from JSM folder

  • @prathamkorade5499
    @prathamkorade5499 ปีที่แล้ว +1

    This is not working now a days!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @karticksharmapro1523
    @karticksharmapro1523 2 ปีที่แล้ว

    the scene and your gltf scene is making a lot of confusion

  • @ludgi1
    @ludgi1 2 ปีที่แล้ว +2

    Improvements :
    1. Upload the source code to Github so that people don't have to copy the code according to your video like an idiot.
    2. Your camera feed is way too large and it blocks the code, which is much important than your face.