CESIUMJS Development Practice (vii) 3D model

Source: Internet
Author: User

The 3D model is supported in cesium, but only the GLTF format is supported. GLTF is an Exchange format defined by the Khronos organization (the one that drafted the OpenGL standard) for displaying 3d content on the Internet or on mobile devices, fully supporting the Opengl,webgl,opengles graphics acceleration standard.

GLTF can now be converted from the Collada format, and a conversion tool (HTTPS://WWW.KHRONOS.ORG/GLTF) is also available on the official website. This tool compared to the pit father, only and Collada files in the same directory to work, the converted result file must also be in the same directory, that is, can not specify the input and output path, the pit of my long time to find.

A Collada file is converted to 4 files, one. Bin, one. JSON, two. GLSL. json files are descriptive files,. bin is the actual data, and two GLSL files are vertex-shaded language files. Deploy the directories on the Web server to which the files reside. Add on client Side

var ellipsoid = viewer.scene.globe.ellipsoid;var cart3 =  Ellipsoid.cartographictocartesian (Cesium.Cartographic.fromDegrees (lng, lat, height));var  Modelmatrix = cesium.transforms.eastnorthuptofixedframe (CART3);var quat =  Cesium.Quaternion.fromAxisAngle (Cesium.cartesian3.unit_z, cesium.math.toradians (rotate - 90)); Var mat3 = cesium.matrix3.fromquaternion (Quat);var mat4 =  Cesium.Matrix4.fromRotationTranslation (Mat3, cesium.cartesian3.zero);var m =  Cesium.Matrix4.multiplyTransformation (MODELMATRIX, MAT4);//Obtain the final transformation matrix, referring to the author's previous written "Coordinate transformation" chapter var model =  viewer.scene.primitives.add (CESIUM.MODEL.FROMGLTF ({url :  ' Http://localhost:88/gltf/tower.json ' ,///conversion of 4 files in the JSON file modelmatrix : m, //add the Model transformation matrix, in order to display in the correct position, otherwise killed can not find, is placed in a corner of the Earth scale:1.0 // magnification}));//After the model is loaded, play Model.readyToRender.addEventListener (model)  {//&NB If there is an animationSp Play and loop all animations at half-speadmodel.activeanimations.addall ({speedup  : 0.5,loop : cesium.modelanimationloop.repeat});

Effects after loading a model

The model shows whether the smoothness is closely related to the number of triangular faces of the model, machine configuration, and browser version. Browsers recommend using Chrome30.0 above.

This is the end of this article



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.