Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:36:16+00:00 2026-06-14T14:36:16+00:00

I am loading .obj files using THREE.OBJLoader() and pushing each object in myobj[] array

  • 0

I am loading .obj files using THREE.OBJLoader() and pushing each object in myobj[] array after adding it to screen.

var myObjs = [];
var loader = new THREE.OBJLoader();
loader.addEventListener( 'load', function ( event ) {
var object = event.content;
object.position.x=xpos;
object.position.y = ypos;
scene.add( object );
teeth.push(object);
});
loader.load( 'obj/myobj1.obj' );
loader.load('obj/myobj2.obj');
loader.load('obj/myobj3.obj');

I can check whether an object is clicked or not using the following code:

function onDocumentMouseDown( event ) {

event.preventDefault();
var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1, - (   event.clientY / window.innerHeight ) * 2 + 1, 0.5 );


projector.unprojectVector( vector, camera );

var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
var intersects = ray.intersectObjects( teeth, true );

if ( intersects.length > 0 ) {

intersects[0].object.position.z=50;
}

So far so good. Now what I can’t figure out is how to track which of my object in myobjs[] array was click or should I say how can I map intersects[0].object in myobjs array.

Regards,
ZB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:36:17+00:00Added an answer on June 14, 2026 at 2:36 pm

    The object will be exactly the same, i.e. intersects[0].object and some myobjs array member will both be references to the same instance. If you want to find the index to the myobjs array (for example in order to delete it from there), you have several choices:

    1. After intersection, loop through myobjs and compare intersects[0].object.id to myobj[i].id (each three.js object has a unique id property).
    2. You are also free to assign any suitable custom properties to the object in your load event handler, so simply add a line object.myId = myobjs.length; just before pushing it to myobjs and you can index the array later with intersects[0].object.myId.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am loading an object through an obj file in opengl using GLM Library
I have .obj files each with several texture files. Does three.js comes out of
I'm loading a JSON string in Django using simplejson , thus: obj = json.loads('{name:
After loading a PHP template (using jQuery's load function), this simple script won't make
Im working with a parser that handles Wavefront OBJ 3D object files and im
I am having some difficulty loading in texture coords from the obj file using
I have a model of a snowman that I am loading from a .obj
When loading the class, using method forName() , any static initializers in the class
After loading a reference to an assembly with something like: import clr clr.AddRferenceToFileAndPath(r'C:\foo.dll') How
I have been given the task of importing an obj file and loading it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.