Log in or register to post comments

How to duplicate a 3D object from one marker to another marker in runtime

January 22, 2014 - 6:42pm #1

Hi evereyone, now, i can show the button that user to call the empty function for duplicate the gmaeObject when the marker A is tracked. However, how can i write the duplicate function that it allows to  duplicate function from markerA to markerB.

As i know, in unity, there are API for it, i have changed the XY position that used o duplicatie the gameObject in same markerA and shown the gameobject in debug log. However, it cannot show in runtime AR application.
http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

 

thanks

How to duplicate a 3D object from one marker to another marker in runtime

January 12, 2019 - 10:25am #10

     private void OnCollisionEnter(Collision collision)

     {

        rb.useGravity = false;

        rb.constraints = RigidbodyConstraints.FreezeRotation;

        rb.constraints = RigidbodyConstraints.FreezePosition;



        collision.gameObject.transform.parent = GameObject.Find("ImageTarget").transform;    // This line image target and collision object combine. Thus, non-moving object move direction of image target. TAG:           stcik objects



        Debug.Log("Collission detect.");

     }

     //Deniz BABAT

How to duplicate a 3D object from one marker to another marker i

February 5, 2014 - 4:21am #9

As I said, you can set the game object transform so to duplicate the same values of the original object, using this code:

gameObject.transform.localScale =  desired local scale (e.g. the one of another object)

But you should definitely debug your code and understand why you are getting such small scale values...

Also, probably worth checking in the Unity websoite about how to Instantiate / clone game objects, as this goes beyond the scope of Vuforia:

http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

 

How to duplicate a 3D object from one marker to another marker i

February 5, 2014 - 12:17am #8

Thank you for your answer. i done it in Unity. I duplicate it in one script and change the duplicate's scale in other script. i do not know why it is not work when do it in same script

The duplicate Script

void onDuplicat(){
        Debug.LogError("Test Step two OK");
        if (duplicateObject){
            pickedObject = GameObject.Find("teapot");
            childObject = Instantiate(pickedObject.gameObject,new Vector3(0,0,0),Quaternion.identity) as GameObject;
            childObject.gameObject.transform.parent = GameObject.Find("IMAGE2").transform
        }
    }

Change the Scale Script

 void onChangeScale(){
        Debug.LogError("Test Step two OK");
        if (duplicateObject){
            pickedObject = GameObject.Find("teapot(Clone)");
            childObject.transform.localScale = new Vector3(0.1f,0.1f,0.1f);
            childObject.transform.localPosition = new Vector3(0,0,0);
        }
         
    }

Also, i find that the Scale of the duplicate is very small, about 5e-3, and the Rotation is different . How can i duplicate the exactly transform values of 3D Object?

How to duplicate a 3D object from one marker to another marker i

January 29, 2014 - 3:37am #7

You can change localScale of any game object by doing:

gameObject.transform.localScale = new Vector3 (  sx,  sy,  sz );

 

How to duplicate a 3D object from one marker to another marker i

January 29, 2014 - 12:24am #6
using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour, ITrackableEventHandler{
	
	private TrackableBehaviour mTrackableBehaviour;
	private bool duplicateObject = false;
	public GameObject pickedObject = null;
	public GameObject childObject = null;
	
	// Use this for initialization
	void Start () {
		Debug.LogError("Start Check!!!!!!!");
		mTrackableBehaviour = GetComponent<TrackableBehaviour>();
		if (mTrackableBehaviour){
			mTrackableBehaviour.RegisterTrackableEventHandler(this);
		}
	
	}
	
	public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus,TrackableBehaviour.Status newStatus){
		
		Debug.LogError("duplicateObject = True. Test Step one OK");
		if (newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED){
			duplicateObject = true;
			onDuplicat();
		}else{
			duplicateObject = false;
		}
	}
	
	// Update is called once per frame
	
	void onDuplicat(){
		Debug.LogError("Test Step two OK");
		if (duplicateObject){
			pickedObject = GameObject.Find("teapot");
			Debug.LogError(pickedObject.name+ ", parent:"+pickedObject.gameObject.transform.parent);
			Debug.LogError("Picked Scale:"+pickedObject.transform.localScale);
			Debug.LogError("Picked Position:"+pickedObject.transform.localPosition);
			Debug.LogError("Picked rotation:"+pickedObject.transform.localRotation);
			childObject = Instantiate(pickedObject.gameObject,new Vector3(0,0,0),Quaternion.identity) as GameObject;
			childObject.gameObject.transform.localScale = new Vector3(0.1f,0.1f,0.1f);
			childObject.gameObject.transform.parent = pickedObject.transform.parent;
			childObject.transform.position = new Vector3(0,0,1);
			Debug.LogError("Child:"+childObject.name);
			Debug.LogError("Child:"+childObject.transform.localScale);
			Debug.LogError("Child Position:"+childObject.transform.localPosition);
			Debug.LogError("Child rotation:"+childObject.transform.localRotation);
			Debug.LogError("The parent: "+ childObject.gameObject.transform.parent +"!!!");
		}
		
	}

I have modified the code and the it is still can not show the duplicate gameObject.

Show in Debug Log,  the localScale of childObject and pickedObject are (0.0, 0.0, 0.0)? How can i change the localscale of childObject??

 

How to duplicate a 3D object from one marker to another marker i

January 28, 2014 - 8:42pm #5

Is it any sample apps of Diminoes of unity? I cannot find it in the website

I want to study how to  duplicate the 3D object, also, i want to study how to clean the 3D object in runtime

Thanks

How to duplicate a 3D object from one marker to another marker i

January 26, 2014 - 5:00am #4

The code you posted does not show how you set the pickedObject and the parentObject;

first you should verify / debug if those are correctly set; then, if everything is correctly setup, you may also need to check the localScale of your childObject (currently youu are setting the localPosition to new Vector3(0,0,0), but you could also change the localScale; for example, the object may be too small (and thus not visible) due to the parent scale...

 

How to duplicate a 3D object from one marker to another marker i

January 25, 2014 - 7:52pm #3
using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour, ITrackableEventHandler{

private TrackableBehaviour mTrackableBehaviour;
private bool duplicateObject = false;
public GameObject pickedObject;
public GameObject childObject = null;
public GameObject parentObject ;

// Use this for initialization
void Start () {
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour){
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}

}

public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus,TrackableBehaviour.Status newStatus){
if (newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED){
duplicateObject = true;
Debug.LogError("True111111");
onDuplicat();
}else{
duplicateObject = false;
}
}

// Update is called once per frame

void onDuplicat(){
Debug.LogError("True33333");
if (duplicateObject){
Debug.LogError("True2222222");
childObject = Instantiate(pickedObject.gameObject,new Vector3(0,0,0),Quaternion.identity) as GameObject;
childObject.gameObject.transform.parent = parentObject.transform;
childObject.transform.localPosition = new Vector3(0,0,0);
Debug.LogError("The parent: "+ childObject.gameObject.transform.parent +"!!!");
}

}
}

 

Hi, this is the code i have done.

The problem is i cannot see the gameObject in runtime

How to duplicate a 3D object from one marker to another marker i

January 23, 2014 - 12:13am #2

Hi, 

not sure I fully understand what you are trying to achieve; could you explain it a bit more clearly?

 

Log in or register to post comments