Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TextGeometry在Three.js中的性能_Javascript_Performance_Text_3d_Three.js - Fatal编程技术网

Javascript TextGeometry在Three.js中的性能

Javascript TextGeometry在Three.js中的性能,javascript,performance,text,3d,three.js,Javascript,Performance,Text,3d,Three.js,我需要在场景中有超过400个文本对象。每个文本对象是一个带两位数的十进制数的句子。Echa文本正在从JSON文件读取。每个文本对象在场景中都有一个位置x、y、z 使用我的基本场景,加载每个文本需要很多时间 代码如下: function setText(text, textColor, textSize, positionX, positionY, positionZ) { var textGeo = new THREE.TextGeometry(text, {

我需要在场景中有超过400个文本对象。每个文本对象是一个带两位数的十进制数的句子。Echa文本正在从JSON文件读取。每个文本对象在场景中都有一个位置x、y、z

使用我的基本场景,加载每个文本需要很多时间

代码如下:

function setText(text, textColor, textSize, positionX, positionY, positionZ) {        
    var  textGeo = new THREE.TextGeometry(text, {
        height: 0,
        curveSegments: 4,
        font: "helvetiker",
        //font: "optimer",
        weight: "normal",
        style: "normal",
        size: textSize,
        //
        //bevelThickness: bevelThickness,
        //bevelSize: bevelSize,
        //bevelEnabled: bevelEnabled,
        material: 0,
        extrudeMaterial: 1
    });

    textGeo.computeBoundingBox();
    textGeo.computeVertexNormals();

    var textMaterial = new THREE.MeshBasicMaterial({ 
        shading: THREE.FlatShading, 
        transparent: true,
        depthWrite: false,
        transparent: true,
        needsUpdate: true,
        color: textColor, 
        side:THREE.DoubleSide
    }); 

    var text = new THREE.Mesh(textGeo, textMaterial);
    text.position.x = positionX;
    text.position.y = positionY;
    text.position.z = positionZ;
    return text;
}
文本示例:

"model", "metamodel", "syntax", "sentence" ...
数字示例:

    7.32, 
    7.81, 
    8.30, 
    8.78, 
你能帮帮我吗?谢谢

编辑:新代码如下:

    function createTextGeo(textSize, text) {
        var tGeo = new THREE.TextGeometry(text, {
            height: 0,
            curveSegments: 4,
            font: "helvetiker",
            weight: "normal",
            style: "normal",
            size: textSize,
            material: 0,
            extrudeMaterial: 1
        });

        tGeo.computeBoundingBox();
        tGeo.computeVertexNormals();
        return tGeo;
    }

    function createGeoMaterial(textColor) {
        var tMat = new THREE.MeshBasicMaterial({
            color: textColor,
        });
        return tMat;
    }

    function setText(text, textColor, tMat, tGeo, X, Y, Z) {
        tMat.color = textColor;
        tGeo.text = text;

        var text = new THREE.Mesh(tGeo, tMat);
        text.position.set( X, Y, Z );
        return text;
    }

    function createTexts(value) {
        var text;
        var mesh;
        var x = 5;
        var y = 8;
        var z = 10;
        var keyColor = new THREE.Color('#0B0B61');
        var tMat = createGeoMaterial(keyColor);
        var tGeo = createTextGeo(5, "");

        for (var i = 0; i < value; i++) {
            mesh = setText(i, keyColor, tMat, tGeo, x * i, y * i, z * i);
            scene.add(mesh);
        }
    }

无论哪种方式,当你计算大量几何体时,你都会遇到问题,看看你也可以分离你的json文件,在需要的时候加载你只需要的东西,优化并确定优先级…@Careen我正在尝试优化和确定我的代码的优先级,但是数字和文本是图表中比例的一部分。你是另一个想法吗?计算大量的几何图形,看看共享材质,而不是为每个材质创建新的实例text@Careen你能说得更准确些吗。也许你可以给我举个小例子。你能恢复我的部分代码吗?谢谢