0
votes

I have a platter which represents a pedestal for 3D model. It has meshfilter/meshrenderer/meshcollider components. My model comes from the server and it consists of many parts and they have an empty game object as a parent called "3dModel". The scale of the parent is 1.1.1. Every part has the same components as the platter. But model bigger or smaller than the platter. There is the issue - rescale "3DModel" container to fix the platter size. The scale of the platter is 1.1.1 but model has 0.1,0.1,0.1 scale and the same time it 20 times bigger than the platter. Also, I am denied fixing scale on the server. Probably having meshes there is the way to calculate size? The main problem is that models come from the server and every time it comes with different scale. For example, now I have an apple with 0.1 0.1 0.1 scale but it larger the plate 20 times. Next time I have a banana with 1 1 1 scale and it's very very small. I am not allowed to change any values on the server side.The task is to do it programmatically. enter image description here

1
Are you saying that the model is stored on the server with a scale of 0.1, 0.1, 0.1? Why not store as 1,1,1? When importing, model should be scaled as 1,1,1 so that it is normalized. You can then set it to the same scale as the parent container. - JMadelaine
The customer doesn't allow change any values on the server side. It has to be done programmatically - that's the customer's task. - Helliodon
I think your issue is that you are talking about scale when what you first need to consider is size. If the size of the image is much larger than the size of the platter, scaling both to the same scale will not help. You need to calculate the size that you want the image to be and then set the scale appropriately. - JMadelaine
Why are you talking about IMAGE? There wasn't any word about Image. I am working with 3D models. BTW I solved my problem. I used bounds.incapsulate method to collect all bounds for a 3d model which consist of many parts. Then I find out the difference between bound of the platter and 3d model and just rescale 3d model container to fit the platter size. But thank you for your time. - Helliodon

1 Answers

0
votes

I'm not sure I understand your problem, but if you just need to scale an object in the C# (based on the parent scale) you just need something like this:

yourgameobjectchild.transform.localScale = new Vector3(yourgameobjectchild.transform.parent.localscale.x + variabletochangethescale, yourgameobjectchild.transform.parent.localscale.y, yourgameobjectchild.transform.parent.localscale.z);