|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package javax.microedition.m3g; |
|
20 |
|
21 public class MorphingMesh extends Mesh |
|
22 { |
|
23 //------------------------------------------------------------------ |
|
24 // Instance data |
|
25 //------------------------------------------------------------------ |
|
26 |
|
27 private VertexBuffer[] targets; |
|
28 |
|
29 static private IndexBuffer[] tempTrianglesArray; |
|
30 static private Appearance[] tempAppearanceArray; |
|
31 |
|
32 static private IndexBuffer tempTriangles; |
|
33 static private Appearance tempAppearance; |
|
34 |
|
35 //------------------------------------------------------------------ |
|
36 // Constructor(s) |
|
37 //------------------------------------------------------------------ |
|
38 |
|
39 public MorphingMesh( |
|
40 VertexBuffer base, |
|
41 VertexBuffer[] targets, |
|
42 IndexBuffer triangles, |
|
43 Appearance appearance) |
|
44 { |
|
45 super(createHandle(base, targets, triangles, appearance)); |
|
46 this.targets = new VertexBuffer[targets.length]; |
|
47 System.arraycopy(targets, 0, this.targets, 0, targets.length); |
|
48 } |
|
49 |
|
50 public MorphingMesh( |
|
51 VertexBuffer base, |
|
52 VertexBuffer[] targets, |
|
53 IndexBuffer[] triangles, |
|
54 Appearance[] appearances) |
|
55 { |
|
56 super(createHandle(base, targets, triangles, appearances)); |
|
57 this.targets = new VertexBuffer[targets.length]; |
|
58 System.arraycopy(targets, 0, this.targets, 0, targets.length); |
|
59 } |
|
60 |
|
61 /** |
|
62 */ |
|
63 MorphingMesh(int handle) |
|
64 { |
|
65 super(handle); |
|
66 targets = new VertexBuffer[_getMorphTargetCount(handle)]; |
|
67 for (int i = 0; i < targets.length; i++) |
|
68 { |
|
69 targets[i] = (VertexBuffer)getInstance(_getMorphTarget(handle, i)); |
|
70 } |
|
71 } |
|
72 |
|
73 public VertexBuffer getMorphTarget(int index) |
|
74 { |
|
75 return targets[index]; |
|
76 } |
|
77 |
|
78 public int getMorphTargetCount() |
|
79 { |
|
80 return _getMorphTargetCount(handle); |
|
81 } |
|
82 |
|
83 public void setWeights(float[] weights) |
|
84 { |
|
85 _setWeights(handle, weights); |
|
86 } |
|
87 |
|
88 public void getWeights(float[] weights) |
|
89 { |
|
90 _getWeights(handle, weights); |
|
91 } |
|
92 |
|
93 //------------------------------------------------------------------ |
|
94 // Private methods |
|
95 //------------------------------------------------------------------ |
|
96 |
|
97 static int createHandle(VertexBuffer base, |
|
98 VertexBuffer[] targets, |
|
99 IndexBuffer triangles, |
|
100 Appearance appearance) |
|
101 { |
|
102 |
|
103 tempTriangles = triangles; |
|
104 tempAppearance = appearance; |
|
105 |
|
106 verifyParams(base, triangles); |
|
107 |
|
108 int[] hTargets = new int[targets.length]; |
|
109 int[] hTriangles = null; |
|
110 int[] hAppearances = null; |
|
111 |
|
112 for (int i = 0; i < targets.length; i++) |
|
113 { |
|
114 hTargets[i] = targets[i].handle; |
|
115 } |
|
116 |
|
117 hTriangles = new int[1]; |
|
118 hTriangles[0] = triangles.handle; |
|
119 |
|
120 if (appearance != null) |
|
121 { |
|
122 hAppearances = new int[1]; |
|
123 hAppearances[0] = appearance.handle; |
|
124 } |
|
125 |
|
126 int ret = _ctor(Interface.getHandle(), |
|
127 base.handle, |
|
128 hTargets, |
|
129 hTriangles, |
|
130 hAppearances); |
|
131 |
|
132 tempTriangles = null; |
|
133 tempAppearance = null; |
|
134 |
|
135 return ret; |
|
136 } |
|
137 |
|
138 static int createHandle(VertexBuffer base, |
|
139 VertexBuffer[] targets, |
|
140 IndexBuffer[] triangles, |
|
141 Appearance[] appearances) |
|
142 { |
|
143 |
|
144 tempTrianglesArray = triangles; |
|
145 tempAppearanceArray = appearances; |
|
146 |
|
147 |
|
148 verifyParams(base, triangles, appearances); |
|
149 |
|
150 int[] hTargets = new int[targets.length]; |
|
151 int[] hTriangles = null; |
|
152 int[] hAppearances = null; |
|
153 |
|
154 for (int i = 0; i < targets.length; i++) |
|
155 { |
|
156 hTargets[i] = targets[i].handle; |
|
157 } |
|
158 |
|
159 hTriangles = new int[triangles.length]; |
|
160 |
|
161 if (appearances != null) |
|
162 { |
|
163 hAppearances = new int[appearances.length]; |
|
164 } |
|
165 |
|
166 for (int i = 0; i < triangles.length; i++) |
|
167 { |
|
168 hTriangles[i] = triangles[i].handle; |
|
169 |
|
170 if (hAppearances != null) |
|
171 { |
|
172 hAppearances[i] = appearances[i] != null ? appearances[i].handle : 0; |
|
173 } |
|
174 } |
|
175 |
|
176 int ret = _ctor(Interface.getHandle(), |
|
177 base.handle, |
|
178 hTargets, |
|
179 hTriangles, |
|
180 hAppearances); |
|
181 |
|
182 tempTrianglesArray = null; |
|
183 tempAppearanceArray = null; |
|
184 |
|
185 return ret; |
|
186 |
|
187 } |
|
188 |
|
189 // Native methods |
|
190 private static native int _ctor(int hInstance, |
|
191 int handle, |
|
192 int[] hTargets, |
|
193 int[] hTriangles, |
|
194 int[] hAppearances); |
|
195 private static native void _setWeights(int handle, float[] weights); |
|
196 private static native void _getWeights(int handle, float[] weights); |
|
197 private static native int _getMorphTarget(int handle, int index); |
|
198 private static native int _getMorphTargetCount(int handle); |
|
199 } |