how to create custom geometry ,sucess in versio b29,but failed in latest version

the code run success in version b29 is below:

  var TetrahedronGeometry = function(){
      var negativeRootTwoOverThree = -Math.sqrt(2.0) / 3.0;
        var negativeOneThird = -1.0 / 3.0;
        var rootSixOverThree = Math.sqrt(6.0) / 3.0;
        
        //四面体的四个顶点
        var positions = new Float64Array(4 * 3);

        // position 0
        positions[0] = 0.0;
        positions[1] = 0.0;
        positions[2] = 1.0;

        // position 1
        positions[3] = 0.0;
        positions[4] = (2.0 * Math.sqrt(2.0)) / 3.0;
        positions[5] = negativeOneThird;

        // position 2
        positions[6] = -rootSixOverThree;
        positions[7] = negativeRootTwoOverThree;
        positions[8] = negativeOneThird;

        // position 3
        positions[9] = rootSixOverThree;
        positions[10] = negativeRootTwoOverThree;
        positions[11] = negativeOneThird;

        var attributes = new Cesium.GeometryAttributes({
            position : new Cesium.GeometryAttribute({
                componentDatatype : Cesium.ComponentDatatype.DOUBLE,
                componentsPerAttribute : 3,
                values : positions
            })
        });

        //顶点索引
        var indices = new Uint16Array(4 * 3);

        // back triangle
        indices[0] = 0;
        indices[1] = 1;
        indices[2] = 2;

        // left triangle
        indices[3] = 0;
        indices[4] = 2;
        indices[5] = 3;

        // right triangle
        indices[6] = 0;
        indices[7] = 3;
        indices[8] = 1;

        // bottom triangle
        indices[9] = 2;
        indices[10] = 1;
        indices[11] = 3;
        
        //包围球
        var boundingSphere = new Cesium.BoundingSphere(new Cesium.Cartesian3(0.0,0.0,0.0),1.0);

        var geometry = Cesium.GeometryPipeline.computeNormal(new Cesium.Geometry({
            attributes: attributes,
            indices: indices,
            primitiveType: Cesium.PrimitiveType.TRIANGLES,
            boundingSphere: boundingSphere
        }));

        this.attributes = geometry.attributes;
        this.indices = geometry.indices;
        this.primitiveType = geometry.primitiveType;
        this.boundingSphere = geometry.boundingSphere;
        //this.boundingSphere = Cesium.BoundingSphere.fromVertices(positions);
    };

    var cesiumWidget = new Cesium.CesiumWidget('cesiumContainer');
    var scene = cesiumWidget.scene;
    var ellipsoid = cesiumWidget.scene.globe.ellipsoid;
    
    //模型矩阵
    var modelMatrix = Cesium.Matrix4.multiplyByUniformScale(
            Cesium.Matrix4.multiplyByTranslation(
                    Cesium.Transforms.eastNorthUpToFixedFrame(ellipsoid.cartographicToCartesian(
                            Cesium.Cartographic.fromDegrees(-100.0, 40.0))),
                    new Cesium.Cartesian3(0.0, 0.0, 200000.0)),
            500000.0);
    
    //四面体的实例
var instance = new Cesium.GeometryInstance({
        geometry : Cesium.GeometryPipeline.toWireframe(new TetrahedronGeometry()),
        modelMatrix : modelMatrix,
        attributes : {
            color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.WHITE)
        }
    });
    
    //加入场景
    scene.primitives.add(new Cesium.Primitive({
        geometryInstances : instance,
        appearance : new Cesium.PerInstanceColorAppearance({
            flat : true,
            translucent : false
        })
    }));

I want add polygon with self defined indices,to disply all partition in right height. can any one tell me how to add self defined geometry in the latest version or add polygon with self defined indices.thanks!

Hi there,

Looks like the issue was in your calls of Cesium.Matrix4.multiplyByUniformScale and Cesium.Matrix4.multiplyByTranslation, which both require a result parameter. I’ve pasted a working example here: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Hello%20World.html&label=Showcases

Hope that helps!

  • Rachel

after the matric,there is a new problem _workerName must be defined for asynchronous geometry 😣

Hi there,

Luckily this is an easy fix: Disable asynchronous primitive create by passing [options.asynchronous: false] to the Primitive constructor. This means that when you add a new primitive, Cesium will not render until it is ready.

Hope that helps!

  • Rachel

Hi,
I'm having the same initial issue as 文文武 with , but I can't seem to access the example you posted (the javascript code section is just the cesium.viewer line). Do you think you could repost it? I'm getting a developer error when I put a new matrix4 object as the "result" parameter for both of those functions.
Thanks
- Abhi

Wait actually it seems to work now. I think I was putting "new cesium.matrix4" in the wrong place. ignore my previous question.

Dear everyone!,

I also have this issue, do not display this gemetry.

Could you please help me post your solution?

Thank you very much!

Vào 16:04:33 UTC+7 Thứ Năm, ngày 27 tháng 4 năm 2017, wenwu2...@gmail.com đã viết: