Search in sources :

Example 1 with JmeThread

use of com.cas.sim.tis.anno.JmeThread in project TeachingInSimulation by ScOrPiOzzy.

the class TypicalCaseState method putDown.

/**
 * 将一个元器件放置在电路板上
 */
@JmeThread
public void putDown() {
    // 取消Holding的模型对鼠标透明
    JmeUtil.setMouseVisible(holding, true);
    try {
        if (ElecComp.COMBINE_TOP == elecComp.getCombine()) {
            // 需要底座的元器件不可直接加入电路板
            Platform.runLater(() -> {
                AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("alert.warning.base.need"));
            });
            holding.removeFromParent();
        } else {
            // 1、获取相应元器件
            ElecCompDef elecCompDef = SpringUtil.getBean(ElecCompAction.class).parse(elecComp.getCfgPath());
            elecCompDef.setElecComp(elecComp);
            // 2、将元器件模型与元器件对象一起加入电路板中
            circuitState.attachToCircuit(holding, elecCompDef);
        }
    } catch (Exception e) {
        // 删除出错的模型
        holding.removeFromParent();
        LOG.error("初始化元器件{}时出现了一个错误:{}", elecComp.getModel(), e.getMessage());
        e.printStackTrace();
    } finally {
        holding = null;
        elecComp = null;
        cameraState.setZoomEnable(true);
    }
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) ElecCompAction(com.cas.sim.tis.action.ElecCompAction) JmeThread(com.cas.sim.tis.anno.JmeThread)

Example 2 with JmeThread

use of com.cas.sim.tis.anno.JmeThread in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompState method setElecComp.

@JmeThread
public void setElecComp(ElecComp elecComp) {
    // clean up
    cleanRoot();
    // 加载模型(认知模块使用AnimPath的model)
    Spatial model = loadAsset(new ModelKey(elecComp.getAnimPath()));
    // PBR能在系统中被照亮
    // MikktspaceTangentGenerator.generate(model);
    // 将模型放大100倍
    model.scale(100);
    root.attachChild(model);
    // 
    // 获取相应元器件
    ElecCompDef elecCompDef = SpringUtil.getBean(ElecCompAction.class).parse(elecComp.getCfgPath());
    // 找出元器件外壳模型名称
    loadShell(elecCompDef.getParam(ElecCompDef.PARAM_KEY_SHELL));
    // FIXME 这里应更为精准地设置为元器件模型。
    elecCompDef.bindModel(root);
    // 添加事件
    Map<Spatial, String> nameMap = collectName(elecCompDef);
    nameMap.entrySet().forEach(e -> addListener(e.getKey(), new MouseEventAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            if (!pickEnable) {
                return;
            }
            // FilterUtil.showOutlineEffect(evt.getSpatial());
            System.out.println("ElecCompState.setElecComp(...).new MouseEventAdapter() {...}.mouseClicked()");
            Vector3f point = cam.getScreenCoordinates(evt.getContactPoint());
            Platform.runLater(() -> ui.showName(e.getValue(), point.getX(), point.getY()));
        }
    }));
    explode0();
}
Also used : ModelKey(com.jme3.asset.ModelKey) ElecCompDef(com.cas.circuit.vo.ElecCompDef) ElecCompAction(com.cas.sim.tis.action.ElecCompAction) MouseEvent(com.cas.sim.tis.app.event.MouseEvent) Spatial(com.jme3.scene.Spatial) MouseEventAdapter(com.cas.sim.tis.app.event.MouseEventAdapter) Vector3f(com.jme3.math.Vector3f) JmeThread(com.cas.sim.tis.anno.JmeThread)

Aggregations

ElecCompDef (com.cas.circuit.vo.ElecCompDef)2 ElecCompAction (com.cas.sim.tis.action.ElecCompAction)2 JmeThread (com.cas.sim.tis.anno.JmeThread)2 MouseEvent (com.cas.sim.tis.app.event.MouseEvent)1 MouseEventAdapter (com.cas.sim.tis.app.event.MouseEventAdapter)1 ModelKey (com.jme3.asset.ModelKey)1 Vector3f (com.jme3.math.Vector3f)1 Spatial (com.jme3.scene.Spatial)1