Posted on 2011-03-10 12:20
TWaver 阅读(1997)
评论(1) 编辑 收藏
“hi,用你们TWaver能不能开发个3D的机房图啊?”
现在这句话几乎成了客户见我后的第二句话了,机房管理的呈现方式已经走了n久了,做资源管理的兄弟们奋发拼搏,为了最终客户的口味一次次的去加班,做模板,挖空心思去想创意,从经典的表格式(很庆幸,我没有经历那个年代)走到平面图管理(图一),

从纯平面图走向仿3D的正视效果(图二),
本想已经做到极致了,可是没料到,万恶的摩尔定律,万恶的GPU,万恶的3D游戏把最终客户的口味充分调动了起来,现在居然有了机房3D实景构建的需求。
在各个厂家都在关注于业务做强做精的时候,让他们分心出来做这种效果,无论是哪一家厂商,都是一个不菲的成本项。滴水汇成海,各个厂家开始把这种需求越来越详尽的反馈到了TWaver这边,客户的需求就是TWaver的责任,TWaver中国这边迅速将需求整理汇集,发往了美国核心开发组,抓紧立项开发。经过紧张的工作,core team已经给我发过来了试用包,兄弟得以第一时间尝鲜,我这里就赶紧的把这个包的特点提前披露,跟各位兄弟分享一下。
TWaver的3D开发包命名为TWaver 3D,立足于Java、Flex、.Net、HTML5多个语言开发平台(当然目前兄弟我还是只拿到了Java版,毕竟这个是TWaver的魂魄所属)。这个开发包设计目标是透明化3D开发,降低2D界面到3D界面的门槛,平滑转移原来TWaver客户项目的3D化需求;它的功能主要罗列如下:
(1)呈现3D场景
(2)内建(built-in)常见对象的3D模型,例如Room,Node,Equipment等等
(3)提供场景渲染接口
(4)提供默认交互接口及实现,例如鼠标导航,视图缩放,实体对象的操作等等.这个功能,可以参考下面的例子
TWaver3D 初体验
(5)已有模型文件的导入,例如3ds。(据我所知,此部分还在紧张进行中)
(6)简化用户3D开发的代码复杂度,支持TWaver原有平面模型的转换。这个功能大家可以看一个我们的一个小例子视频:
设备平面图映射为设备的3D模型
对于TWaver的用户来说,渲染效果是一方面,另一方面还得把二次开发的复杂度大大降低才行,否则他们自己成本的控制就无从谈起。我第一时间收到老外的邮件的时候,他在邮件里提的最多的就是可以大大降低用户开发的代码量。究竟有多省,我们自己来看看
1
public static void main(String[] args)
{
2
JFrame frame = new JFrame();
3
final TDataBox box = new TDataBox();
4
final TNetwork3D network = new TNetwork3D(box);
5
network.setSelectedMode(Consts3D.SELECTED_MODE_SKELEON);
6
JPanel panel = new JPanel(new BorderLayout());
7
panel.add(network, BorderLayout.CENTER);
8
JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
9
ActionListener listener = new ActionListener()
{
10
public void actionPerformed(ActionEvent e)
{
11
String command = e.getActionCommand();
12
AbstractButton ab = (AbstractButton) e.getSource();
13
if (ab instanceof JCheckBox)
{
14
JCheckBox s = (JCheckBox) ab;
15
if ("show axes".equals(command))
{
16
network.setAxexVisible(s.isSelected());
17
} else if ("show background".equals(command))
{
18
Color bc = ab.isSelected() ? Color.CYAN : null;
19
network.setBackground(bc);
20
} else if ("highlight".equals(command))
{
21
int mode = ab.isSelected() ? Consts3D.SELECTED_MODE_HIGHLIGHT : Consts3D.SELECTED_MODE_SKELEON;
22
network.setSelectedMode(mode);
23
}
24
} else
{
25
}
26
}
27
};
28
controlPanel.add(createButton(0, "show axes", listener));
29
controlPanel.add(createButton(0, "show background", listener));
30
controlPanel.add(createButton(0, "highlight", listener));
31
panel.add(controlPanel, BorderLayout.SOUTH);
32
frame.setContentPane(panel);
33
frame.setSize(1024, 700);
34
frame.setVisible(true);
35
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
36
frame.setLocationRelativeTo(null);
37
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
38
public void run()
{
39
//build the 3D scene
40
Room room = new Room();
41
Utils3D.setLocation(room, 0, 0, 0);
42
Utils3D.setSize(room, 15, 2, 12);
43
box.addElement(room);
44
double startx = -6.2;
45
double starty = -5;
46
double colStep = 1.3;
47
double rowStep = 2;
48
double length = 0.8;
49
double height = 1.8;
50
double depth = length;
51
for (int col = 0; col < 10; col++)
{
52
for (int row = 0; row < 6; row++)
{
53
Rack chassis = new Rack();
54
Utils3D.setLocation(chassis, startx + col * colStep,
55
starty + row * rowStep, 0);
56
Utils3D.setSize(chassis, length, height, depth);
57
box.addElement(chassis);
58
}
59
}
60
}
61
});
62
}
63
public static AbstractButton createButton(int type, String command, ActionListener listener)
{
64
AbstractButton button = null;
65
if (type == 0)
{
66
button = new JCheckBox(command);
67
} else
{
68
button = new JButton(command);
69
}
70
button.addActionListener(listener);
71
return button;
72
}
这段代码除了界面布局、ActionListener处理、以及Swing对象的构建之外,就只剩下12行做机房模型的代码了。大家想知道这点代码能做到什么效果吗,请看
快速搭建3D机房实景