Skip to content

Commit f81256b

Browse files
committed
VertexAttributes: add a constructor and 3 public setters
1 parent d2ca45b commit f81256b

File tree

2 files changed

+113
-2
lines changed

2 files changed

+113
-2
lines changed

src/main/java/com/github/stephengold/joltjni/VertexAttributes.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024 Stephen Gold
2+
Copyright (c) 2024-2025 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -36,6 +36,14 @@ public class VertexAttributes
3636
// *************************************************************************
3737
// constructors
3838

39+
/**
40+
* Instantiate default attributes.
41+
*/
42+
public VertexAttributes() {
43+
long attributesVa = createDefault();
44+
setVirtualAddress(attributesVa, () -> free(attributesVa));
45+
}
46+
3947
/**
4048
* Instantiate attributes as specified.
4149
*
@@ -90,6 +98,48 @@ public VertexAttributes(float compliance, float shearCompliance,
9098
setVirtualAddress(attributesVa, () -> free(attributesVa));
9199
}
92100
// *************************************************************************
101+
// new methods exposed
102+
103+
/**
104+
* Alter the compliance of normal/regular edges. (native attribute:
105+
* mCompliance)
106+
*
107+
* @param compliance the desired compliance value
108+
* @return the argument, for chaining
109+
*/
110+
public float setCompliance(float compliance) {
111+
long attributesVa = va();
112+
setCompliance(attributesVa, compliance);
113+
114+
return compliance;
115+
}
116+
117+
/**
118+
* Alter the type of the long-range attachment (LRA) constraint. (native
119+
* attribute: mLRAType)
120+
*
121+
* @param type the desired type (not null)
122+
*/
123+
public void setLraType(ELraType type) {
124+
long attributesVa = va();
125+
int ordinal = type.ordinal();
126+
setLraType(attributesVa, ordinal);
127+
}
128+
129+
/**
130+
* Alter the compliance of the shear edges. (native attribute:
131+
* mShearCompliance)
132+
*
133+
* @param compliance the desired compliance value
134+
* @return the argument, for chaining
135+
*/
136+
public float setShearCompliance(float compliance) {
137+
long attributesVa = va();
138+
setShearCompliance(attributesVa, compliance);
139+
140+
return compliance;
141+
}
142+
// *************************************************************************
93143
// ConstVertexAttributes methods
94144

95145
/**
@@ -170,6 +220,8 @@ native private static long createAttributes(
170220
float compliance, float shearCompliance, float bendCompliance,
171221
int ordinal, float lraMultiplier);
172222

223+
native private static long createDefault();
224+
173225
native private static void free(long attributesVa);
174226

175227
native private static float getBendCompliance(long attributesVa);
@@ -181,4 +233,12 @@ native private static long createAttributes(
181233
native private static int getLraType(long attributesVa);
182234

183235
native private static float getShearCompliance(long attributesVa);
236+
237+
native private static void setCompliance(
238+
long attributesVa, float compliance);
239+
240+
native private static void setLraType(long attributesVa, int ordinal);
241+
242+
native private static void setShearCompliance(
243+
long attributesVa, float compliance);
184244
}

src/main/native/glue/v/VertexAttributes.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024 Stephen Gold
2+
Copyright (c) 2024-2025 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -47,6 +47,19 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_cre
4747
return reinterpret_cast<jlong> (pResult);
4848
}
4949

50+
/*
51+
* Class: com_github_stephengold_joltjni_VertexAttributes
52+
* Method: createDefault
53+
* Signature: ()J
54+
*/
55+
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_createDefault
56+
(JNIEnv *, jclass) {
57+
SoftBodySharedSettings::VertexAttributes * const pResult
58+
= new SoftBodySharedSettings::VertexAttributes();
59+
TRACE_NEW("SoftBodySharedSettings::VertexAttributes", pResult)
60+
return reinterpret_cast<jlong> (pResult);
61+
}
62+
5063
/*
5164
* Class: com_github_stephengold_joltjni_VertexAttributes
5265
* Method: free
@@ -123,4 +136,42 @@ JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_ge
123136
= reinterpret_cast<SoftBodySharedSettings::VertexAttributes *> (attributesVa);
124137
const float result = pAttributes->mShearCompliance;
125138
return result;
139+
}
140+
141+
/*
142+
* Class: com_github_stephengold_joltjni_VertexAttributes
143+
* Method: setCompliance
144+
* Signature: (JF)V
145+
*/
146+
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_setCompliance
147+
(JNIEnv *, jclass, jlong attributesVa, jfloat compliance) {
148+
SoftBodySharedSettings::VertexAttributes * const pAttributes
149+
= reinterpret_cast<SoftBodySharedSettings::VertexAttributes *> (attributesVa);
150+
pAttributes->mCompliance = compliance;
151+
}
152+
153+
/*
154+
* Class: com_github_stephengold_joltjni_VertexAttributes
155+
* Method: setLraType
156+
* Signature: (JI)V
157+
*/
158+
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_setLraType
159+
(JNIEnv *, jclass, jlong attributesVa, jint ordinal) {
160+
SoftBodySharedSettings::VertexAttributes * const pAttributes
161+
= reinterpret_cast<SoftBodySharedSettings::VertexAttributes *> (attributesVa);
162+
const SoftBodySharedSettings::ELRAType value
163+
= (SoftBodySharedSettings::ELRAType) ordinal;
164+
pAttributes->mLRAType = value;
165+
}
166+
167+
/*
168+
* Class: com_github_stephengold_joltjni_VertexAttributes
169+
* Method: setShearCompliance
170+
* Signature: (JF)V
171+
*/
172+
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_setShearCompliance
173+
(JNIEnv *, jclass, jlong attributesVa, jfloat compliance) {
174+
SoftBodySharedSettings::VertexAttributes * const pAttributes
175+
= reinterpret_cast<SoftBodySharedSettings::VertexAttributes *> (attributesVa);
176+
pAttributes->mShearCompliance = compliance;
126177
}

0 commit comments

Comments
 (0)