编辑 3D 模型的零件尺寸



我想开发一个网络应用程序来输入一个人的测量值并显示带有这些测量值的3D模型。我选择了三个.js来启动它。我从 clara.io 下载了一个名为standard-male-figure的3D模型。这是我显示人体模型的代码。

import React, { Component } from "react";
import PropTypes from "prop-types";
import withStyles from "@material-ui/core/styles/withStyles";
import * as THREE from "three-full";
const styles = (/*theme*/) => ({
});
class ThreeDView extends Component {
    constructor(props){
        super(props);

        this.start = this.start.bind(this);
        this.stop = this.stop.bind(this);
        this.renderScene - this.renderScene.bind(this);
        this.animate = this.animate.bind(this);
    }
    componentDidMount() {

        const width = this.mount.clientWidth;
        const height = this.mount.clientHeight;
        //ADD SCENE
        this.scene = new THREE.Scene();
        //ADD CAMERA
        this.camera = new THREE.PerspectiveCamera(100,1);
        this.camera.position.z = 12;
        this.camera.position.y = 0;
        this.camera.position.x = 0;
        //ADD RENDERER
        this.renderer = new THREE.WebGLRenderer({ antialias: true });
        this.renderer.setClearColor("#f0f0f0");
        this.renderer.setSize(width, height);
        this.mount.appendChild(this.renderer.domElement);
        // MOUSE ROTATION
        this.orbit = new THREE.OrbitControls(this.camera,this.renderer.domElement);
        this.orbit.update();
        //ADD LIGHTS
        this.light = new THREE.PointLight(0xffffff,1.3);
        this.light.position.z = 10;
        this.light.position.y=20;
        this.scene.add(this.light);
        // ADD MAN FIGURE
        const loader = new THREE.ColladaLoader();
        loader.load("/models/standard-male-figure.dae",(manFigure)=>{
            this.man = manFigure;
            this.man.name = "man-figure";
            this.man.scene.position.y = -10;
            this.scene.add(this.man.scene);
        },undefined,()=>alert("Loading failed"));

        this.start();
    }
    componentWillUnmount() {
        this.stop();
        this.mount.removeChild(this.renderer.domElement);
    }
    start() {
        if (!this.frameId) {
            this.frameId = requestAnimationFrame(this.animate);
        }
    }
    stop () {
        cancelAnimationFrame(this.frameId);
    }
    animate () {
        this.renderScene();
        this.frameId = window.requestAnimationFrame(this.animate);
    }
    renderScene () {
        this.orbit.update();
        this.light.position.z = this.camera.position.z;
        this.light.position.y=this.camera.position.y+20;
        this.light.position.x=this.camera.position.x;
        this.renderer.render(this.scene, this.camera);
    }

    render() {

        return (
            <div style={{ height: "640px" }} ref={(mount) => { this.mount = mount; }} >
            </div>
        );
    }
}
ThreeDView.propTypes = {
    values: PropTypes.object
};
/*
all values in inches
values = {
 heightOfHand:10,
 , etc..
}
*/
export default withStyles(styles)(ThreeDView);

是用户输入的度量值。我不知道如何开始使用这些测量值更新 3D 模型。请给我一个起点或任何建议来完成这个。谢谢!。

首先,您可以获得您的男人的当前大小和规模

const box = new THREE.Box3().setFromObject(this.man)
const currentObjectSize = box.getSize()
const currentObjectScale = this.man.scale

当用户更新尺寸值(newSize(时,您可以为您计算新的比例

const newScale = new THREE.Vector3(
    currentObjectScale.x * newSize.x/currentObjectSize.x,
    currentObjectScale.y * newSize.y/currentObjectSize.y,
    currentObjectScale.z * newSize.z/currentObjectSize.z
)

并用这个秤更新你的男人

this.man.scale.set(newScale.x, newScale.y, newScale.z)

相关内容

  • 没有找到相关文章

最新更新