1 /* $RCSfile$ 2 * $Author: hansonr $ 3 * $Date: 2007-05-18 15:41:42 -0500 (Fri, 18 May 2007) $ 4 * $Revision: 7752 $ 5 6 * 7 * Copyright (C) 2003-2005 The Jmol Development Team 8 * 9 * Contact: jmol-developers@lists.sf.net 10 * 11 * This library is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with this library; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 */ 25 26 package org.jmol.export; 27 28 29 30 import java.util.Map; 31 32 33 import javajs.util.BS; 34 35 import javajs.util.Lst; 36 import javajs.util.P3; 37 import javajs.util.T3; 38 39 40 public class _MayaExporter extends __CartesianExporter { 41 _MayaExporter()42 public _MayaExporter() { 43 commentChar = "// "; 44 } 45 46 /* 47 * The Maya exporter was the first exporter -- really very crude 48 * and never worked out because the user interest didn't develop 49 * past the initial stages. Still, it is important because it 50 * represents the first effort, which is much more fulfilled in 51 * other exporters now, and it does produce a basic model 52 * with sticks and balls. 53 * 54 * Bob Hanson 55 * 56 */ 57 private int nBalls = 0; 58 private int nCyl = 0; 59 private String name; 60 private String id; 61 62 @Override outputHeader()63 protected void outputHeader() { 64 output("// Maya ASCII 8.5 scene\n"); 65 output("// Name: ball_stripped.ma\n"); 66 // output("// CreatedBy: Jmol"); 67 output("// Last modified: Thu, Jul 5, 2007 10:25:55 PM\n"); 68 output("// Codeset: UTF-8\n"); 69 output("requires maya \"8.5\";\n"); 70 output("currentUnit -l centimeter -a degree -t film;\n"); 71 output("fileInfo \"application\" \"maya\";\n"); 72 output("fileInfo \"product\" \"Maya Unlimited 8.5\";\n"); 73 output("fileInfo \"version\" \"8.5\";\n"); 74 output("fileInfo \"cutIdentifier\" \"200612170012-692032\";\n"); 75 output("fileInfo \"osv\" \"Mac OS X 10.4.9\"; \n"); 76 } 77 addAttr()78 private void addAttr() { 79 output(" setAttr -k off \".v\";\n"); 80 output(" setAttr \".vir\" yes;\n"); 81 output(" setAttr \".vif\" yes;\n"); 82 output(" setAttr \".tw\" yes;\n"); 83 output(" setAttr \".covm[0]\" 0 1 1;\n"); 84 output(" setAttr \".cdvm[0]\" 0 1 1;\n"); 85 } 86 addConnect()87 private void addConnect() { 88 output(" connectAttr \"make" + name + ".os\" \"" + id + ".cr\";\n"); 89 output("connectAttr \"" + id 90 + ".iog\" \":initialShadingGroup.dsm\" -na;\n"); 91 } 92 setAttr(String attr, float val)93 private void setAttr(String attr, float val) { 94 output(" setAttr \"." + attr + "\" " + val + ";\n"); 95 } 96 setAttr(String attr, int val)97 private void setAttr(String attr, int val) { 98 output(" setAttr \"." + attr + "\" " + val + ";\n"); 99 } 100 setAttr(String attr, T3 pt)101 private void setAttr(String attr, T3 pt) { 102 output(" setAttr \"." + attr + "\" -type \"double3\" " + pt.x + " " 103 + pt.y + " " + pt.z + ";\n"); 104 } 105 106 @Override outputCylinder(P3 ptCenter, P3 pt1, P3 pt2, short colix, byte endcaps, float radius, P3 ptX, P3 ptY, boolean checkRadius)107 protected boolean outputCylinder(P3 ptCenter, P3 pt1, P3 pt2, short colix, 108 byte endcaps, float radius, P3 ptX, P3 ptY, boolean checkRadius) { 109 if (ptX != null) 110 return false; 111 nCyl++; 112 name = "nurbsCylinder" + nCyl; 113 id = "nurbsCylinderShape" + nCyl; 114 output(" createNode transform -n \"" + name + "\";\n"); 115 float length = pt1.distance(pt2); 116 tempV1.ave(pt2, pt1); 117 setAttr("t", tempV1); 118 tempV1.sub(pt1); 119 tempV2.setT(tempV1); 120 tempV2.normalize(); 121 float r = tempV1.length(); 122 float rX = (float) Math.acos(tempV1.y / r) * degreesPerRadian; 123 if (tempV1.x < 0) 124 rX += 180; 125 float rY = (float) Math.atan2(tempV1.x, tempV1.z) * degreesPerRadian; 126 tempV2.set(rX, rY, 0); 127 setAttr("r", tempV2); 128 output(" createNode nurbsSurface -n \"" + id + "\" -p \"" + name 129 + "\";\n"); 130 addAttr(); 131 output("createNode makeNurbCylinder -n \"make" + name + "\";\n"); 132 output(" setAttr \".ax\" -type \"double3\" 0 1 0;\n"); 133 setAttr("r", radius); 134 setAttr("s", 4); 135 setAttr("hr", length / radius); 136 addConnect(); 137 return true; 138 } 139 140 @Override outputSphere(P3 pt, float radius, short colix, boolean checkRadius)141 protected void outputSphere(P3 pt, float radius, short colix, boolean checkRadius) { 142 //String color = rgbFromColix(colix); 143 nBalls++; 144 name = "nurbsSphere" + nBalls; 145 id = "nurbsSphereShape" + nBalls; 146 147 output("createNode transform -n \"" + name + "\";\n"); 148 setAttr("t", pt); 149 output("createNode nurbsSurface -n \"" + id + "\" -p \"" + name 150 + "\";\n"); 151 addAttr(); 152 output("createNode makeNurbSphere -n \"make" + name + "\";\n"); 153 output(" setAttr \".ax\" -type \"double3\" 0 1 0;\n"); 154 setAttr("r", radius); 155 setAttr("s", 4); 156 setAttr("nsp", 3); 157 addConnect(); 158 } 159 160 // not implemented: 161 162 @Override drawTextPixel(int argb, int x, int y, int z)163 void drawTextPixel(int argb, int x, int y, int z) { 164 // override __CartesianExporter 165 } 166 167 @Override outputTextPixel(P3 pt, int argb)168 protected void outputTextPixel(P3 pt, int argb) { 169 } 170 171 @Override outputSurface(T3[] vertices, T3[] normals, short[] colixes, int[][] indices, short[] polygonColixes, int nVertices, int nPolygons, int nTriangles, BS bsPolygons, int faceVertexMax, short colix, Lst<Short> colorList, Map<Short, Integer> htColixes, P3 offset)172 protected void outputSurface(T3[] vertices, T3[] normals, 173 short[] colixes, int[][] indices, 174 short[] polygonColixes, 175 int nVertices, int nPolygons, int nTriangles, BS bsPolygons, 176 int faceVertexMax, short colix, 177 Lst<Short> colorList, Map<Short, Integer> htColixes, P3 offset) { 178 } 179 180 @Override outputTriangle(T3 pt1, T3 pt2, T3 pt3, short colix)181 protected void outputTriangle(T3 pt1, T3 pt2, T3 pt3, 182 short colix) { 183 // TODO 184 185 } 186 187 @Override outputCircle(P3 pt1, P3 pt2, float radius, short colix, boolean doFill)188 protected void outputCircle(P3 pt1, P3 pt2, float radius, 189 short colix, boolean doFill) { 190 // TODO 191 192 } 193 194 @Override outputCone(P3 ptBase, P3 ptTip, float radius, short colix)195 protected void outputCone(P3 ptBase, P3 ptTip, float radius, 196 short colix) { 197 // TODO 198 199 } 200 201 @Override outputEllipsoid(P3 center, P3[] points, short colix)202 protected void outputEllipsoid(P3 center, P3[] points, short colix) { 203 // TODO 204 205 } 206 207 @Override outputFace(int[] is, int[] coordMap, int faceVertexMax)208 protected void outputFace(int[] is, int[] coordMap, int faceVertexMax) { 209 // TODO 210 211 } 212 213 @Override output(T3 pt)214 protected void output(T3 pt) { 215 // TODO 216 217 } 218 219 } 220