Log in or register to post comments

[Help] Resize Model

April 18, 2013 - 4:57pm #1

 

Hello
 
I have a problem to solve regarding the Resize Model.
 
Now I press the button to increase the size, Model, but when I press the button, the Model is missing from the Marker, I just press the button to reduce the size Model.
 
Model shows the same, which is to increase and decrease the size of each is equal to 0.3. 
 
Anyone can help me, one at a time.
 
This is my Code : 
using System;
using UnityEngine;
using System.Collections;
 
public class ButtonZoomCap : MonoBehaviour {
    public Texture zoominpic;
    public Texture zoomoutpic;
    public Texture capturepic;
    public float sW;
    public float sH;
    public bool mCap,mZoom;
    private int screenshotCount = 0;
    public GameObject teapot;
    private Vector3 tempScale;
     
    void Start () {
     
    }
     
    // Update is called once per frame
    void Update () {
        if (Input.GetKeyDown(KeyCode.Escape)) 
        { 
            Application.Quit(); 
        }
    }
     
    void OnGUI() {
        if (GUI.Button (new Rect (Screen.width - 100,Screen.height - 70,100,100), zoominpic)) {
            scaleup();
        }   
        if (GUI.Button (new Rect (Screen.width - 200,Screen.height - 70,100,100), zoomoutpic)) {
            scaledown();
        }
         
    }
     
    private void scaleup(){
        teapot.transform.localScale += new Vector3(0.3F, .3F, .3F); 
    }
     
    private void scaledown(){
        teapot.transform.localScale -= new Vector3(0.3F, .3F, .3F); 
    }
}

 

 

[Help] Resize Model

April 21, 2013 - 8:23am #13

you're welcome

[Help] Resize Model

April 21, 2013 - 8:10am #12

I do, thank you very much.

[Help] Resize Model

April 21, 2013 - 6:42am #11

Hi,

this is the whole script that I have quickly implemented to perform the scale up and scale down;

You can try it with the ImageTargets sample, by attaching this script to the ARCamera; the script shows 2 buttons, one to scale up and 1 to scale down;

note: the script looks for a gameObject called "teapot" in the Start() method (as you will see in the code); just adjust that code if you are using a different name or a different technique to identify your gameObject; 

I just tested this and it scale the teapot up and down nicely:

public class ModelTransformer : MonoBehaviour {

	private Transform mTeapotTransform = null;
	
	private float mScaleFactor = 1;
	private bool mUpdateTransform = false;
	
	// Use this for initialization
	void Start () {
		GameObject go = GameObject.Find("teapot");
		if (go != null) {
			Debug.Log ("found teapot game object");
			mTeapotTransform = go.transform;
		}
	}
	
	// Update is called once per frame
	void Update () {
		if (mUpdateTransform) {
			Debug.Log ("updating transform");
			mTeapotTransform.localScale = 
             new Vector3(mScaleFactor, mScaleFactor, mScaleFactor);
			mUpdateTransform = false;
		}
	}
	
	void OnGUI() {
		if (GUI.Button(new Rect(0,100, 140, 70), "Scale Up")) {
			scaleUp();
		}
		if (GUI.Button(new Rect(0,200, 140, 70), "Scale Down")) {
			scaleDown();
		}
	}
	
	void scaleUp() {
		if (mTeapotTransform != null) {
			Debug.Log ("scale up");
			mScaleFactor = mTeapotTransform.localScale.x;
			mScaleFactor *= 1.5f;
			
			mUpdateTransform = true;
		}
	}
	
	void scaleDown() {
		if (mTeapotTransform != null) {
			Debug.Log ("scale down");
			mScaleFactor = mTeapotTransform.localScale.x;
			mScaleFactor *= 0.67f;
			
			mUpdateTransform = true;
		}
	}	
}

I hope this helps.

[Help] Resize Model

April 21, 2013 - 1:02am #10

AlessandroB wrote:

Yes, but you should first try to set a constant scale, to see if you see the model; then, if it works, in order to increase the scale I would rather use a scaleFactor and incease the scale factor, somehing like:

scaleFactor += 0.3f;

localScale = new Vector3( scaleFactor, scaleFactor, scaleFactor );

Note: you can declare scaleFactor in your class like:

private float scaleFactor = 1.0f;

 

 

 

 

 

I've done as you suggest, then it's back to the original problem is that when the press the Add Marker is missing from the Model size. 
 
If you have made. The problem does not occur, like me. How do I get to see your Code?

[Help] Resize Model

April 21, 2013 - 12:48am #9

Yes, but you should first try to set a constant scale, to see if you see the model; then, if it works, in order to increase the scale I would rather use a scaleFactor and incease the scale factor, somehing like:

scaleFactor += 0.3f;

localScale = new Vector3( scaleFactor, scaleFactor, scaleFactor );

Note: you can declare scaleFactor in your class like:

private float scaleFactor = 1.0f;

 

 

 

[Help] Resize Model

April 21, 2013 - 12:35am #8

AlessandroB wrote:

Hi, consider this line:

teapot.transform.localScale += new Vector3(0.3F, .3F, .3F);

could you replace it with and see if the model disappear (not the "=" instead of the "+=") ?:

teapot.transform.localScale = new Vector3(0.3F, .3F, .3F);

Could you also try setting different scale values ?

 

 

I need to put the "+=", because I need to scale it, increasingly, when I press the button to increase the size.

[Help] Resize Model

April 21, 2013 - 12:31am #7

Hi, consider this line:

teapot.transform.localScale += new Vector3(0.3F, .3F, .3F);

could you replace it with and see if the model disappear (not the "=" instead of the "+=") ?:

teapot.transform.localScale = new Vector3(0.3F, .3F, .3F);

Could you also try setting different scale values ?

 

[Help] Resize Model

April 21, 2013 - 12:16am #6

AlessandroB wrote:

Hi, it sounds like a basic Unity question, not very much about Vuforia (there is nothing in Vuforia that prevents you from scaling an object, but you need to be sure that the gameObject that you rescale is a child of the Marker or Target object, or a child of a child, but not the ImageTarget or the Marker itself);

 

 

Yes, it is the basis of Unity but I have implemented the AR is to increase the size and reduce the size of the Model, which I can add size and shrink it, but when I press the increase or decrease the size, Model, it will disappear from the Marker, I think it is likely to be about Vuforia, and I think you can help me.

[Help] Resize Model

April 20, 2013 - 1:12pm #5

Hi, it sounds like a basic Unity question, not very much about Vuforia (there is nothing in Vuforia that prevents you from scaling an object, but you need to be sure that the gameObject that you rescale is a child of the Marker or Target object, or a child of a child, but not the ImageTarget or the Marker itself);

 

[Help] Resize Model

April 20, 2013 - 3:08am #4

Now I'm not able to increase the size of Model.

When I press the button to increase the size Marker is missing from the Model it. but if I press the button to reduce the size of the original Model only comes back the same.

I would like to know why so much of what

I use the Unity Pro 4.1.2 and applied development of Android

 

Help me please I can't continue to Function.

[Help] Resize Model

April 19, 2013 - 10:25am #3

Anyone can help me solve the problem?

[Help] Resize Model

April 19, 2013 - 4:31am #2

Help me please

Log in or register to post comments