cancel
Showing results for 
Search instead for 
Did you mean: 

Scaling imported models

Hey,

 I am toying with the LaserGun from the tutorial and trying to replace the example assets with custom models. For some reason the mesh I am importing for the LaserShot replacement is not scaling. All I am trying to do is replace the cylinder with a model that has an emission material on it.

I have tested using a primitive cylinder from the shapes menu and it scales fine, albeit on the wrong axis, but easily fixable. The gravity, physics and collisions are set correctly as the example LaserShot.

The code makes sense and I've ran various debugs to make sure things are calculating correctly:

var thisEntityScaleY = this.entity.scale.get().y;
        console.log("thisEntityScaleY = " + thisEntityScaleY)
        var laserBeamScale = this.props.laserBeam.scale.get();
        laserBeamScale.x = this.props.laserBeamWidth;
        laserBeamScale.y = laserLength / thisEntityScaleY;
        console.log("laserBeamScale.y = " + laserBeamScale.y)
        laserBeamScale.z = this.props.laserBeamWidth;
        this.props.laserBeam.scale.set(laserBeamScale);
        this.props.laserBeam.color.set(Color.red);

        this.props.laserBeam.moveRelativeTo(this.entity, new Vec3(0, laserLength / (2 * thisEntityScaleY), 0));
 
I had this working quite early on but as I've been changing things I can't for the life of me work out what I am doing wrong. 
 
To put it simply I am trying to create a laser beam with emission on a custom weapon.
Any help is greatly appreciate. 
1 ACCEPTED SOLUTION

Accepted Solutions

Seems to be working now, so what I believe was the issue came down to using "replace" and "update" of the model after changing pivot points. It is a nested object. I am not sure if that is a known bug, but happy to log it if anyone wants to point me in the right direction.

There was also a large offset from
this.props.laserBeam.moveRelativeTo(this.entitynew Vec3(0laserLength / (2 * thisEntityScaleY), 0))

I settled with the Y value of Vec3 set to thisEntityScaleY and it looks fine. Also worked well just setting it to 1.

Phew, now I can move on 😅 Thanks for the response @SeeingBlue 😎

View solution in original post

3 REPLIES 3

SeeingBlue
Mentor

I suspect the scale of the cylinder you import is not the same scale of the previous cylinder. When you have you cylinder in blender, make sure the dimensions say 1,1,1 then apply the scale. You can fix rotation this way too.

Upcoming Events:
Performance Pro - UI Unleashed - Building Responsive & Performant Interfaces Thursday June 19th 5:00 PM PT - Register
June Programming Calendar

Yes it's something to do with the model. The scale is 1,1,1 and all transforms applied in Blender. I'm trying different pivots atm... It's doing something, just not what I want. I think previously the scaling was happening out of sight from the camera.

Seems to be working now, so what I believe was the issue came down to using "replace" and "update" of the model after changing pivot points. It is a nested object. I am not sure if that is a known bug, but happy to log it if anyone wants to point me in the right direction.

There was also a large offset from
this.props.laserBeam.moveRelativeTo(this.entitynew Vec3(0laserLength / (2 * thisEntityScaleY), 0))

I settled with the Y value of Vec3 set to thisEntityScaleY and it looks fine. Also worked well just setting it to 1.

Phew, now I can move on 😅 Thanks for the response @SeeingBlue 😎