How to set An gltf model z scale?

662 views
Skip to first unread message

liuxup...@gmail.com

unread,
Jun 29, 2017, 4:01:32 AM6/29/17
to cesium-dev
I have learn about load gltf model, now I want know How to set z scale ?

this is my code:

var entity = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(121.466, 31.234, 200),
orientation: orientation,
model: {
//uri: 'SampleData/models/CesiumGround/Cesium_Ground.gltf',
uri: '地层/feature_53.gltf',
nodeTransformations: {
CLR1400000010703000000_54:{
scale: new Cesium.Cartesian3(1, 1, 10000)
}


}


}
});
viewer.zoomTo(entity);

there is an node by name in my gltf file. but set 10000 does not affect.

Kangning Li

unread,
Jun 29, 2017, 9:55:30 AM6/29/17
to cesium-dev, liuxup...@gmail.com
According to the ModelGraphics documentation, nodeTransformations should be a Cesium.TranslationRotationScale object instead of just a Cartesian3. See http://cesiumjs.org/Cesium/Build/Documentation/TranslationRotationScale.html.
 
Message has been deleted
Message has been deleted

liuxup...@gmail.com

unread,
Jun 29, 2017, 9:13:43 PM6/29/17
to cesium-dev, liuxup...@gmail.com
在 2017年6月29日星期四 UTC+8下午9:55:30,Kangning Li写道:
> According to the ModelGraphics documentation, nodeTransformations should be a Cesium.TranslationRotationScale object instead of just a Cartesian3. See http://cesiumjs.org/Cesium/Build/Documentation/TranslationRotationScale.html.
>  

Thank you! I set it as an TranslationRotationScale object, but it does not affect.

liuxup...@gmail.com

unread,
Jun 29, 2017, 9:15:40 PM6/29/17
to cesium-dev, liuxup...@gmail.com
在 2017年6月29日星期四 UTC+8下午9:55:30,Kangning Li写道:

liuxup...@gmail.com

unread,
Jun 29, 2017, 9:17:40 PM6/29/17
to cesium-dev, liuxup...@gmail.com
在 2017年6月29日星期四 UTC+8下午9:55:30,Kangning Li写道:
> According to the ModelGraphics documentation, nodeTransformations should be a Cesium.TranslationRotationScale object instead of just a Cartesian3. See http://cesiumjs.org/Cesium/Build/Documentation/TranslationRotationScale.html.
>  

var r = new Cesium.TranslationRotationScale(Cesium.Cartesian3.ZERO, Cesium.Quaternion.IDENTITY,new Cesium.Cartesian3(1, 1, 10000));

var entity = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(121.466, 31.234, 200),
orientation: orientation,
model: {
//uri: 'SampleData/models/CesiumGround/Cesium_Ground.gltf',
uri: '地层/feature_53.gltf',
nodeTransformations: {
'CLR1400000010703000000_54': r
}


}
});

liuxup...@gmail.com

unread,
Jun 29, 2017, 11:56:01 PM6/29/17
to cesium-dev
在 2017年6月29日星期四 UTC+8下午9:55:30,Kangning Li写道:
> According to the ModelGraphics documentation, nodeTransformations should be a Cesium.TranslationRotationScale object instead of just a Cartesian3. See http://cesiumjs.org/Cesium/Build/Documentation/TranslationRotationScale.html.
>  

Thank you! I set it as an TranslationRotationScale object, but it does not affect:

var r = new Cesium.TranslationRotationScale(new Cesium.Cartesian3(1, 1, 1000), Cesium.Quaternion.IDENTITY,new Cesium.Cartesian3(1, 1, 1000000));

var entity = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(121.466, 31.234, 200),
orientation: orientation,
model: {
//uri: 'SampleData/models/CesiumGround/Cesium_Ground.gltf',
uri: '地层/feature_53.gltf',
nodeTransformations: {
'"CLR1400000010704000000_1': r
}
}
});

Kangning Li

unread,
Jun 30, 2017, 9:24:08 AM6/30/17
to cesium-dev
Sorry, I just realized that the documentation says nodeTransformations needs to be a PropertyBag: http://cesiumjs.org/Cesium/Build/Documentation/ModelGraphics.html#nodeTransformations

Here's the documentation for PropertyBag: http://cesiumjs.org/Cesium/Build/Documentation/PropertyBag.html

Can you give that a try?

nodegis

unread,
Jun 30, 2017, 9:43:52 AM6/30/17
to cesium-dev
Thank you, does not affect too, I Try it as that:
var trs = new Cesium.TranslationRotationScale(new Cesium.Cartesian3(1, 1, 1000), Cesium.Quaternion.IDENTITY,new Cesium.Cartesian3(1, 1, 1000000));

    var entity = viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(121.466, 31.234, 200),
        orientation: orientation,
        model: {
            //uri: 'SampleData/models/CesiumGround/Cesium_Ground.gltf',
            uri: '地层/feature_53.gltf',
            nodeTransformations: new Cesium.PropertyBag({
                CLR1400000010704000000_1: trs
            })
        }
    });



在 2017年6月30日星期五 UTC+8下午9:24:08,Kangning Li写道:

nodegis

unread,
Jun 30, 2017, 9:49:27 AM6/30/17
to cesium-dev

Is there any other way to set z scale for gltf model?


在 2017年6月30日星期五 UTC+8下午9:24:08,Kangning Li写道:
Sorry, I just realized that the documentation says nodeTransformations needs to be a PropertyBag: http://cesiumjs.org/Cesium/Build/Documentation/ModelGraphics.html#nodeTransformations

Kangning Li

unread,
Jun 30, 2017, 10:25:43 AM6/30/17
to cesium-dev
Hmmm, you can edit the gltf itself, but it seems odd that this doesn't work. Here's the specification: https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#transforms

Can you share the model? I can think of a couple possibilities too where something in the model doesn't let it transform correctly.

nodegis

unread,
Jul 2, 2017, 9:29:35 PM7/2/17
to cesium-dev
model file been uploaded, you can try it again with that code:
var trs = new Cesium.TranslationRotationScale(new Cesium.Cartesian3(1, 1, 1), Cesium.Quaternion.IDENTITY,new Cesium.Cartesian3(1, 1, 10));
var heading = Cesium.Math.toRadians(0);
var pitch = Cesium.Math.toRadians(0.0);
var roll = Cesium.Math.toRadians(0.0);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(Cesium.Cartesian3.fromDegrees(-71, 22, 0), new Cesium.HeadingPitchRoll(heading, pitch, roll));
var holes = viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(-71, 22, 500),
        orientation: orientation,
        model: {
            uri: 'test-z.gltf',
           nodeTransformations: new Cesium.PropertyBag({
                TEX1400000010101000000: trs
            })


        }
    });




在 2017年6月30日星期五 UTC+8下午10:25:43,Kangning Li写道:
test-z.gltf

Kangning Li

unread,
Jul 3, 2017, 10:35:39 PM7/3/17
to cesium-dev
My mistake... it looks like the code you posted as well as the 3D models example in Sandcastle is using the Entity API from this tutorial: https://cesiumjs.org/tutorials/Visualizing-Spatial-Data/, which doesn't seem to have full support for modifying model transformations yet.

Is it sufficient to scale entire models? That can be done by modifying this earlier method for placing models: https://cesiumjs.org/tutorials/3D-Models-Tutorial/

Here's the code with the changes I made:

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;


var scaleMatrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(1.0, 1.0, 5.0));


var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
   
Cesium.Cartesian3.fromDegrees(-75.62898254394531, 40.02804946899414, 0.0));
var model = scene.primitives.add(Cesium.Model.fromGltf({
    url
: '../../SampleData/models/CesiumGround/Cesium_Ground.gltf',
    modelMatrix
: Cesium.Matrix4.multiply(modelMatrix, scaleMatrix, modelMatrix),
    scale
: 10.0
}));


viewer
.camera.setView({
    destination
: Cesium.Cartesian3.fromDegrees(-75.62898254394531, 40.02804946899414, 300.0),
    orientation
: {
        heading
: 0.0,
        pitch
: -Cesium.Math.PI_OVER_TWO,
        roll
: 0.0
   
}
});



Kangning Li

unread,
Jul 3, 2017, 11:05:08 PM7/3/17
to cesium-dev
Ah. You might also be able to modify the model's nodeTransformations after the entity has already been created.
Take a look at this Sandcastle example which modifies other properties like model's color and outlining:

nodegis

unread,
Jul 4, 2017, 2:16:20 AM7/4/17
to cesium-dev
Wow! Well, my problem is solved, thank you very much. I wish you a happy life!

在 2017年7月4日星期二 UTC+8上午10:35:39,Kangning Li写道:
Reply all
Reply to author
Forward
0 new messages